|
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 parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
23 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
24 bool checkDataFileName( string& sFileName ); |
|
25 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args ); |
|
26 |
|
27 // Constants for old "hooking" parameter parsing. |
|
28 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: " |
|
29 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$%*()|\\/[]{}<>?;:,\"'"; |
|
30 |
|
31 /** |
|
32 * Check datafile name for invalid characters. |
|
33 * @return true if file name ok. |
|
34 */ |
|
35 bool checkDataFileName( string& sFileName ) |
|
36 { |
|
37 for ( size_t i = 0; i < sFileName.length(); i++ ) |
|
38 { |
|
39 const char c = sFileName.at( i ); |
|
40 if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 ) |
|
41 return false; |
|
42 } |
|
43 return true; |
|
44 } |
|
45 |
|
46 /** |
|
47 * Parse base arguments from given vector of strings. |
|
48 * Removes debug / help arguments from vector. |
|
49 */ |
|
50 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args ) |
|
51 { |
|
52 // Iterator used in this function. |
|
53 vector<string>::iterator it; |
|
54 // If no arguments set show help true. |
|
55 if ( vArgs.size() == 0 ) |
|
56 { |
|
57 args.eMainSwitch = SWITCH_UNKNOWN; |
|
58 args.bHelp = true; |
|
59 } |
|
60 //Try find help and debug switches. |
|
61 //Note: -help is main switch what shows syntax examples. |
|
62 for(it = vArgs.begin(); it != vArgs.end(); it++ ) |
|
63 { |
|
64 //Help switches. |
|
65 if ( ! _stricmp( (*it).c_str(), "-?" ) ) |
|
66 { |
|
67 args.bHelp = true; |
|
68 it = vArgs.erase( it ); |
|
69 if ( it == vArgs.end() ) |
|
70 break; |
|
71 } |
|
72 else if ( ! _stricmp( (*it).c_str(), "--?" ) ) |
|
73 { |
|
74 args.bHelp = true; |
|
75 it = vArgs.erase( it ); |
|
76 if ( it == vArgs.end() ) |
|
77 break; |
|
78 } |
|
79 else if ( ! _stricmp( (*it).c_str(), "--help" ) ) |
|
80 { |
|
81 args.bHelp = true; |
|
82 it = vArgs.erase( it ); |
|
83 if ( it == vArgs.end() ) |
|
84 break; |
|
85 } |
|
86 else if ( ! _stricmp( (*it).c_str(), "/?" ) ) |
|
87 { |
|
88 args.bHelp = true; |
|
89 it = vArgs.erase( it ); |
|
90 if ( it == vArgs.end() ) |
|
91 break; |
|
92 } |
|
93 //Debug switches. |
|
94 else if ( ! _stricmp( (*it).c_str(), "-show_debug" ) ) |
|
95 { |
|
96 args.bDebugConsole = true; |
|
97 it = vArgs.erase( it ); |
|
98 if ( it == vArgs.end() ) |
|
99 break; |
|
100 } |
|
101 else if ( ! _stricmp( (*it).c_str(), "--show_debug" ) ) |
|
102 { |
|
103 args.bDebugConsole = true; |
|
104 it = vArgs.erase( it ); |
|
105 if ( it == vArgs.end() ) |
|
106 break; |
|
107 } |
|
108 else if ( ! _stricmp( (*it).c_str(), "-show_debug_all" ) ) |
|
109 { |
|
110 args.bDebugConsole = true; |
|
111 args.bDebugLowLevel = true; |
|
112 it = vArgs.erase( it ); |
|
113 if ( it == vArgs.end() ) |
|
114 break; |
|
115 } |
|
116 else if ( ! _stricmp( (*it).c_str(), "--show_debug_all" ) ) |
|
117 { |
|
118 args.bDebugConsole = true; |
|
119 args.bDebugLowLevel = true; |
|
120 it = vArgs.erase( it ); |
|
121 if ( it == vArgs.end() ) |
|
122 break; |
|
123 } |
|
124 else if ( ! _stricmp( (*it).c_str(), "-show_dbgview" ) ) |
|
125 { |
|
126 args.bDebugDbgView = true; |
|
127 it = vArgs.erase( it ); |
|
128 if ( it == vArgs.end() ) |
|
129 break; |
|
130 } |
|
131 else if ( ! _stricmp( (*it).c_str(), "--show_dbgview" ) ) |
|
132 { |
|
133 args.bDebugDbgView = true; |
|
134 it = vArgs.erase( it ); |
|
135 if ( it == vArgs.end() ) |
|
136 break; |
|
137 } |
|
138 else if ( ! _stricmp( (*it).c_str(), "-show_dbgview_all" ) ) |
|
139 { |
|
140 args.bDebugDbgView = true; |
|
141 args.bDebugLowLevel = true; |
|
142 it = vArgs.erase( it ); |
|
143 if ( it == vArgs.end() ) |
|
144 break; |
|
145 } |
|
146 else if ( ! _stricmp( (*it).c_str(), "--show_dbgview_all" ) ) |
|
147 { |
|
148 args.bDebugDbgView = true; |
|
149 args.bDebugLowLevel = true; |
|
150 it = vArgs.erase( it ); |
|
151 if ( it == vArgs.end() ) |
|
152 break; |
|
153 } |
|
154 //Raptor switch. |
|
155 else if ( ! _stricmp( (*it).c_str(), "-sbs2" ) ) |
|
156 { |
|
157 args.bEnableSbs2 = true; |
|
158 it = vArgs.erase( it ); |
|
159 if ( it == vArgs.end() ) |
|
160 break; |
|
161 } |
|
162 } |
|
163 if ( vArgs.size() > 0 ) |
|
164 { |
|
165 //Pick up main switch. |
|
166 it = vArgs.begin(); |
|
167 if ( ! _stricmp( (*it).c_str(), "-a" ) ) |
|
168 args.eMainSwitch = SWITCH_ANALYZE; |
|
169 else if ( ! _stricmp( (*it).c_str(), "-p" ) ) |
|
170 args.eMainSwitch = SWITCH_PARSE_TRACE; |
|
171 else if ( ! _stricmp( (*it).c_str(), "-c" ) ) |
|
172 args.eMainSwitch = SWITCH_CLEAN; |
|
173 else if ( ! _stricmp( (*it).c_str(), "-v" ) ) |
|
174 args.eMainSwitch = SWITCH_VERSION; |
|
175 else if ( ! _stricmp( (*it).c_str(), "-vdbghelp" ) ) |
|
176 args.eMainSwitch = SWITCH_DBGHELP_VERSION; |
|
177 else if ( ! _stricmp( (*it).c_str(), "-help" ) ) |
|
178 args.eMainSwitch = SWITCH_HELP; |
|
179 else if ( ! _stricmp( (*it).c_str(), "-me" ) ) |
|
180 { |
|
181 args.eMainSwitch = SWITCH_HOOK; |
|
182 args.eHookSwitch = HOOK_EXTERNAL; |
|
183 } |
|
184 else if ( ! _stricmp( (*it).c_str(), "-e" ) ) |
|
185 { |
|
186 args.eMainSwitch = SWITCH_HOOK; |
|
187 args.eHookSwitch = HOOK_EXTERNAL_FAST; |
|
188 } |
|
189 else if ( ! _stricmp( (*it).c_str(), "-mi" ) ) |
|
190 { |
|
191 args.eMainSwitch = SWITCH_HOOK; |
|
192 args.eHookSwitch = HOOK_INTERNAL; |
|
193 } |
|
194 else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) ) |
|
195 { |
|
196 args.eMainSwitch = SWITCH_HOOK; |
|
197 args.eHookSwitch = HOOK_EXTENSION_INTERNAL; |
|
198 } |
|
199 else if ( ! _stricmp( (*it).c_str(), "-instrument_e" ) ) |
|
200 { |
|
201 args.eMainSwitch = SWITCH_HOOK; |
|
202 args.eHookSwitch = HOOK_EXTENSION_EXTERNAL; |
|
203 } |
|
204 else if ( ! _stricmp( (*it).c_str(), "-instrument_ef" ) ) |
|
205 { |
|
206 args.eMainSwitch = SWITCH_HOOK; |
|
207 args.eHookSwitch = HOOK_EXTENSION_EXTERNAL_FAST; |
|
208 } |
|
209 else if ( ! _stricmp( (*it).c_str(), "-uninstrument" ) ) |
|
210 { |
|
211 args.eMainSwitch = SWITCH_UNHOOK; |
|
212 args.eHookSwitch = HOOK_EXTENSION_UNINSTRUMENT; |
|
213 } |
|
214 else if ( ! _stricmp( (*it).c_str(), "-uninstrument_failed" ) ) |
|
215 { |
|
216 args.eMainSwitch = SWITCH_UNHOOK; |
|
217 args.eHookSwitch = HOOK_EXTENSION_FAILED; |
|
218 } |
|
219 } |
|
220 return true; |
|
221 } |
|
222 |
|
223 /** |
|
224 * Parse analyze related arguments from given vector of strings. |
|
225 */ |
|
226 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ) |
|
227 { |
|
228 bool bRet = true; |
|
229 if ( vArgs.size() < 2 ) |
|
230 { |
|
231 cout << AT_MSG << "Error, missing datafile." << endl; |
|
232 return false; |
|
233 } |
|
234 // Iterator used in this function. |
|
235 vector<string>::const_iterator it; |
|
236 for(it = vArgs.begin()+1; it != vArgs.end(); it++ ) |
|
237 { |
|
238 if ( it->find("-l") != string::npos ) |
|
239 { |
|
240 if ( it->length() == 3 ) |
|
241 { |
|
242 // Create char array for atoi function |
|
243 char level[2]; |
|
244 level[0] = it->at(2); |
|
245 level[1] = 0; // null terminate |
|
246 // check that its digit first |
|
247 if ( isdigit(level[0]) ) |
|
248 { |
|
249 // pass array to atoi |
|
250 int iLoggingLevel = atoi( level ); |
|
251 if ( iLoggingLevel >= 0 && iLoggingLevel <= 3 ) |
|
252 { |
|
253 // log level ok |
|
254 args.ANALYZE.iLoggingLevel = iLoggingLevel; |
|
255 continue; |
|
256 } |
|
257 } |
|
258 bRet = false; |
|
259 cout << AT_MSG << "Invalid logging level specified (0-3)." << endl; |
|
260 args.ANALYZE.iLoggingLevel = -1; |
|
261 } |
|
262 } |
|
263 // No else here because logging level check is done to all args in list. |
|
264 // Rom symbol file |
|
265 if( _stricmp( it->c_str(), "-s" ) == 0 ) |
|
266 { |
|
267 it++; |
|
268 if ( it == vArgs.end() ) |
|
269 { |
|
270 bRet = false; |
|
271 cout << AT_MSG << "Missing symbol file." << endl; |
|
272 break; // Leave for loop. |
|
273 } |
|
274 else |
|
275 { |
|
276 args.ANALYZE.bSymbolFile = true; |
|
277 args.ANALYZE.vSymbolFiles.push_back( *it ); |
|
278 continue; |
|
279 } |
|
280 } |
|
281 else |
|
282 { |
|
283 // If we got datafile we must assume this is output |
|
284 if( ! args.ANALYZE.sDataFile.empty() ) |
|
285 { |
|
286 if ( args.ANALYZE.sOutputFile.empty() ) |
|
287 args.ANALYZE.sOutputFile = *it; |
|
288 else |
|
289 { |
|
290 bRet = false; |
|
291 cout << AT_MSG << "Invalid parameter: " << *it << endl; |
|
292 } |
|
293 } |
|
294 // If this is file we assume datafile |
|
295 else if( CATBase::FileExists( it->c_str() ) ) |
|
296 { |
|
297 args.ANALYZE.sDataFile = *it; |
|
298 } |
|
299 else |
|
300 { |
|
301 bRet = false; |
|
302 cout << AT_MSG << "Specified datafile does not exist." << endl; |
|
303 } |
|
304 } |
|
305 } |
|
306 if ( args.ANALYZE.sDataFile.empty() ) |
|
307 bRet = false; |
|
308 return bRet; |
|
309 } |
|
310 |
|
311 |
|
312 /** |
|
313 * Parse hooking related arguments from given vector of strings. |
|
314 */ |
|
315 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args ) |
|
316 { |
|
317 bool bRet = true; |
|
318 try { |
|
319 // Iterator used in this function. |
|
320 vector<string>::const_iterator it; |
|
321 |
|
322 // Check that we have some arguments except main switch. |
|
323 if ( vArgs.size() < 2 ) |
|
324 { |
|
325 if ( args.eHookSwitch == HOOK_EXTENSION_UNINSTRUMENT |
|
326 || args.eHookSwitch == HOOK_EXTENSION_FAILED |
|
327 ) |
|
328 return bRet; |
|
329 cout << AT_MSG << "Error, Missing build command." << endl; |
|
330 bRet = false; |
|
331 } |
|
332 bool bBuildFound = false; |
|
333 for(it = vArgs.begin()+1; it != vArgs.end(); it++ ) |
|
334 { |
|
335 // If's to pickup atool options |
|
336 // no build switch |
|
337 if ( _stricmp( it->c_str(), "-nobuild" ) == 0 ) |
|
338 { |
|
339 args.HOOK.bNoBuild = true; |
|
340 } |
|
341 // call stack size(s) |
|
342 else if ( _stricmp( it->c_str(), "-acs" ) == 0 || _stricmp( it->c_str(), "-fcs" ) == 0 ) |
|
343 { |
|
344 // Free vs Alloc |
|
345 bool bAlloc = true; |
|
346 if ( _stricmp( it->c_str(), "-fcs" ) == 0 ) |
|
347 bAlloc = false; |
|
348 // Value |
|
349 it++; |
|
350 if ( it== vArgs.end() ) |
|
351 { |
|
352 bRet = false; |
|
353 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
|
354 break; |
|
355 } |
|
356 else if ( ! _stricmp( it->c_str(), "sbs" ) |
|
357 || ! _stricmp( it->c_str(), "abld" ) |
|
358 || ! _stricmp( it->c_str(), "-f" ) ) |
|
359 { |
|
360 bRet = false; |
|
361 cout << AT_MSG << "Error, missing call stack size parameter." << endl; |
|
362 break; |
|
363 } |
|
364 else |
|
365 { |
|
366 int i; |
|
367 // Try to parse integer value using stream. |
|
368 istringstream ss( *it ); |
|
369 if ( ss>>i ) |
|
370 { |
|
371 // Value parsed ok now check bounds. |
|
372 if ( i < AT_CALL_STACK_SIZE_MIN ) |
|
373 { |
|
374 bRet = false; |
|
375 cout << AT_MSG << "Error, specified call stack size value too small." << endl; |
|
376 break; |
|
377 } |
|
378 else if ( i > AT_CALL_STACK_SIZE_MAX ) |
|
379 { |
|
380 bRet = false; |
|
381 cout << AT_MSG << "Error, specified call stack size value too big." << endl; |
|
382 break; |
|
383 } |
|
384 else |
|
385 { |
|
386 // Value valid. |
|
387 if ( bAlloc ) |
|
388 args.HOOK.iAllocCallStackSize = i; |
|
389 else |
|
390 args.HOOK.iFreeCallStackSize = i; |
|
391 } |
|
392 } |
|
393 else |
|
394 { |
|
395 // Error parsing value using stream. |
|
396 bRet = false; |
|
397 cout << AT_MSG << "Error, specified call stack size value invalid." << endl; |
|
398 break; |
|
399 } |
|
400 |
|
401 } |
|
402 } |
|
403 // Data file name. |
|
404 else if ( _stricmp( it->c_str(), "-f" ) == 0 ) |
|
405 { |
|
406 it++; |
|
407 if ( it == vArgs.end() ) |
|
408 { |
|
409 bRet = false; |
|
410 cout << AT_MSG << "Error, missing internal data gathering file name." << endl; |
|
411 break; |
|
412 } |
|
413 else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) ) |
|
414 { |
|
415 bRet = false; |
|
416 cout << AT_MSG << "Error, missing internal data gathering file name." << endl; |
|
417 break; |
|
418 } |
|
419 else |
|
420 { |
|
421 if ( checkDataFileName( string( *it ) ) ) |
|
422 { |
|
423 // Pickup filename. |
|
424 args.HOOK.bDataFileName = true; |
|
425 args.HOOK.sDataFileName = *it; |
|
426 } |
|
427 else |
|
428 { |
|
429 bRet = false; |
|
430 cout << AT_MSG << "Error, specified internal data gathering file name contains invalid character(s)." << endl; |
|
431 break; |
|
432 } |
|
433 } |
|
434 } |
|
435 // Build command parsing. |
|
436 else if ( _stricmp( it->c_str(), "sbs" ) == 0 ) |
|
437 { |
|
438 // By default sbs command is not valid. |
|
439 bRet = false; |
|
440 // By default build found |
|
441 bBuildFound = true; |
|
442 // Use raptor build system, pickup all rest arguments to sbs commmand. |
|
443 bool bFoundConfig = false; // Is configuration defined. |
|
444 args.HOOK.iBuildSystem = 2; |
|
445 vector<string>::const_iterator itC = it; |
|
446 args.HOOK.sBuildCmd.clear(); |
|
447 for ( ; itC != vArgs.end() ; itC++ ) |
|
448 { |
|
449 args.HOOK.sBuildCmd.append( *itC ); |
|
450 args.HOOK.sBuildCmd.append( " " ); |
|
451 args.HOOK.vBuildCmd.push_back( *itC ); |
|
452 } |
|
453 // Remove last space |
|
454 if ( args.HOOK.vBuildCmd.size() > 1 ) |
|
455 args.HOOK.sBuildCmd.erase( args.HOOK.sBuildCmd.size()-1 ); |
|
456 |
|
457 // Parse needed variables from sbs command. |
|
458 vector<string>::iterator itSbs; |
|
459 for( itSbs = args.HOOK.vBuildCmd.begin(); itSbs != args.HOOK.vBuildCmd.end() ; itSbs++ ) |
|
460 { |
|
461 // Program(s). |
|
462 if ( _stricmp( itSbs->c_str(), "-p" ) == 0 ) |
|
463 { |
|
464 // Next is program. |
|
465 itSbs++; |
|
466 args.HOOK.vTargetPrograms.push_back( *itSbs ); |
|
467 } |
|
468 else if ( itSbs->find( "--project=" ) != string::npos ) |
|
469 { |
|
470 itSbs->erase(0, 10 ); |
|
471 args.HOOK.vTargetPrograms.push_back( *itSbs ); |
|
472 } |
|
473 // platform & build type ( configuration ) |
|
474 else if ( _stricmp( itSbs->c_str(), "-c" ) == 0 || itSbs->find( "--config=" ) != string::npos ) |
|
475 { |
|
476 // Error message if config found more than once. |
|
477 if ( bFoundConfig ) |
|
478 { |
|
479 cout << AT_MSG << "Error, no support defining more than one configuration." << endl; |
|
480 bRet = false; |
|
481 continue; |
|
482 } |
|
483 |
|
484 if (_stricmp( itSbs->c_str(), "-c" ) == 0 ) |
|
485 { |
|
486 // Next is the configuration |
|
487 itSbs++; |
|
488 // Check that iterator is valid. |
|
489 if ( itSbs == args.HOOK.vBuildCmd.end() ) |
|
490 break; |
|
491 } |
|
492 else |
|
493 { |
|
494 // Remove the "--config=". |
|
495 itSbs->erase( 0, 9 ); |
|
496 // Check its not empty. |
|
497 if ( itSbs->size() == 0 ) |
|
498 break; |
|
499 } |
|
500 |
|
501 // Identify configuration, if successful set sbs command as valid. |
|
502 if ( parseSbsConfiguration( *itSbs, args ) ) |
|
503 bRet = true; |
|
504 // Set we encountered one configuration. |
|
505 bFoundConfig = true; |
|
506 } |
|
507 } |
|
508 // Error message if command is missing configuration. |
|
509 if ( !bFoundConfig ) |
|
510 cout << AT_MSG << "Error, missing configuration definition from sbs cmd." << endl; |
|
511 } |
|
512 else if ( _stricmp( it->c_str(), "abld" ) == 0 ) |
|
513 { |
|
514 bBuildFound = true; |
|
515 // Use abld build system, pickup all rest argumenst as abld options. |
|
516 args.HOOK.iBuildSystem = 1; |
|
517 |
|
518 vector<string>::const_iterator itC = it; |
|
519 args.HOOK.sBuildCmd.clear(); |
|
520 for ( ; itC != vArgs.end() ; itC++ ) |
|
521 { |
|
522 args.HOOK.sBuildCmd.append( *itC ); |
|
523 args.HOOK.sBuildCmd.append( " " ); |
|
524 args.HOOK.vBuildCmd.push_back( *itC ); |
|
525 } |
|
526 |
|
527 string sCmd( args.HOOK.sBuildCmd ); // build command to lower case here. |
|
528 for( size_t i = 0 ; i < sCmd.size(); i++ ) |
|
529 sCmd.at(i) = tolower( sCmd.at(i) ); |
|
530 |
|
531 // Remove all until platform |
|
532 if ( sCmd.find("build ") != string::npos ) |
|
533 { |
|
534 // Check is test defined |
|
535 if ( sCmd.substr(0, sCmd.find("build ")).find("test") != string::npos ) |
|
536 args.HOOK.bAbldTest = true; |
|
537 sCmd.erase( 0, sCmd.find("build")+6 ); |
|
538 } |
|
539 else |
|
540 return false; |
|
541 |
|
542 //Is -debug switch in command? |
|
543 if( sCmd.find( "-debug " ) != string::npos ) |
|
544 { |
|
545 sCmd.erase( sCmd.find( "-debug " ), 7 ); |
|
546 } |
|
547 |
|
548 // Parse needed "variables" from command. |
|
549 bool bOk = false; |
|
550 |
|
551 // Find platform |
|
552 if ( sCmd.find( "armv5" ) != string::npos ) |
|
553 { |
|
554 bOk = true; |
|
555 args.HOOK.sPlatform = "armv5"; |
|
556 sCmd.erase( sCmd.find( "armv5" ), 5 ); |
|
557 } |
|
558 else if ( sCmd.find( "winscw" ) != string::npos ) |
|
559 { |
|
560 bOk = true; |
|
561 args.HOOK.sPlatform = "winscw"; |
|
562 sCmd.erase( sCmd.find( "winscw" ), 6 ); |
|
563 } |
|
564 else if ( sCmd.find( "gcce" ) != string::npos ) |
|
565 { |
|
566 bOk = true; |
|
567 args.HOOK.sPlatform = "gcce"; |
|
568 sCmd.erase( sCmd.find( "gcce" ), 4 ); |
|
569 } |
|
570 if ( bOk ) |
|
571 { |
|
572 // Feature variant. |
|
573 if ( sCmd.at(0 ) == '.' ) |
|
574 { |
|
575 sCmd.erase(0,1); |
|
576 args.HOOK.sFeatureVariant = sCmd.substr( 0, sCmd.find_first_of(' ') ); |
|
577 sCmd.erase(0, sCmd.find_first_of(' ')+1 ); |
|
578 } |
|
579 } |
|
580 else |
|
581 { |
|
582 // not platform specified. |
|
583 cout << AT_MSG << "Error, no supported platform found in abld parameters (armv5/winscw/gcce)." << endl; |
|
584 bRet = false; |
|
585 } |
|
586 |
|
587 // find build type |
|
588 bOk = false; |
|
589 if ( sCmd.find( "urel" ) != string::npos ) |
|
590 { |
|
591 bOk = true; |
|
592 args.HOOK.sBuildType = "urel"; |
|
593 sCmd.erase( sCmd.find( "urel" ), 4 ); |
|
594 } |
|
595 |
|
596 else if ( sCmd.find( "udeb" ) != string::npos ) |
|
597 { |
|
598 bOk = true; |
|
599 args.HOOK.sBuildType = "udeb"; |
|
600 sCmd.erase( sCmd.find( "udeb" ), 4 ); |
|
601 } |
|
602 if( !bOk ) |
|
603 { |
|
604 // no build type specified. |
|
605 cout << AT_MSG << "Error, no build type specified in abld parameters (udeb/urel)." << endl; |
|
606 bRet = false; |
|
607 } |
|
608 |
|
609 // Is there multiple programs (only should be used from extension). |
|
610 if ( sCmd.find(" -p") != string::npos ) |
|
611 { |
|
612 sCmd.erase( sCmd.find(" -p" ), sCmd.size() - sCmd.find(" -p" ) ); |
|
613 // Loop thru all parameters and pick up programs. |
|
614 vector<string>::iterator it; |
|
615 for( it = args.HOOK.vBuildCmd.begin(); it != args.HOOK.vBuildCmd.end(); it++ ) |
|
616 { |
|
617 if ( _stricmp( it->c_str(), "-p" ) == 0 ) |
|
618 { |
|
619 // Next is program. |
|
620 it++; |
|
621 string sProgram = *it; |
|
622 // Make sure program name ends with ".mmp". |
|
623 CATBase::ChangeToLower( sProgram ); |
|
624 if ( sProgram.length() >= 4 ) |
|
625 { |
|
626 string sEnd = sProgram.substr( sProgram.length()-4, 4 ); |
|
627 if ( sEnd.compare( ".mmp" ) != 0 ) |
|
628 sProgram.append( ".mmp" ); |
|
629 } |
|
630 else |
|
631 sProgram.append( ".mmp" ); |
|
632 args.HOOK.vTargetPrograms.push_back( sProgram ); |
|
633 } |
|
634 } |
|
635 } |
|
636 else { |
|
637 // find single defined program. |
|
638 if ( sCmd.find_first_not_of(' ') != string::npos ) |
|
639 { |
|
640 size_t iS = sCmd.find_first_not_of(' '); |
|
641 size_t iE = sCmd.find_first_of(' ', iS ); |
|
642 string sProgram; |
|
643 if ( iE == string::npos ) |
|
644 sProgram = sCmd.substr( iS, sCmd.size()-iS ); |
|
645 else |
|
646 sProgram = sCmd.substr( iS, iE-iS); |
|
647 // Make sure program name ends with ".mmp". |
|
648 CATBase::ChangeToLower( sProgram ); |
|
649 if ( sProgram.length() >= 4 ) |
|
650 { |
|
651 string sEnd = sProgram.substr( sProgram.length()-4, 4 ); |
|
652 if ( sEnd.compare( ".mmp" ) != 0 ) |
|
653 sProgram.append( ".mmp" ); |
|
654 } |
|
655 else |
|
656 sProgram.append( ".mmp" ); |
|
657 args.HOOK.vTargetPrograms.push_back( sProgram ); |
|
658 } |
|
659 } |
|
660 } |
|
661 else |
|
662 { |
|
663 if ( ! bBuildFound ) |
|
664 { |
|
665 bRet = false; |
|
666 cout << AT_MSG << "Error, invalid parameter :" << *it << endl; |
|
667 break; |
|
668 } |
|
669 } |
|
670 } |
|
671 } |
|
672 catch(...) |
|
673 { |
|
674 bRet = false; |
|
675 cout << AT_MSG << "Error parsing arguments." << endl; |
|
676 } |
|
677 return bRet; |
|
678 } |
|
679 |
|
680 |
|
681 /** |
|
682 * Parse trace parsing related arguments from given vector of strings. |
|
683 */ |
|
684 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ) |
|
685 { |
|
686 // Iterator used in this function. |
|
687 vector<string>::const_iterator it = vArgs.begin(); |
|
688 |
|
689 if ( it == vArgs.end() ) |
|
690 return false; |
|
691 |
|
692 it++; |
|
693 |
|
694 if ( it == vArgs.end() ) |
|
695 { |
|
696 cout << AT_MSG << "Error, input file not defined (raw data file)." << endl; |
|
697 return false; |
|
698 } |
|
699 |
|
700 //Input. |
|
701 args.PARSE.bDataFile = true; |
|
702 args.PARSE.sDataFile = *it; |
|
703 |
|
704 it++; |
|
705 if ( it == vArgs.end() ) |
|
706 { |
|
707 |
|
708 cout << AT_MSG << "Error, output file not defined (device data file)." << endl; |
|
709 return false; |
|
710 } |
|
711 |
|
712 //Output. |
|
713 args.PARSE.bOutputFile = true; |
|
714 args.PARSE.sOutputFile = *it; |
|
715 return true; |
|
716 } |
|
717 |
|
718 /** |
|
719 * Identifies/parses the configuration string when raptor used (-c / --config= ). |
|
720 */ |
|
721 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args ) |
|
722 { |
|
723 CATBase::ChangeToLower( sConfiguration ); |
|
724 vector<string> tokens = CATBase::ParseStringToVector( sConfiguration, '.' ); |
|
725 |
|
726 //we check if winscw/armv5 and udeb/urel is used |
|
727 //rest of the "." are variants which we all support by default. |
|
728 |
|
729 //first we check if some of aliases is used |
|
730 if ( tokens.at(0).compare("armv5_urel") == 0 ) |
|
731 { |
|
732 args.HOOK.sPlatform = "armv5"; |
|
733 args.HOOK.sBuildType = "urel"; |
|
734 return true; |
|
735 } |
|
736 else if ( tokens.at(0).compare("armv5_udeb") == 0 ) |
|
737 { |
|
738 args.HOOK.sPlatform = "armv5"; |
|
739 args.HOOK.sBuildType = "udeb"; |
|
740 return true; |
|
741 } |
|
742 else if ( tokens.at(0).compare("winscw_udeb") == 0) |
|
743 { |
|
744 args.HOOK.sPlatform = "winscw"; |
|
745 args.HOOK.sBuildType = "udeb"; |
|
746 return true; |
|
747 } |
|
748 else if ( tokens.at(0).compare("winscw_urel") == 0 ) |
|
749 { |
|
750 args.HOOK.sPlatform = "winscw"; |
|
751 args.HOOK.sBuildType = "urel"; |
|
752 return true; |
|
753 } |
|
754 //if 1st token is not an alias, lets try dot configurations |
|
755 else if ( tokens.at(0).compare("arm") == 0 ) |
|
756 { |
|
757 // check we have atleast 3 tokens. i.e arm v5 debug x ... |
|
758 if ( tokens.size() >= 3 ) |
|
759 { |
|
760 // Next configuration is arm version, we only support v5. |
|
761 if ( tokens.at(1).compare( "v5" ) == 0) |
|
762 { |
|
763 args.HOOK.sPlatform = "armv5"; |
|
764 |
|
765 // Check next configuration part is debug or release |
|
766 if ( tokens.at(2).compare( "udeb" ) == 0) |
|
767 { |
|
768 args.HOOK.sBuildType = "udeb"; |
|
769 return true; |
|
770 } |
|
771 else if ( tokens.at(2).compare( "urel" ) == 0 ) |
|
772 { |
|
773 args.HOOK.sBuildType = "urel"; |
|
774 return true; |
|
775 } |
|
776 else |
|
777 { |
|
778 cout << AT_MSG << "Error in sbs configuration part: " << tokens.at(2) << endl; |
|
779 cout << AT_MSG << "Supported are: udeb,urel." << endl; |
|
780 return false; |
|
781 } |
|
782 } |
|
783 else |
|
784 { |
|
785 cout << AT_MSG << "Error in sbs configuration part: " << tokens.at(1) << endl; |
|
786 cout << AT_MSG << "Supported are: v5." << endl; |
|
787 return false; |
|
788 } |
|
789 } |
|
790 } |
|
791 |
|
792 cout << AT_MSG << "Error in sbs configuration part: " << tokens.at(0) << endl; |
|
793 cout << AT_MSG << "Supported are: arm, armv5_urel, armv5_udeb, winscw_udeb, winscw_urel." << endl; |
|
794 return false; |
|
795 |
|
796 } |
|
797 |
|
798 //EOF |