Bitstream Interpretation Library (BIL)  0.1
v5cfgmap_genArgs.cpp
Go to the documentation of this file.
1 
10 
11 using namespace bil;
12 
13 
14 std::string deviceFileName;
15 std::string dataPathName;
16 std::string mapFileName;
17 
18 
19 void parseCommandLine(int argc, char** argv)
20 {
21  // test if there are enough parameters
23 
24  // set program parameters to standard values
25  deviceFileName.clear();
26  dataPathName.clear();
27  mapFileName.clear();
28 
29  // examine all program parameters
30  std::string arg;
31  size_t positionalOptIndex = 0;
32  for (size_t i = 1; i < static_cast<size_t>(argc); ++i)
33  {
34  // copy parameter
35  arg.assign(argv[i]);
36  // no switches allowed
37  if ('-' == arg[0])
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  // process positional arguments
45  else
46  {
47  switch (positionalOptIndex)
48  {
49  case 0: deviceFileName = arg; break;
50  case 1: dataPathName = arg; break;
51  case 2: mapFileName = arg; break;
53  }
54  positionalOptIndex++;
55  }
56  }
57 
58  // if data path set, enforce that it ends with path separator
59  if (!dataPathName.empty())
60  {
61  char lastChar = dataPathName[dataPathName.size()-1];
62  if (('/' != lastChar) && ('\\' != lastChar)) dataPathName.push_back('/');
63  }
64 
65  // if mapFileName not set, set it
66  if (mapFileName.empty())
67  {
68  size_t pos = deviceFileName.find_last_of(".");
69  std::string deviceFileNameWithoutExt = deviceFileName.substr(0, pos);
70  mapFileName = deviceFileNameWithoutExt + MAP_FILE_EXT;
71  }
72 }