|
0
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2008, 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:
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
#include "CmdGlobals.h"
|
|
|
20 |
#ifdef __WIN__
|
|
|
21 |
#pragma warning(disable:4786)
|
|
|
22 |
#endif
|
|
|
23 |
|
|
|
24 |
#ifndef _MSC_VER
|
|
|
25 |
#define stricmp strcasecmp
|
|
|
26 |
#endif
|
|
|
27 |
#include <iostream>
|
|
|
28 |
#include <sstream>
|
|
|
29 |
#include <map>
|
|
|
30 |
|
|
|
31 |
#include "CommandLine.h"
|
|
|
32 |
#include "HAException.h"
|
|
|
33 |
#include "CmdGlobals.h"
|
|
|
34 |
#include "CommandFile.h"
|
|
|
35 |
#include "BBCFileUtils.h"
|
|
|
36 |
#include "Utils.h"
|
|
|
37 |
#include "ReportGeneratorConstants.h"
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
using namespace std;
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
// ----------------------------------------------------------------------------
|
|
|
44 |
// CommandLine::CommandLine
|
|
|
45 |
// Constructor
|
|
|
46 |
// ----------------------------------------------------------------------------
|
|
|
47 |
//
|
|
|
48 |
CommandLine::CommandLine() : iParametersValid(-1)
|
|
|
49 |
{
|
|
|
50 |
initializeAcceptableParametersList();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
// ----------------------------------------------------------------------------
|
|
|
55 |
// CommandLine::CommandLine
|
|
|
56 |
// Constructor
|
|
|
57 |
// ----------------------------------------------------------------------------
|
|
|
58 |
//
|
|
|
59 |
CommandLine::CommandLine(char** args, int argc) : iParametersValid(-1)
|
|
|
60 |
{
|
|
|
61 |
// first check if the command line parameters contain any help command
|
|
|
62 |
int i=1;
|
|
|
63 |
while (i<argc)
|
|
|
64 |
{
|
|
|
65 |
if (stricmp("-?", args[i])==0 || stricmp("-h", args[i])==0 || stricmp("--help", args[i])==0)
|
|
|
66 |
{
|
|
|
67 |
showCommandLineOptionsAndExit();
|
|
|
68 |
}
|
|
|
69 |
i++;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
initializeAcceptableParametersList();
|
|
|
73 |
iArgList = args;
|
|
|
74 |
iArgCount = argc;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
// ----------------------------------------------------------------------------
|
|
|
78 |
// CommandLine::~CommandLine
|
|
|
79 |
// Destructor
|
|
|
80 |
// ----------------------------------------------------------------------------
|
|
|
81 |
//
|
|
|
82 |
CommandLine::~CommandLine()
|
|
|
83 |
{
|
|
|
84 |
iAcceptableParameterMap.clear();
|
|
|
85 |
parameterSpecifierSet.clear();
|
|
|
86 |
requiredParametersSet.clear();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// ----------------------------------------------------------------------------
|
|
|
90 |
// CommandLine::getParameter
|
|
|
91 |
// Returns the parameter value for a given parameter
|
|
|
92 |
// ----------------------------------------------------------------------------
|
|
|
93 |
//
|
|
|
94 |
string CommandLine::getParameter(string aParm)
|
|
|
95 |
{
|
|
|
96 |
map<string, string>::iterator mapitem = iParameterMap.find(aParm);
|
|
|
97 |
bool isValidParm = mapitem == iParameterMap.end() ? false : true;
|
|
|
98 |
if (!isValidParm)
|
|
|
99 |
{
|
|
|
100 |
string excstr = "No such parameter: ";
|
|
|
101 |
excstr += aParm;
|
|
|
102 |
throw HAException(excstr);
|
|
|
103 |
}
|
|
|
104 |
return mapitem->second;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
const map <string, string>& CommandLine::getParameters()
|
|
|
108 |
{
|
|
|
109 |
return iParameterMap;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
// ----------------------------------------------------------------------------
|
|
|
113 |
// CommandLine::CommandLine
|
|
|
114 |
// ----------------------------------------------------------------------------
|
|
|
115 |
//
|
|
|
116 |
void CommandLine::insertParameter(string paramName, bool specifierRequired, bool optional)
|
|
|
117 |
{
|
|
|
118 |
mapentry parm(paramName, "");
|
|
|
119 |
iAcceptableParameterMap.insert(parm);
|
|
|
120 |
if (specifierRequired)
|
|
|
121 |
{
|
|
|
122 |
parameterSpecifierSet.insert(paramName);
|
|
|
123 |
}
|
|
|
124 |
if (!optional)
|
|
|
125 |
{
|
|
|
126 |
requiredParametersSet.insert(paramName);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
// ----------------------------------------------------------------------------
|
|
|
131 |
// CommandLine::parameterExists
|
|
|
132 |
// Check parameter existence
|
|
|
133 |
//
|
|
|
134 |
// ----------------------------------------------------------------------------
|
|
|
135 |
//
|
|
|
136 |
bool CommandLine::parameterExists(const string& aParmName)
|
|
|
137 |
{
|
|
|
138 |
bool ret = false;
|
|
|
139 |
map<string, string>::iterator mapitem = iParameterMap.find(aParmName);
|
|
|
140 |
if (mapitem != iParameterMap.end())
|
|
|
141 |
{
|
|
|
142 |
ret = true;
|
|
|
143 |
}
|
|
|
144 |
return ret;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// ----------------------------------------------------------------------------
|
|
|
148 |
// CommandLine::initializeAcceptableParametersList
|
|
|
149 |
// Initialize acceptable parameter list
|
|
|
150 |
//
|
|
|
151 |
// ----------------------------------------------------------------------------
|
|
|
152 |
//
|
|
|
153 |
void CommandLine::initializeAcceptableParametersList()
|
|
|
154 |
{
|
|
|
155 |
// note: baseline/current may be long strings (ie. many filenames separated by semicolons)
|
|
|
156 |
insertParameter(BASELINE, true);
|
|
|
157 |
insertParameter(CURRENT, true);
|
|
|
158 |
insertParameter(BASELINEDIR, true);
|
|
|
159 |
insertParameter(CURRENTDIR, true);
|
|
|
160 |
insertParameter(REPORTFILE, true, false);
|
|
|
161 |
insertParameter(BASELINEVERSION, true);
|
|
|
162 |
insertParameter(CURRENTVERSION, true);
|
|
|
163 |
insertParameter(COMMANDFILE, false);
|
|
|
164 |
insertParameter(BASEPLATFORMDATA, true);
|
|
|
165 |
insertParameter(CURRENTPLATFORMDATA, true);
|
|
|
166 |
|
|
|
167 |
insertParameter(RECURSIVE, false);
|
|
|
168 |
insertParameter(FILEREPLACE, true);
|
|
|
169 |
insertParameter(HEADERSET, true);
|
|
|
170 |
insertParameter(BASELINEPLAT, true, false);
|
|
|
171 |
insertParameter(CURRENTPLAT, true, false);
|
|
|
172 |
insertParameter(BUNDLESIZE, true);
|
|
|
173 |
insertParameter(TRIMXML, true);
|
|
|
174 |
insertParameter(TEMPDIR, true, false);
|
|
|
175 |
insertParameter(BASEFORCEDHEADERSFILE, true);
|
|
|
176 |
insertParameter(CURRENTFORCEDHEADERSFILE, true);
|
|
|
177 |
insertParameter(DOCURL, true);
|
|
|
178 |
insertParameter(DISCARDDIRS, true);
|
|
|
179 |
#if defined(_DEBUG) || defined(DEBUG)
|
|
|
180 |
insertParameter(COMMANDLINETEST, false);
|
|
|
181 |
#endif
|
|
|
182 |
insertParameter(USETHREAD, false);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// ----------------------------------------------------------------------------
|
|
|
186 |
// CommandLine::validateParameters
|
|
|
187 |
// Validate parameters
|
|
|
188 |
//
|
|
|
189 |
// ----------------------------------------------------------------------------
|
|
|
190 |
//
|
|
|
191 |
string CommandLine::validateParameters()
|
|
|
192 |
{
|
|
|
193 |
ostringstream ret;
|
|
|
194 |
parse(iArgList, iArgCount);
|
|
|
195 |
|
|
|
196 |
map<string, string>::iterator mapitem = iParameterMap.find(TEMPDIR);
|
|
|
197 |
if (mapitem == iParameterMap.end() || mapitem->second.length() < 1)
|
|
|
198 |
{
|
|
|
199 |
const char* env2 = getenv("TEMP");
|
|
|
200 |
if (env2 != NULL)
|
|
|
201 |
{
|
|
|
202 |
string tempfiles(env2);
|
|
|
203 |
if (mapitem != iParameterMap.end())
|
|
|
204 |
{
|
|
|
205 |
mapitem->second = tempfiles;
|
|
|
206 |
} else
|
|
|
207 |
{
|
|
|
208 |
pair <string,string> parm(TEMPDIR, tempfiles);
|
|
|
209 |
iParameterMap.insert(parm);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
mapitem = iParameterMap.find(BASELINEPLAT);
|
|
|
215 |
if (mapitem == iParameterMap.end() || mapitem->second.length() < 1)
|
|
|
216 |
{
|
|
|
217 |
string envvar = BASELINEPLAT;
|
|
|
218 |
const char* env2 = getenv(toUpperCase(envvar).c_str());
|
|
|
219 |
if (env2 != NULL)
|
|
|
220 |
{
|
|
|
221 |
string tempfiles(env2);
|
|
|
222 |
if (mapitem != iParameterMap.end())
|
|
|
223 |
{
|
|
|
224 |
mapitem->second = tempfiles;
|
|
|
225 |
} else
|
|
|
226 |
{
|
|
|
227 |
pair <string,string> parm(TEMPDIR, tempfiles);
|
|
|
228 |
iParameterMap.insert(parm);
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
mapitem = iParameterMap.find(CURRENTPLAT);
|
|
|
234 |
if (mapitem == iParameterMap.end() || mapitem->second.length() < 1)
|
|
|
235 |
{
|
|
|
236 |
string envvar = CURRENTPLAT;
|
|
|
237 |
const char* env2 = getenv(toUpperCase(envvar).c_str());
|
|
|
238 |
if (env2 != NULL)
|
|
|
239 |
{
|
|
|
240 |
string tempfiles(env2);
|
|
|
241 |
if (mapitem != iParameterMap.end())
|
|
|
242 |
{
|
|
|
243 |
mapitem->second = tempfiles;
|
|
|
244 |
} else
|
|
|
245 |
{
|
|
|
246 |
pair <string,string> parm(TEMPDIR, tempfiles);
|
|
|
247 |
iParameterMap.insert(parm);
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
// START -- Support for multiple header directories --
|
|
|
253 |
mapitem = iParameterMap.find(BASELINEDIR);
|
|
|
254 |
if (mapitem == iParameterMap.end() || mapitem->second.length() < 1)
|
|
|
255 |
{
|
|
|
256 |
string envvar = BASELINEDIR;
|
|
|
257 |
const char* env2 = getenv(toUpperCase(envvar).c_str());
|
|
|
258 |
if (env2 != NULL)
|
|
|
259 |
{
|
|
|
260 |
string tempfiles(env2);
|
|
|
261 |
if (mapitem != iParameterMap.end())
|
|
|
262 |
{
|
|
|
263 |
mapitem->second = tempfiles;
|
|
|
264 |
} else
|
|
|
265 |
{
|
|
|
266 |
pair <string,string> parm(TEMPDIR, tempfiles);
|
|
|
267 |
iParameterMap.insert(parm);
|
|
|
268 |
}
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
mapitem = iParameterMap.find(CURRENTDIR);
|
|
|
273 |
if (mapitem == iParameterMap.end() || mapitem->second.length() < 1)
|
|
|
274 |
{
|
|
|
275 |
string envvar = CURRENTDIR;
|
|
|
276 |
const char* env2 = getenv(toUpperCase(envvar).c_str());
|
|
|
277 |
if (env2 != NULL)
|
|
|
278 |
{
|
|
|
279 |
string tempfiles(env2);
|
|
|
280 |
if (mapitem != iParameterMap.end())
|
|
|
281 |
{
|
|
|
282 |
mapitem->second = tempfiles;
|
|
|
283 |
} else
|
|
|
284 |
{
|
|
|
285 |
pair <string,string> parm(TEMPDIR, tempfiles);
|
|
|
286 |
iParameterMap.insert(parm);
|
|
|
287 |
}
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
// END -- Support for multiple header directories --
|
|
|
291 |
|
|
|
292 |
set<string>::iterator setitem = requiredParametersSet.begin();
|
|
|
293 |
while (setitem != requiredParametersSet.end())
|
|
|
294 |
{
|
|
|
295 |
string s = *setitem;
|
|
|
296 |
map<string, string>::iterator mapitem = iParameterMap.find(s);
|
|
|
297 |
if (mapitem == iParameterMap.end())
|
|
|
298 |
{
|
|
|
299 |
if (ret.str().length() == 0)
|
|
|
300 |
{
|
|
|
301 |
ret << "Missing required parameters: ";
|
|
|
302 |
}
|
|
|
303 |
ret << s;
|
|
|
304 |
ret << " ";
|
|
|
305 |
} else
|
|
|
306 |
{
|
|
|
307 |
// else branch not required anymore
|
|
|
308 |
if (mapitem->second.length() == 0)
|
|
|
309 |
{
|
|
|
310 |
if (ret.str().length() == 0)
|
|
|
311 |
{
|
|
|
312 |
ret << "Missing required parameters: ";
|
|
|
313 |
}
|
|
|
314 |
ret << s;
|
|
|
315 |
ret << " ";
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
setitem++;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
if (ret.str().length() > 0)
|
|
|
322 |
{
|
|
|
323 |
ret << "\n";
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
if (!parameterExists(BASELINE) && !parameterExists(BASELINEDIR) && !parameterExists(CURRENT) && !parameterExists(CURRENTDIR))
|
|
|
327 |
{
|
|
|
328 |
ret << "One of the parameter listed next must be given: -"<< BASELINEDIR <<" -"<< BASELINE <<"\n";
|
|
|
329 |
ret << "One of the parameter listed next must be given: -"<< CURRENTDIR <<" -"<< CURRENT <<"\n";
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
// check for parameter conflicts in baseline parameters
|
|
|
333 |
if (parameterExists(BASELINE) && parameterExists(BASELINEDIR))
|
|
|
334 |
{
|
|
|
335 |
ret << "Parameter conflict: -"<< BASELINEDIR <<" and -"<< BASELINE <<" cannot co-exist\n";
|
|
|
336 |
} else
|
|
|
337 |
{
|
|
|
338 |
if (parameterExists(BASELINE) && !parameterExists(CURRENT))
|
|
|
339 |
{
|
|
|
340 |
ret << "Parameter conflict: When -"<< BASELINE <<" is specified then also -"<< CURRENT <<" is required.\n";
|
|
|
341 |
}
|
|
|
342 |
if (parameterExists(BASELINEDIR) && !parameterExists(CURRENTDIR))
|
|
|
343 |
{
|
|
|
344 |
ret << "Parameter conflict: When -"<< BASELINEDIR <<" is specified then also -"<< CURRENTDIR <<" is required.\n";
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
// Same for current headers
|
|
|
349 |
if (parameterExists(CURRENT) && parameterExists(CURRENTDIR))
|
|
|
350 |
{
|
|
|
351 |
ret << "Parameter conflict: -"<< CURRENTDIR <<" and -"<< CURRENT <<" cannot co-exist\n";
|
|
|
352 |
} else
|
|
|
353 |
{
|
|
|
354 |
if (parameterExists(CURRENT) && !parameterExists(BASELINE))
|
|
|
355 |
{
|
|
|
356 |
ret << "Parameter conflict: When -"<< CURRENT <<" is specified then also -"<< BASELINE <<" is required.\n";
|
|
|
357 |
}
|
|
|
358 |
if (parameterExists(CURRENTDIR) && !parameterExists(BASELINEDIR))
|
|
|
359 |
{
|
|
|
360 |
ret << "Parameter conflict: When -"<< CURRENTDIR <<" is specified then also -"<< BASELINEDIR <<" is required.\n";
|
|
|
361 |
}
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
// Check for parameters which are specific only for baselinedir/currentdir
|
|
|
365 |
if (parameterExists(BASELINE) || parameterExists(CURRENT))
|
|
|
366 |
{
|
|
|
367 |
if (parameterExists(FILEREPLACE))
|
|
|
368 |
{
|
|
|
369 |
ret << "Parameter conflict: -"<< FILEREPLACE <<" cannot be used in combination with file parameters (-"<< CURRENT <<"/-"<< BASELINE <<")\n";
|
|
|
370 |
}
|
|
|
371 |
if (parameterExists(RECURSIVE))
|
|
|
372 |
{
|
|
|
373 |
ret << "Parameter conflict: -"<< RECURSIVE <<" cannot be used in combination with file parameters (-"<< CURRENT <<"/-"<< BASELINE <<")\n";
|
|
|
374 |
}
|
|
|
375 |
if (parameterExists(HEADERSET))
|
|
|
376 |
{
|
|
|
377 |
ret << "Parameter conflict: -"<< HEADERSET <<" cannot be used in combination with file parameters (-"<< CURRENT <<"/-"<< BASELINE <<")\n";
|
|
|
378 |
}
|
|
|
379 |
}
|
|
|
380 |
if (!parameterExists(RECURSIVE) && parameterExists(DISCARDDIRS))
|
|
|
381 |
{
|
|
|
382 |
ret << "Parameter conflict: -"<< DISCARDDIRS <<" requires -"<< RECURSIVE <<"\n";
|
|
|
383 |
}
|
|
|
384 |
// Check that all the parameters that require a specifier
|
|
|
385 |
// indeed contain a specifier. If not, it's an error and must
|
|
|
386 |
// be reported
|
|
|
387 |
set<string>::iterator specIt = parameterSpecifierSet.begin();
|
|
|
388 |
while (specIt != parameterSpecifierSet.end())
|
|
|
389 |
{
|
|
|
390 |
map<string,string>::iterator parmIt = iParameterMap.find(*specIt);
|
|
|
391 |
if (parmIt != iParameterMap.end())
|
|
|
392 |
{
|
|
|
393 |
if (parmIt->second.length() < 1)
|
|
|
394 |
{
|
|
|
395 |
ret << "Missing required specifier for parameter -";
|
|
|
396 |
ret << *specIt;
|
|
|
397 |
ret << "\n";
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
specIt++;
|
|
|
401 |
}
|
|
|
402 |
return ret.str();
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
// ----------------------------------------------------------------------------
|
|
|
407 |
// CommandLine::validParamValue
|
|
|
408 |
// Check if the parameter value is valid.
|
|
|
409 |
// ----------------------------------------------------------------------------
|
|
|
410 |
//
|
|
|
411 |
void CommandLine::validParamValue(string parm,string val)
|
|
|
412 |
{
|
|
|
413 |
string ret;
|
|
|
414 |
|
|
|
415 |
// Don't check parameter 'recursive' , 'usethread' or any other that
|
|
|
416 |
// doesn't need a value.
|
|
|
417 |
int dontCheckParm = parm.compare( RECURSIVE);
|
|
|
418 |
int threadParm = parm.compare( USETHREAD);
|
|
|
419 |
|
|
|
420 |
if ( dontCheckParm !=0 && threadParm != 0 )
|
|
|
421 |
{
|
|
|
422 |
if ( parm.compare( BASELINEVERSION )==0 || parm.compare( CURRENTVERSION )==0 || parm.compare( BUNDLESIZE )==0 || parm.compare( HEADERSET )==0 )
|
|
|
423 |
{
|
|
|
424 |
//check for atleast one char long
|
|
|
425 |
if( val.length()<=0 )
|
|
|
426 |
{
|
|
|
427 |
ret = "Invalid value for parameter: " + parm + '\n';
|
|
|
428 |
throw HAException(ret);
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
else
|
|
|
432 |
{
|
|
|
433 |
//check for atleast two char long
|
|
|
434 |
if ( val.length()<=1 )
|
|
|
435 |
{
|
|
|
436 |
ret = "Invalid value for parameter: " + parm + '\n';
|
|
|
437 |
throw HAException(ret);
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
// ----------------------------------------------------------------------------
|
|
|
444 |
// CommandLine::storeParameter
|
|
|
445 |
// Stores a parameter.
|
|
|
446 |
// ----------------------------------------------------------------------------
|
|
|
447 |
//
|
|
|
448 |
void CommandLine::storeParameter(string parm, string val, int parmType)
|
|
|
449 |
{
|
|
|
450 |
map<string, string>::iterator mapitem;
|
|
|
451 |
bool isValidParm = false;
|
|
|
452 |
string errormsg;
|
|
|
453 |
mapitem = iAcceptableParameterMap.find(parm);
|
|
|
454 |
isValidParm = mapitem == iAcceptableParameterMap.end() ? false : true;
|
|
|
455 |
validParamValue(parm, val);
|
|
|
456 |
if (isValidParm && parm.length() > 0)
|
|
|
457 |
{
|
|
|
458 |
// Valid parameters are those that the map structure has been initialised with;
|
|
|
459 |
// any other parameter is invalid, and will yield an error.
|
|
|
460 |
bool needsSpecifier = parameterSpecifierSet.find(parm) == parameterSpecifierSet.end() ? false : true;
|
|
|
461 |
map<string, string>::iterator mapitem2;
|
|
|
462 |
mapitem2 = iParameterMap.find(parm);
|
|
|
463 |
pair<string,string> parmToInsert(parm, val);
|
|
|
464 |
if (needsSpecifier)
|
|
|
465 |
{
|
|
|
466 |
// Arguments that need specifier must have both the ARGUMENT_NAME and VALUE
|
|
|
467 |
// (ie. both fields in the map must be of nonzero length)
|
|
|
468 |
if (val.length() > 0)
|
|
|
469 |
{
|
|
|
470 |
if (parmType == EParmCommandFile)
|
|
|
471 |
{
|
|
|
472 |
// command file arguments can't replace (already existing) command-line
|
|
|
473 |
// arguments; command-file args will only be used when no similar
|
|
|
474 |
// argument was given in commandline.
|
|
|
475 |
if (mapitem2 != iParameterMap.end())
|
|
|
476 |
{
|
|
|
477 |
#if ( defined(_DEBUG) || defined(DEBUG) ) && !defined(NO_DBG)
|
|
|
478 |
cout << "Not overriding parameter from file: " << parm << "\n";
|
|
|
479 |
#endif
|
|
|
480 |
} else
|
|
|
481 |
{
|
|
|
482 |
#if ( defined(_DEBUG) || defined(DEBUG) ) && !defined(NO_DBG)
|
|
|
483 |
cout << "Got command-file parameter: "<<parm<<" value: "<<val<<"\n";
|
|
|
484 |
#endif
|
|
|
485 |
iParameterMap.insert(parmToInsert);
|
|
|
486 |
}
|
|
|
487 |
} else if (parmType == EParmCommandLine)
|
|
|
488 |
{
|
|
|
489 |
// command-line argument always overrides
|
|
|
490 |
#if ( defined(_DEBUG) || defined(DEBUG) ) && !defined(NO_DBG)
|
|
|
491 |
cout << "Got command-line parameter: "<<parm<<" value: "<<val<<"\n";
|
|
|
492 |
#endif
|
|
|
493 |
iParameterMap.insert(parmToInsert);
|
|
|
494 |
} else if (parmType == EParmEnvironment)
|
|
|
495 |
{
|
|
|
496 |
}
|
|
|
497 |
} else {
|
|
|
498 |
errormsg = "Expected non-empty specifier for parameter \"-" + parm + "\"\n";
|
|
|
499 |
throw(new HAException(errormsg));
|
|
|
500 |
}
|
|
|
501 |
} else
|
|
|
502 |
{
|
|
|
503 |
#if ( defined(_DEBUG) || defined(DEBUG) ) && !defined(NO_DBG)
|
|
|
504 |
cout << "Got switch: "<<parm<<"\n";
|
|
|
505 |
#endif
|
|
|
506 |
iParameterMap.insert(parmToInsert);
|
|
|
507 |
}
|
|
|
508 |
} else {
|
|
|
509 |
// Throw an exception containing the list of valid parameter names.
|
|
|
510 |
string errormsg = "Invalid parameter: " + parm + "\n";
|
|
|
511 |
/*
|
|
|
512 |
errormsg += "Valid parameters are:\n";
|
|
|
513 |
|
|
|
514 |
map<string,string>::iterator iter;
|
|
|
515 |
iter = iAcceptableParameterMap.begin();
|
|
|
516 |
while (iter != iAcceptableParameterMap.end())
|
|
|
517 |
{
|
|
|
518 |
errormsg += "\t" + iter->first + "\n";
|
|
|
519 |
iter++;
|
|
|
520 |
}
|
|
|
521 |
*/
|
|
|
522 |
HAException e(errormsg);
|
|
|
523 |
throw(e);
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
// ----------------------------------------------------------------------------
|
|
|
529 |
// CommandLine::parse
|
|
|
530 |
// ----------------------------------------------------------------------------
|
|
|
531 |
//
|
|
|
532 |
void CommandLine::parse(char** parms, size_t count, int parmsType)
|
|
|
533 |
{
|
|
|
534 |
// "Key" string
|
|
|
535 |
string currentstr;
|
|
|
536 |
// "Value" string
|
|
|
537 |
string currentparam;
|
|
|
538 |
bool hasSpace = false;
|
|
|
539 |
bool isString = false;
|
|
|
540 |
int lastPos = -1;
|
|
|
541 |
|
|
|
542 |
// Iterate through the parameters, char by char.
|
|
|
543 |
// argument names have a preceding '-' (and whitespace),
|
|
|
544 |
// argument values only have a preceding ' ' (whitespace).
|
|
|
545 |
for (unsigned int i = 1; i < count; i++)
|
|
|
546 |
{
|
|
|
547 |
int j = 0;
|
|
|
548 |
char ch = parms[i][j];
|
|
|
549 |
if (i > 1 && j == 0 && ch == '-')
|
|
|
550 |
{
|
|
|
551 |
if (hasSpace == true && currentparam == FILEREPLACE)
|
|
|
552 |
{
|
|
|
553 |
if (currentstr.at(lastPos) != '\"')
|
|
|
554 |
{
|
|
|
555 |
currentstr = currentstr.substr(0, lastPos) + "\"" + currentstr.substr(lastPos);
|
|
|
556 |
}
|
|
|
557 |
currentstr = currentstr + "\"";
|
|
|
558 |
}
|
|
|
559 |
storeParameter(currentparam, currentstr, parmsType);
|
|
|
560 |
currentparam = "";
|
|
|
561 |
currentstr = "";
|
|
|
562 |
isString = false;
|
|
|
563 |
hasSpace = false;
|
|
|
564 |
} else if (i > 1 && j == 0 && isString == false)
|
|
|
565 |
{
|
|
|
566 |
isString = true;
|
|
|
567 |
hasSpace = false;
|
|
|
568 |
lastPos = 0;
|
|
|
569 |
} else if (i > 1 && j == 0)
|
|
|
570 |
{
|
|
|
571 |
if (hasSpace == true && currentparam == FILEREPLACE)
|
|
|
572 |
{
|
|
|
573 |
if (currentstr.at(lastPos) != '\"')
|
|
|
574 |
{
|
|
|
575 |
currentstr = currentstr.substr(0, lastPos) + "\"" + currentstr.substr(lastPos);
|
|
|
576 |
}
|
|
|
577 |
currentstr = currentstr + "\"";
|
|
|
578 |
}
|
|
|
579 |
currentstr += ' ';
|
|
|
580 |
hasSpace = false;
|
|
|
581 |
lastPos = (int)currentstr.length();
|
|
|
582 |
}
|
|
|
583 |
while (ch != '\0')
|
|
|
584 |
{
|
|
|
585 |
if (ch == '\\' || ch == '/')
|
|
|
586 |
{
|
|
|
587 |
ch = DIR_SEPARATOR;
|
|
|
588 |
}
|
|
|
589 |
if (!isString)
|
|
|
590 |
{
|
|
|
591 |
if (j > 0)
|
|
|
592 |
{
|
|
|
593 |
currentparam += ch;
|
|
|
594 |
}
|
|
|
595 |
} else
|
|
|
596 |
{
|
|
|
597 |
if (ch == ' ') hasSpace = true;
|
|
|
598 |
currentstr += ch;
|
|
|
599 |
}
|
|
|
600 |
j++;
|
|
|
601 |
ch = parms[i][j];
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
// Dump the last one as well
|
|
|
606 |
if ( count > 1)
|
|
|
607 |
{
|
|
|
608 |
if (hasSpace == true && currentparam == FILEREPLACE)
|
|
|
609 |
{
|
|
|
610 |
currentstr = "\"" + currentstr + "\"";
|
|
|
611 |
}
|
|
|
612 |
storeParameter(currentparam, currentstr, parmsType);
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
// If the processed arguments didn't come from command file,
|
|
|
616 |
// check out if one exists and parse it if necessary.
|
|
|
617 |
if (parmsType != EParmCommandFile && parameterExists(COMMANDFILE))
|
|
|
618 |
{
|
|
|
619 |
string s = BBCFileUtils::getFullPath(getParameter(COMMANDFILE));
|
|
|
620 |
storeParameter(COMMANDFILE, s);
|
|
|
621 |
if (s.size() > 0)
|
|
|
622 |
{
|
|
|
623 |
|
|
|
624 |
CommandFile f = CommandFile(s);
|
|
|
625 |
char** commands = f.getCommandBuffer();
|
|
|
626 |
size_t length = f.commandBufferLength();
|
|
|
627 |
parse(commands, length , EParmCommandFile);
|
|
|
628 |
}
|
|
|
629 |
}
|
|
|
630 |
iParametersValid = true;
|
|
|
631 |
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
// ----------------------------------------------------------------------------
|
|
|
635 |
// CommandLine::showCommandLineOptionsAndExit
|
|
|
636 |
// Show options and exit
|
|
|
637 |
// ----------------------------------------------------------------------------
|
|
|
638 |
//
|
|
|
639 |
void CommandLine::showCommandLineOptionsAndExit()
|
|
|
640 |
{
|
|
|
641 |
cout << "HeaderAnalyser v" << HEADER_ANALYSER_VERSION << " - " << HEADER_ANALYSER_DATE << endl;
|
|
|
642 |
cout << "Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.\n"
|
|
|
643 |
"\n"
|
|
|
644 |
"Usage: ha [parameters]\n"
|
|
|
645 |
"\n"
|
|
|
646 |
"Parameters:\n"
|
|
|
647 |
" -baseline FILE Baseline FILE used when comparing two files\n"
|
|
|
648 |
" -current FILE Current release FILE used when comparing two files\n"
|
|
|
649 |
" -baselinedir Baseline directory WILDCARDS used when comparing two files\n"
|
|
|
650 |
" WILDCARDS;WILDCARDS\n"
|
|
|
651 |
" -currentdir Current release DIR used when comparing two files\n"
|
|
|
652 |
" DIR;DIR\n"
|
|
|
653 |
" -baselineversion NAME NAME of the baseline\n"
|
|
|
654 |
" -currentversion NAME NAME of the current release\n"
|
|
|
655 |
" -reportfile FILE Save report to FILE\n"
|
|
|
656 |
" -commandfile FILE Read command line parameters from FILE\n"
|
|
|
657 |
" -baseplatformheaders Read baseline platform headers from DIR\n"
|
|
|
658 |
" DIR;DIR\n"
|
|
|
659 |
" -currentplatformheaders Read current release platform headers from DIR\n"
|
|
|
660 |
" DIR;DIR\n"
|
|
|
661 |
" -forcebaseinclude Force to include this FILE always for baseline\n"
|
|
|
662 |
" FILE;FILE\n"
|
|
|
663 |
" -forcecurrentinclude Force to include this FILE always for current release\n"
|
|
|
664 |
" FILE;FILE\n"
|
|
|
665 |
" -recursive Include sub directories when scanning files\n"
|
|
|
666 |
" -excludedirs DIR;DIR When recursive is in use, exclude DIR\n"
|
|
|
667 |
" -set FILE;FILE Include only this FILE to the analysis. Wildcards can be used also.\n"
|
|
|
668 |
" -replace FILE NEWFILE Notify FILE has been renamed as NEWFILE in current\n"
|
|
|
669 |
" -bundlesize COUNT Specifies COUNT files are processed in one go\n"
|
|
|
670 |
" -temp DIRECTORY DIRECTORY to store intermediate files\n"
|
|
|
671 |
" -docurl URL Includes documentation URL for each issue\n"
|
|
|
672 |
" -baseplatformdata FILE Read baseline platform data from FILE.\n"
|
|
|
673 |
" The data is used when compiling the baseline headers\n"
|
|
|
674 |
" -currentplatformdata FILE Read current platform data from FILE.\n"
|
|
|
675 |
" The data is used when compiling the current headers\n"
|
|
|
676 |
" -usethread Enables multiple threading logic.Useful for Public vs Rnd\n"
|
|
|
677 |
" Sdk analysis or small no of headers (<3000).\n"
|
|
|
678 |
"\n";
|
|
|
679 |
|
|
|
680 |
exit(0);
|
|
|
681 |
}
|