Bitstream Interpretation Library (BIL)  0.1
bitextractArgs.cpp
Go to the documentation of this file.
1 
9 
10 using namespace bil;
11 
12 
13 std::string bitFileName;
14 std::string dataPathName;
15 std::string outCfgFile;
16 std::string outIndexFile;
17 
18 
19 void parseCommandLine(int argc, char** argv)
20 {
21  // set program parameters to standard values
22  bitFileName.clear();
23  dataPathName.clear();
24  outCfgFile.clear();
25  outIndexFile.clear();
26 
27  // examine all program parameters
28  std::string arg;
29  size_t positionalOptIndex = 0;
30  size_t argCount = static_cast<size_t>(argc);
31  for (size_t i = 1; i < argCount; ++i)
32  {
33  // copy parameter
34  arg.assign(argv[i]);
35  // process named arguments/switches
36  if ('-' == arg[0])
37  {
38  if ("-dp" == arg)
39  {
40  if ((++i) >= argCount)
42  dataPathName.assign(argv[i]);
43  }
44  else
45  {
46  std::string msg = ERROR_UNKNOWN_OPTION_1_MSG;
47  msg.append(arg);
48  msg.append(ERROR_UNKNOWN_OPTION_2_MSG);
49  throw CommandLineException(msg);
50  }
51  }
52  // process positional arguments
53  else
54  {
55  switch (positionalOptIndex)
56  {
57  case 0: bitFileName = arg; break;
58  case 1: outCfgFile = arg; break;
59  case 2: outIndexFile = arg; break;
61  }
62  positionalOptIndex++;
63  }
64  }
65 
66  // check required bitfile name
68 
69  // if data path set, enforce that it ends with path separator
70  if (!dataPathName.empty())
71  {
72  char lastChar = dataPathName[dataPathName.size()-1];
73  if (('/' != lastChar) && ('\\' != lastChar)) dataPathName.push_back('/');
74  }
75 
76  // set output configuration and output index file name, if not set
77  if (outCfgFile.empty() || outIndexFile.empty())
78  {
79  size_t pos = bitFileName.find_last_of(".");
80  std::string bitFileNameWithoutExt = bitFileName.substr(0, pos);
81  if (outCfgFile.empty()) outCfgFile = bitFileNameWithoutExt + CFG_FILE_EXT;
82  if (outIndexFile.empty()) outIndexFile = bitFileNameWithoutExt + INDEX_FILE_EXT;
83  }
84 }