Added vimicxx_conf
[vimicxx.git] / src / vimicxx_conf.cc
blobb3680e705f39930c1089c9079ee837e783e797af
1 /*******************************************************************************
2 ********************************************************************************
4 Copyright (c) 2008 Ahmed S. Badran
6 Licensed under the FreeBSD License (see LICENSE)
8 Filename: vimicxx_conf.cc
9 Description: Implementation.
10 Created: 09/07/2008 05:31:00 PM PDT
11 Author: Ahmed S. Badran (Ahmed B.), ahmed.badran@gmail.com
13 ********************************************************************************
14 *******************************************************************************/
15 #include "vimicxx_conf.h"
16 #include "configfile.h"
17 #include <sys/stat.h>
18 using namespace std;
20 vimicxx_conf::vimicxx_conf(const string& vimicxx_dir):
21 conf(0), vimicxx_home(vimicxx_dir),
22 conf_path(vimicxx_home + "/vimicxx.conf")
24 conf = new configfile(conf_path);
25 struct stat tmp_stat;
26 if (stat(conf_path.c_str(), &tmp_stat) != 0) {
27 string sec_name = "vimicxx.conf";
28 conf->add_section(sec_name);
29 conf->add_key(sec_name, "version", "1.0");
30 conf->add_key(sec_name, "conf_file", conf_path);
34 const std::string
35 vimicxx_conf::err_to_string(int e)
37 switch (e) {
38 case Ok:
39 return "All ok";
40 break;
41 case Err_DuplicatePrjName:
42 return "A project with this name already exists";
43 break;
44 case Err_MissingPrjPath:
45 return "Directory does not exist or is unreadable";
46 break;
50 int
51 vimicxx_conf::add_project(const string& prj_name, const string& prj_path,
52 const vector<string>& ext_list)
54 string new_project = "project." + prj_name;
55 vector<string> projects = conf->get_sections();
56 if (find(projects.begin(), projects.end(), new_project) !=
57 projects.end()) {
58 return Err_DuplicatePrjName;
60 struct stat tmp_stat;
61 if (stat(prj_path.c_str(), &tmp_stat) != 0) {
62 return Err_MissingPrjPath;
65 conf->add_section(new_project);
66 string prj_cache = vimicxx_home + "/" + prj_name;
67 conf->add_key(new_project, "path", prj_path);
68 conf->add_key(new_project, "cache_dir", prj_cache);
69 conf->add_key(new_project, "index", prj_cache + "/index");
70 conf->add_key(new_project, "file_list", prj_cache + "/file_list.txt");
71 conf->add_key(new_project, "cscope_db", prj_cache + "/cscope_db.txt");
72 return Ok;
75 bool
76 vimicxx_conf::get_project_path(const string& prj, string* path) const
78 string secname = "project." + prj;
79 return conf->get_key_value(secname, "path", path);
81 bool
82 vimicxx_conf::get_project_cache_dir(const string& prj, string* cache_dir)
83 const
85 string secname = "project." + prj;
86 return conf->get_key_value(secname, "cache_dir", cache_dir);
89 bool
90 vimicxx_conf::get_project_index(const string& prj, string* index) const
92 string secname = "project." + prj;
93 return conf->get_key_value(secname, "index", index);
96 bool
97 vimicxx_conf::get_project_flist(const string& prj, string* flist) const
99 return ;
101 bool
102 vimicxx_conf::get_project_cscope_db(const string& prj, string* cscope_db)
103 const
105 return ;
108 vimicxx_conf::~vimicxx_conf ()
110 conf->save();