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