Began implementing the VCommunication namespace.
[aesalon.git] / monitor / src / config / ArgumentParser.cpp
blob9d5bc032524c73eed4e0f4fb3508ee3d9272e578
1 /**
2 Aesalon, a tool to visualize a program's behaviour at run-time.
3 Copyright (C) 2010, Aesalon Development Team.
5 Aesalon is distributed under the terms of the GNU GPLv3. For more
6 licensing information, see the file LICENSE included with the distribution.
8 @file monitor/src/config/ArgumentParser.cpp
12 #include <iostream>
13 #include <cstring>
15 #include "config/ArgumentParser.h"
16 #include "config/Parser.h"
17 #include "config/ConcreteVault.h"
18 #include "common/PathSanitizer.h"
20 namespace Monitor {
21 namespace Config {
23 int ArgumentParser::parse(ConcreteVault *vault, char **argv) {
24 int arg;
25 for(arg = 1; argv[arg] != NULL; arg ++) {
26 if(std::strcmp(argv[arg], "--") == 0) {
27 arg ++;
28 break;
30 else if(std::strcmp(argv[arg], "--set") == 0) {
31 /*std::cout << argv[arg+1] << std::endl;*/
32 std::string line = argv[arg+1];
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 arg ++;
42 else if(std::strcmp(argv[arg], "--use-module") == 0) {
43 vault->set("::modules", argv[++arg]);
44 /*std::cout << "ArgumentParser: Using module " << argv[++arg] << std::endl;*/
46 else if(std::strcmp(argv[arg], "--search") == 0) {
47 Parser().parseDirectory(vault, argv[++arg]);
49 else if(std::strcmp(argv[arg], "--help") == 0) {
50 vault->set("::help", "true");
52 else if(std::strcmp(argv[arg], "--version") == 0) {
53 vault->set("::version", "true");
55 else if(std::strcmp(argv[arg], "--list-attributes") == 0) {
56 vault->set("::list-attributes", "true");
58 else if(std::strncmp(argv[arg], "--", 2) == 0) {
59 std::cout << "Unknown argument \"" << argv[arg] << "\".\n";
60 // TODO: do something about the error.
62 else break;
65 return arg;
68 } // namespace Config
69 } // namespace Monitor