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"
22 vimicxx_conf::vimicxx_conf(const string
& vimicxx_dir
):
23 conf(0), vimicxx_home(vimicxx_dir
),
24 conf_path(vimicxx_home
+ "/vimicxx.conf")
26 conf
= new configfile(conf_path
);
28 if (stat(conf_path
.c_str(), &tmp_stat
) != 0) {
29 string sec_name
= "vimicxx.conf";
30 conf
->add_section(sec_name
);
31 conf
->add_key(sec_name
, "version", "1.0");
32 conf
->add_key(sec_name
, "conf_file", conf_path
);
37 vimicxx_conf::err_to_string(int e
)
43 case Err_DuplicatePrjName
:
44 return "A project with this name already exists";
46 case Err_MissingPrjPath
:
47 return "Directory does not exist or is unreadable";
53 vimicxx_conf::add_project(const string
& prj_name
, const string
& prj_path
,
54 const vector
<string
>& ext_list
)
56 string new_project
= "project." + prj_name
;
57 vector
<string
> projects
= conf
->get_sections();
58 if (find(projects
.begin(), projects
.end(), new_project
) !=
60 return Err_DuplicatePrjName
;
63 if (stat(prj_path
.c_str(), &tmp_stat
) != 0) {
64 return Err_MissingPrjPath
;
68 conf
->add_section(new_project
);
69 string prj_cache
= vimicxx_home
+ "/" + prj_name
;
70 int tmp
= stat(prj_cache
.c_str(), &tmp_stat
);
71 if ((tmp
== 0) || (errno
!= ENOENT
)) {
72 return Err_DuplicatePrjCache
;
73 } else if (mkdir(prj_cache
.c_str(), S_IRUSR
| S_IWUSR
| S_IXUSR
|
74 S_IRGRP
| S_IXGRP
| S_IROTH
| S_IXOTH
) != 0) {
79 conf
->add_key(new_project
, "path", prj_path
);
80 conf
->add_key(new_project
, "cache_dir", prj_cache
);
81 conf
->add_key(new_project
, "index", prj_cache
+ "/index");
82 conf
->add_key(new_project
, "file_list", prj_cache
+ "/file_list.txt");
83 conf
->add_key(new_project
, "tags_db", prj_cache
+ "/tags_db.txt");
88 vimicxx_conf::get_project_path(const string
& prj
, string
* path
) const
90 string secname
= "project." + prj
;
91 return conf
->get_key_value(secname
, "path", path
);
94 vimicxx_conf::get_project_cache_dir(const string
& prj
, string
* cache_dir
)
97 string secname
= "project." + prj
;
98 return conf
->get_key_value(secname
, "cache_dir", cache_dir
);
102 vimicxx_conf::get_project_index(const string
& prj
, string
* index
) const
104 string secname
= "project." + prj
;
105 return conf
->get_key_value(secname
, "index", index
);
109 vimicxx_conf::get_project_flist(const string
& prj
, string
* flist
) const
111 string secname
= "project." + prj
;
112 return conf
->get_key_value(secname
, "file_list", flist
);
115 vimicxx_conf::get_project_tags_db(const string
& prj
, string
* tags_db
)
118 string secname
= "project." + prj
;
119 return conf
->get_key_value(secname
, "tags_db", tags_db
);
122 vimicxx_conf::~vimicxx_conf ()