Bitstream Interpretation Library (BIL)  0.1
bit2xmlArgs.cpp
Go to the documentation of this file.
1 
10 
11 using namespace bil;
12 
13 
15 std::string bitFileName;
16 std::string xmlFileName;
17 
18 
19 void parseCommandLine(int argc, char** argv)
20 {
21  // set program parameters to standard values
22  addStylesheet = false;
23  bitFileName.clear();
24  xmlFileName.clear();
25 
26  // examine all program parameters
27  std::string arg;
28  size_t positionalOptIndex = 0;
29  for (size_t i = 1; i < static_cast<size_t>(argc); ++i)
30  {
31  // copy parameter
32  arg.assign(argv[i]);
33  // process named arguments/switches
34  if ('-' == arg[0])
35  {
36  if ("-s" == arg) addStylesheet = true;
37  else
38  {
39  std::string msg = ERROR_UNKNOWN_OPTION_1_MSG;
40  msg.append(arg);
41  msg.append(ERROR_UNKNOWN_OPTION_2_MSG);
42  throw CommandLineException(msg);
43  }
44  }
45  // process positional arguments
46  else
47  {
48  switch (positionalOptIndex)
49  {
50  case 0: bitFileName = arg; break;
51  case 1: xmlFileName = arg; break;
53  }
54  positionalOptIndex++;
55  }
56  }
57 
58  // check required bitfile name
60  // set XML file name, if not set
61  if (xmlFileName.empty())
62  {
63  size_t pos = bitFileName.find_last_of(".");
64  std::string bitFileNameWithoutExt = bitFileName.substr(0, pos);
65  xmlFileName = bitFileNameWithoutExt + XML_FILE_EXT;
66  }
67 }