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"
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
);
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
);
35 vimicxx_conf::err_to_string(int e
)
41 case Err_DuplicatePrjName
:
42 return "A project with this name already exists";
44 case Err_MissingPrjPath
:
45 return "Directory does not exist or is unreadable";
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
) !=
58 return Err_DuplicatePrjName
;
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");
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
);
82 vimicxx_conf::get_project_cache_dir(const string
& prj
, string
* cache_dir
)
85 string secname
= "project." + prj
;
86 return conf
->get_key_value(secname
, "cache_dir", cache_dir
);
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
);
97 vimicxx_conf::get_project_flist(const string
& prj
, string
* flist
) const
102 vimicxx_conf::get_project_cscope_db(const string
& prj
, string
* cscope_db
)
108 vimicxx_conf::~vimicxx_conf ()