1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/monitor/ArgumentParser.cpp
13 #include "monitor/ArgumentParser.h"
14 #include "config/Parser.h"
15 #include "util/MessageSystem.h"
19 int ArgumentParser::parse(Config::Vault
*vault
, char **argv
) {
21 for(arg
= 1; argv
[arg
] != NULL
; arg
++) {
22 if(std::strcmp(argv
[arg
], "--") == 0) {
26 else if(std::strcmp(argv
[arg
], "--set") == 0) {
27 if(argv
[++arg
] == NULL
) {
28 Message(Warning
, "Expected argument to --set.");
31 /*std::cout << argv[arg+1] << std::endl;*/
32 std::string line
= argv
[arg
];
33 std::string::size_type divider
= line
.find('=');
34 std::string key
= line
.substr(0, divider
);
35 std::string data
= line
.substr(divider
+1);
36 if(key
[key
.length()-1] != '+') vault
->clear(key
);
37 else key
.erase(key
.length()-1);
39 vault
->set(key
, data
);
41 else if(std::strcmp(argv
[arg
], "--use-module") == 0) {
42 if(argv
[++arg
] == NULL
) {
43 Message(Warning
, "Expected argument to --use-module.");
46 vault
->set("::modules", argv
[arg
]);
47 /*std::cout << "ArgumentParser: Using module " << argv[++arg] << std::endl;*/
49 else if(std::strcmp(argv
[arg
], "--search") == 0) {
50 Config::Parser().parseDirectory(vault
, argv
[++arg
]);
52 else if(std::strcmp(argv
[arg
], "--help") == 0 ||
53 std::strcmp(argv
[arg
], "--usage") == 0) {
54 vault
->set("::help", "true");
56 else if(std::strcmp(argv
[arg
], "--version") == 0) {
57 vault
->set("::version", "true");
59 else if(std::strcmp(argv
[arg
], "--list-attributes") == 0) {
60 vault
->set("::list-attributes", "true");
62 else if(std::strcmp(argv
[arg
], "--output") == 0) {
63 if(argv
[++arg
] == NULL
) {
64 Message(Warning
, "Expected argument to --output.");
67 vault
->set("monitor:output", argv
[arg
]);
69 else if(std::strncmp(argv
[arg
], "--", 2) == 0) {
70 Message(Warning
, "Unknown argument \"" << argv
[arg
] << "\".");
78 } // namespace Monitor