Began implementing Marshaller system again.
[aesalon.git] / src / monitor / ArgumentParser.cpp
blob8bdb6a1ecddec34e0fb7deed8ca894d6c0dba108
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
8 */
10 #include <cstring>
11 #include <iostream>
13 #include "monitor/ArgumentParser.h"
14 #include "config/Parser.h"
15 #include "util/MessageSystem.h"
17 namespace Monitor {
19 int ArgumentParser::parse(Config::Vault *vault, char **argv) {
20 int arg;
21 for(arg = 1; argv[arg] != NULL; arg ++) {
22 if(std::strcmp(argv[arg], "--") == 0) {
23 arg ++;
24 break;
26 else if(std::strcmp(argv[arg], "--set") == 0) {
27 if(argv[++arg] == NULL) {
28 Message(Warning, "Expected argument to --set.");
29 continue;
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 vault->clear(key);
38 vault->set(key, data);
40 else if(std::strcmp(argv[arg], "--use-module") == 0) {
41 if(argv[++arg] == NULL) {
42 Message(Warning, "Expected argument to --use-module.");
43 continue;
45 vault->set("::modules", argv[arg]);
46 /*std::cout << "ArgumentParser: Using module " << argv[++arg] << std::endl;*/
48 else if(std::strcmp(argv[arg], "--search") == 0) {
49 Config::Parser().parseDirectory(vault, argv[++arg]);
51 else if(std::strcmp(argv[arg], "--help") == 0 ||
52 std::strcmp(argv[arg], "--usage") == 0) {
53 vault->set("::help", "true");
55 else if(std::strcmp(argv[arg], "--version") == 0) {
56 vault->set("::version", "true");
58 else if(std::strcmp(argv[arg], "--list-attributes") == 0) {
59 vault->set("::list-attributes", "true");
61 else if(std::strcmp(argv[arg], "--output") == 0) {
62 if(argv[++arg] == NULL) {
63 Message(Warning, "Expected argument to --output.");
64 continue;
66 vault->set("::output", argv[arg]);
68 else if(std::strncmp(argv[arg], "--", 2) == 0) {
69 Message(Warning, "Unknown argument \"" << argv[arg] << "\".");
71 else break;
74 return arg;
77 } // namespace Monitor