From 8edb153204afd89912c33e8edc4cb4e39a031f6c Mon Sep 17 00:00:00 2001 From: Ahmed Badran Date: Sun, 7 Sep 2008 23:27:55 -0700 Subject: [PATCH] Added vimicxx_conf Signed-off-by: Ahmed Badran --- libtool | 4 +- src/Makefile.am | 2 +- src/Makefile.in | 20 +++++++++- src/main.cc | 23 +++-------- src/vimicxx_conf.cc | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vimicxx_conf.h | 52 ++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 src/vimicxx_conf.cc create mode 100644 src/vimicxx_conf.h diff --git a/libtool b/libtool index cf08bd7..612f962 100755 --- a/libtool +++ b/libtool @@ -85,7 +85,7 @@ AR_FLAGS="cru" LTCC="gcc" # LTCC compiler flags. -LTCFLAGS="-g -O2" +LTCFLAGS="-g" # A language-specific compiler. CC="gcc" @@ -7323,7 +7323,7 @@ AR_FLAGS="cru" LTCC="gcc" # LTCC compiler flags. -LTCFLAGS="-g -O2" +LTCFLAGS="-g" # A language-specific compiler. CC="g++" diff --git a/src/Makefile.am b/src/Makefile.am index fb8286e..4917307 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = fs tests bin_PROGRAMS = vimicxx.exe -vimicxx_exe_SOURCES = main.cc +vimicxx_exe_SOURCES = main.cc vimicxx_conf.cc vimicxx_exe_CPPFLAGS = -I$(top_srcdir)/libconfigfile-1.0/src vimicxx_exe_LDADD = $(abs_top_builddir)/libconfigfile-1.0/src/libconfigfile.la EXTRA_DIST = generic_exception.h diff --git a/src/Makefile.in b/src/Makefile.in index 2bf9ae4..bb1e277 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -45,7 +45,8 @@ CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) -am_vimicxx_exe_OBJECTS = vimicxx_exe-main.$(OBJEXT) +am_vimicxx_exe_OBJECTS = vimicxx_exe-main.$(OBJEXT) \ + vimicxx_exe-vimicxx_conf.$(OBJEXT) vimicxx_exe_OBJECTS = $(am_vimicxx_exe_OBJECTS) vimicxx_exe_DEPENDENCIES = \ $(abs_top_builddir)/libconfigfile-1.0/src/libconfigfile.la @@ -184,7 +185,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = fs tests -vimicxx_exe_SOURCES = main.cc +vimicxx_exe_SOURCES = main.cc vimicxx_conf.cc vimicxx_exe_CPPFLAGS = -I$(top_srcdir)/libconfigfile-1.0/src vimicxx_exe_LDADD = $(abs_top_builddir)/libconfigfile-1.0/src/libconfigfile.la EXTRA_DIST = generic_exception.h @@ -260,6 +261,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vimicxx_exe-main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vimicxx_exe-vimicxx_conf.Po@am__quote@ .cc.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -296,6 +298,20 @@ vimicxx_exe-main.obj: main.cc @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(vimicxx_exe_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vimicxx_exe-main.obj `if test -f 'main.cc'; then $(CYGPATH_W) 'main.cc'; else $(CYGPATH_W) '$(srcdir)/main.cc'; fi` +vimicxx_exe-vimicxx_conf.o: vimicxx_conf.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(vimicxx_exe_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vimicxx_exe-vimicxx_conf.o -MD -MP -MF $(DEPDIR)/vimicxx_exe-vimicxx_conf.Tpo -c -o vimicxx_exe-vimicxx_conf.o `test -f 'vimicxx_conf.cc' || echo '$(srcdir)/'`vimicxx_conf.cc +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/vimicxx_exe-vimicxx_conf.Tpo $(DEPDIR)/vimicxx_exe-vimicxx_conf.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='vimicxx_conf.cc' object='vimicxx_exe-vimicxx_conf.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(vimicxx_exe_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vimicxx_exe-vimicxx_conf.o `test -f 'vimicxx_conf.cc' || echo '$(srcdir)/'`vimicxx_conf.cc + +vimicxx_exe-vimicxx_conf.obj: vimicxx_conf.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(vimicxx_exe_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vimicxx_exe-vimicxx_conf.obj -MD -MP -MF $(DEPDIR)/vimicxx_exe-vimicxx_conf.Tpo -c -o vimicxx_exe-vimicxx_conf.obj `if test -f 'vimicxx_conf.cc'; then $(CYGPATH_W) 'vimicxx_conf.cc'; else $(CYGPATH_W) '$(srcdir)/vimicxx_conf.cc'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/vimicxx_exe-vimicxx_conf.Tpo $(DEPDIR)/vimicxx_exe-vimicxx_conf.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='vimicxx_conf.cc' object='vimicxx_exe-vimicxx_conf.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(vimicxx_exe_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vimicxx_exe-vimicxx_conf.obj `if test -f 'vimicxx_conf.cc'; then $(CYGPATH_W) 'vimicxx_conf.cc'; else $(CYGPATH_W) '$(srcdir)/vimicxx_conf.cc'; fi` + mostlyclean-libtool: -rm -f *.lo diff --git a/src/main.cc b/src/main.cc index 7d468f2..b660766 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,7 +17,7 @@ #include #include #include -#include "configfile.h" +#include "vimicxx_conf.h" using namespace std; bool vimicxx_init(string*); @@ -30,8 +30,11 @@ int main(int argc, char* argv[]) if (!vimicxx_init(&DOTVIMICXX_PATH)) { return 1; } - configfile vimicxx_conf(DOTVIMICXX_PATH + "/vimicxx.conf"); - vimicxx_config(&vimicxx_conf); + vimicxx_conf conf(DOTVIMICXX_PATH); + vector tmp; + conf.add_project("test", "/home/ahmed/data", tmp); + conf.add_project("test2", "/home/ahmed/data", tmp); + /* vimicxx_config(&vimicxx_conf); */ if (!vimicxx_parse_cmd(argc, argv)) { return 1; } @@ -67,20 +70,6 @@ bool vimicxx_init(string* vimicxx_path) } /* - * Parse the command line, figure out what needs to be done. - */ -void vimicxx_config(configfile* conf) -{ - struct stat tmp_stat; - if ((stat(conf->get_name().c_str(), &tmp_stat)) == 0) { - return; - } - conf->add_section("vimicxx.conf"); - conf->add_key("vimicxx.conf", "conf_file_path", conf->get_name()); - conf->save(); -} - -/* * Parse the command, figure out what are we being asked for */ bool vimicxx_parse_cmd(int argc, char** argv) diff --git a/src/vimicxx_conf.cc b/src/vimicxx_conf.cc new file mode 100644 index 0000000..b3680e7 --- /dev/null +++ b/src/vimicxx_conf.cc @@ -0,0 +1,112 @@ +/******************************************************************************* +******************************************************************************** + + Copyright (c) 2008 Ahmed S. Badran + + Licensed under the FreeBSD License (see LICENSE) + + Filename: vimicxx_conf.cc + Description: Implementation. + Created: 09/07/2008 05:31:00 PM PDT + Author: Ahmed S. Badran (Ahmed B.), ahmed.badran@gmail.com + +******************************************************************************** +*******************************************************************************/ +#include "vimicxx_conf.h" +#include "configfile.h" +#include +using namespace std; + +vimicxx_conf::vimicxx_conf(const string& vimicxx_dir): + conf(0), vimicxx_home(vimicxx_dir), + conf_path(vimicxx_home + "/vimicxx.conf") +{ + conf = new configfile(conf_path); + struct stat tmp_stat; + if (stat(conf_path.c_str(), &tmp_stat) != 0) { + string sec_name = "vimicxx.conf"; + conf->add_section(sec_name); + conf->add_key(sec_name, "version", "1.0"); + conf->add_key(sec_name, "conf_file", conf_path); + } +} + +const std::string +vimicxx_conf::err_to_string(int e) +{ + switch (e) { + case Ok: + return "All ok"; + break; + case Err_DuplicatePrjName: + return "A project with this name already exists"; + break; + case Err_MissingPrjPath: + return "Directory does not exist or is unreadable"; + break; + } +} + +int +vimicxx_conf::add_project(const string& prj_name, const string& prj_path, + const vector& ext_list) +{ + string new_project = "project." + prj_name; + vector projects = conf->get_sections(); + if (find(projects.begin(), projects.end(), new_project) != + projects.end()) { + return Err_DuplicatePrjName; + } + struct stat tmp_stat; + if (stat(prj_path.c_str(), &tmp_stat) != 0) { + return Err_MissingPrjPath; + } + + conf->add_section(new_project); + string prj_cache = vimicxx_home + "/" + prj_name; + conf->add_key(new_project, "path", prj_path); + conf->add_key(new_project, "cache_dir", prj_cache); + conf->add_key(new_project, "index", prj_cache + "/index"); + conf->add_key(new_project, "file_list", prj_cache + "/file_list.txt"); + conf->add_key(new_project, "cscope_db", prj_cache + "/cscope_db.txt"); + return Ok; +} + +bool +vimicxx_conf::get_project_path(const string& prj, string* path) const +{ + string secname = "project." + prj; + return conf->get_key_value(secname, "path", path); +} +bool +vimicxx_conf::get_project_cache_dir(const string& prj, string* cache_dir) + const +{ + string secname = "project." + prj; + return conf->get_key_value(secname, "cache_dir", cache_dir); +} + +bool +vimicxx_conf::get_project_index(const string& prj, string* index) const +{ + string secname = "project." + prj; + return conf->get_key_value(secname, "index", index); +} + +bool +vimicxx_conf::get_project_flist(const string& prj, string* flist) const +{ + return ; +} +bool +vimicxx_conf::get_project_cscope_db(const string& prj, string* cscope_db) + const +{ + return ; +} + +vimicxx_conf::~vimicxx_conf () +{ + conf->save(); +} + diff --git a/src/vimicxx_conf.h b/src/vimicxx_conf.h new file mode 100644 index 0000000..5b25bad --- /dev/null +++ b/src/vimicxx_conf.h @@ -0,0 +1,52 @@ +/******************************************************************************* +******************************************************************************** + + Copyright (c) 2008 Ahmed S. Badran + + Licensed under the FreeBSD License (see LICENSE) + + Filename: vimicxx_conf.h + Description: Implements vimicxx configuration file policy. + Created: 09/07/2008 05:03:11 PM PDT + Author: Ahmed S. Badran (Ahmed B.), ahmed.badran@gmail.com + +******************************************************************************** +*******************************************************************************/ +#ifndef VIMICXX_CONF_INC +#define VIMICXX_CONF_INC +#include +#include +class configfile; +class vimicxx_conf +{ + public: + vimicxx_conf(const std::string& vimicxx_dir); + static const std::string err_to_string(int e); + int add_project(const std::string& prj_name, const std::string& + prj_path, const std::vector& ext_list); + bool get_project_path(const std::string& prj, std::string* path) const; + bool get_project_cache(const std::string& prj, std::string* cache) + const; + bool get_project_index(const std::string& prj, std::string* index) + const; + bool get_project_flist(const std::string& prj, std::string* flist) + const; + bool get_project_cscope_db(const std::string& prj, std::string* + cscope_db) const; + ~vimicxx_conf(); + private: + enum { + Ok, + Err_DuplicatePrjName, + Err_MissingPrjPath + }; + private: + configfile* conf; + const std::string vimicxx_home; + const std::string conf_path; + + private: + vimicxx_conf(const vimicxx_conf&); + const vimicxx_conf& operator=(const vimicxx_conf&); +}; +#endif // ----- #ifndef VIMICXX_CONF_INC ----- -- 2.11.4.GIT