Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
application
bitreverse
bitreverseArgs.cpp
Go to the documentation of this file.
1
6
#include <
application/bitreverse/bitreverseArgs.hpp
>
7
#include <
application/bitreverse/bitreverseMsgs.hpp
>
8
#include <
exception/CommandLineException.hpp
>
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)
40
throw
CommandLineException
(
ERROR_NO_DATAPATH_MSG
);
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
;
59
default
:
throw
CommandLineException
(
ERROR_TOO_MANY_PARAMETERS_MSG
);
60
}
61
positionalOptIndex++;
62
}
63
}
64
65
// bitfile name must not be empty
66
if
(
bitFileName
.empty())
throw
CommandLineException
(
ERROR_NO_BIT_FILE_MSG
);
67
68
// package name must not be empty
69
if
(
packageName
.empty())
throw
CommandLineException
(
ERROR_NO_PACKAGENAME_MSG
);
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
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1