Bitstream Interpretation Library (BIL)  0.1
v5data_genArgs.cpp
Go to the documentation of this file.
1 
10 
11 using namespace bil;
12 
13 
14 std::string outputPath;
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  outputPath.clear();
24 
25  // examine all program parameters
26  std::string arg;
27  size_t positionalOptIndex = 0;
28  for (size_t i = 1; i < static_cast<size_t>(argc); ++i)
29  {
30  // copy parameter
31  arg.assign(argv[i]);
32  // no switches allowed
33  if ('-' == arg[0])
34  {
35  std::string msg = ERROR_UNKNOWN_OPTION_1_MSG;
36  msg.append(arg);
37  msg.append(ERROR_UNKNOWN_OPTION_2_MSG);
38  throw CommandLineException(msg);
39  }
40  // process positional arguments
41  else
42  {
43  if (0 == positionalOptIndex) outputPath = arg;
45  positionalOptIndex++;
46  }
47  }
48 
49  // enforce that output path ends with path separator
50  if (outputPath.empty()) return;
51  char lastChar = outputPath[outputPath.size()-1];
52  if ('/' == lastChar) return;
53  if ('\\' == lastChar) return;
54  outputPath.push_back('/');
55 }