File: kolabformatchecker.cpp

package info (click to toggle)
libkolabxml 1.2.1-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,612 kB
  • sloc: cpp: 9,911; ansic: 596; xml: 430; python: 221; php: 194; sh: 94; makefile: 12; cs: 9
file content (99 lines) | stat: -rw-r--r-- 3,226 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2011  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <boost/program_options.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "src/kolabformat.h"

namespace po = boost::program_options;
using namespace std;

int main(int argc, char *argv[])
{
    // Declare the supported options.
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help", "produce help message")
        ("contact", "parse contact")
        ("distlist", "parse distlist")
        ("event", "parse event")
        ("todo", "parse todo")
        ("journal", "parse journal")
        ("freebusy", "parse freebusy")
        ("note", "parse note")
        ("configuration", "parse configuration")
        ("file", "parse file")
        ("input-file", po::value<std::vector<std::string> >(), "input files of given type")
    ;

    po::positional_options_description p;
    p.add("input-file", -1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).
            options(desc).positional(p).run(), vm);
    po::notify(vm);

    if (vm.count("help")) {
        cout << desc << "\n";
        return 1;
    }

    vector<string> inputFiles;
    if (vm.count("input-file")) {
        inputFiles = vm["input-file"].as< vector<string> >();
    } else {
        cout << "Specify input-file";
        return -1;
    }

    for(vector<string>::const_iterator it = inputFiles.begin();
            it != inputFiles.end(); it++){

        if (vm.count("contact")) {
            Kolab::readContact(*it, true);
        } else if (vm.count("distlist")) {
            Kolab::readDistlist(*it, true);
        } else if (vm.count("event")) {
            Kolab::readEvent(*it, true);
        } else if (vm.count("todo")) {
            Kolab::readTodo(*it, true);
        } else if (vm.count("journal")) {
            Kolab::readJournal(*it, true);
        } else if (vm.count("freebusy")) {
            Kolab::readFreebusy(*it, true);
        } else if (vm.count("note")) {
            Kolab::readNote(*it, true);
        } else if (vm.count("configuration")) {
            Kolab::readConfiguration(*it, true);
        } else if (vm.count("file")) {
            Kolab::readFile(*it, true);
        } else {
            cout << "Specify type";
            return -1;
        }
        if (Kolab::error()) {
            cout << "Error: " << Kolab::errorMessage() << endl;
            return -1;
        } else {
            cout << "Parsed message without error." << endl;
        }
    }
    return 0;
}