Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
application
bit2xml
bit2xmlArgs.cpp
Go to the documentation of this file.
1
6
#include <
application/bit2xml/bit2xmlArgs.hpp
>
7
#include <
application/bit2xml/bit2xmlMsgs.hpp
>
8
#include <
exception/CommandLineException.hpp
>
9
#include <
exception/Exception.hpp
>
10
11
using namespace
bil;
12
13
14
bool
addStylesheet
;
15
std::string
bitFileName
;
16
std::string
xmlFileName
;
17
18
19
void
parseCommandLine
(
int
argc,
char
** argv)
20
{
21
// set program parameters to standard values
22
addStylesheet
=
false
;
23
bitFileName
.clear();
24
xmlFileName
.clear();
25
26
// examine all program parameters
27
std::string arg;
28
size_t
positionalOptIndex = 0;
29
for
(
size_t
i = 1; i < static_cast<size_t>(argc); ++i)
30
{
31
// copy parameter
32
arg.assign(argv[i]);
33
// process named arguments/switches
34
if
(
'-'
== arg[0])
35
{
36
if
(
"-s"
== arg)
addStylesheet
=
true
;
37
else
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
}
45
// process positional arguments
46
else
47
{
48
switch
(positionalOptIndex)
49
{
50
case
0:
bitFileName
= arg;
break
;
51
case
1:
xmlFileName
= arg;
break
;
52
default
:
throw
CommandLineException
(
ERROR_TOO_MANY_PARAMETERS_MSG
);
53
}
54
positionalOptIndex++;
55
}
56
}
57
58
// check required bitfile name
59
if
(
bitFileName
.empty())
throw
CommandLineException
(
ERROR_NO_INPUT_FILE_MSG
);
60
// set XML file name, if not set
61
if
(
xmlFileName
.empty())
62
{
63
size_t
pos =
bitFileName
.find_last_of(
"."
);
64
std::string bitFileNameWithoutExt =
bitFileName
.substr(0, pos);
65
xmlFileName
= bitFileNameWithoutExt +
XML_FILE_EXT
;
66
}
67
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1