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