Bitstream Interpretation Library (BIL)  0.1
xdlrc_convertArgs.cpp
Go to the documentation of this file.
1 
9 
10 using namespace bil;
11 
12 
13 std::string xdlrcFileName;
14 std::string outFileName;
15 
16 
17 void parseCommandLine(int argc, char** argv)
18 {
19  // test if there are enough parameters
21 
22  // set program parameters to standard values
23  xdlrcFileName.clear();
24  outFileName.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  // no switches allowed
34  if ('-' == arg[0])
35  {
36  std::string msg = ERROR_UNKNOWN_OPTION_1_MSG;
37  msg.append(arg);
38  msg.append(ERROR_UNKNOWN_OPTION_2_MSG);
39  throw CommandLineException(msg);
40  }
41  // process positional arguments
42  else
43  {
44  switch (positionalOptIndex)
45  {
46  case 0: xdlrcFileName = arg; break;
47  case 1: outFileName = arg; break;
49  }
50  positionalOptIndex++;
51  }
52  }
53 
54  // if out filename not set, set it
55  if (outFileName.empty())
56  {
57  size_t pos = xdlrcFileName.find_last_of(".");
58  std::string xdlrcFileNameWithoutExt = xdlrcFileName.substr(0, pos);
59  outFileName = xdlrcFileNameWithoutExt + DEVICE_FILE_EXT;
60  }
61 }