From c3264a1cd188a977b1131ee1a0fcd3116f9f0413 Mon Sep 17 00:00:00 2001 From: Ahmed Badran Date: Sun, 21 Sep 2008 00:22:27 -0700 Subject: [PATCH] Added more login to cscope_db Signed-off-by: Ahmed Badran --- config.h.in | 14 ++ configure | 405 ++++++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + libtool | 4 +- src/cscope_db.cc | 59 ++++++ src/cscope_db.h | 18 +- src/fs/tree_builder.cc | 35 +++- src/fs/tree_builder.h | 8 +- src/tests/test_dir_builder.cc | 16 +- 9 files changed, 536 insertions(+), 24 deletions(-) create mode 100644 src/cscope_db.cc diff --git a/config.h.in b/config.h.in index 7bc1aa3..b039bd2 100644 --- a/config.h.in +++ b/config.h.in @@ -59,8 +59,22 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* The size of `long *', as computed by sizeof. */ +#undef SIZEOF_LONG_P + /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to empty if `const' does not conform to ANSI C. */ #undef const +#if SIZEOF_LONG_P == 4 +typedef unsigned long long u64; +typedef unsigned int u32; +typedef unsigned short u16; +typedef unsigned char u8; +#else +typedef unsigned long u64; +typedef unsigned int u32; +typedef unsigned short u16; +typedef unsigned char u8; +#endif diff --git a/configure b/configure index ce3551f..6cd7fc3 100755 --- a/configure +++ b/configure @@ -19854,6 +19854,411 @@ _ACEOF fi +{ echo "$as_me:$LINENO: checking for long *" >&5 +echo $ECHO_N "checking for long *... $ECHO_C" >&6; } +if test "${ac_cv_type_long_p+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef long * ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_type_long_p=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_long_p=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_long_p" >&5 +echo "${ECHO_T}$ac_cv_type_long_p" >&6; } + +# The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ echo "$as_me:$LINENO: checking size of long *" >&5 +echo $ECHO_N "checking size of long *... $ECHO_C" >&6; } +if test "${ac_cv_sizeof_long_p+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo= ac_hi= +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr '(' $ac_mid ')' + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_long_p=$ac_lo;; +'') if test "$ac_cv_type_long_p" = yes; then + { { echo "$as_me:$LINENO: error: cannot compute sizeof (long *) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long *) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } + else + ac_cv_sizeof_long_p=0 + fi ;; +esac +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long * ac__type_sizeof_; +static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); } +static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (((long int) (sizeof (ac__type_sizeof_))) < 0) + { + long int i = longval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%ld\n", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%lu\n", i); + } + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_long_p=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +if test "$ac_cv_type_long_p" = yes; then + { { echo "$as_me:$LINENO: error: cannot compute sizeof (long *) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long *) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } + else + ac_cv_sizeof_long_p=0 + fi +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.val +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_p" >&5 +echo "${ECHO_T}$ac_cv_sizeof_long_p" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_LONG_P $ac_cv_sizeof_long_p +_ACEOF + + # Checks for library functions. { echo "$as_me:$LINENO: checking whether lstat dereferences a symlink specified with a trailing slash" >&5 diff --git a/configure.ac b/configure.ac index 28a4f54..bc37a58 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,7 @@ PKG_CHECK_MODULES([libconfigfile], [libconfigfile >= 1.0]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL AC_C_CONST +AC_CHECK_SIZEOF(long *) # Checks for library functions. AC_FUNC_STAT diff --git a/libtool b/libtool index cf08bd7..fa51dab 100755 --- a/libtool +++ b/libtool @@ -85,7 +85,7 @@ AR_FLAGS="cru" LTCC="gcc" # LTCC compiler flags. -LTCFLAGS="-g -O2" +LTCFLAGS="-pg" # A language-specific compiler. CC="gcc" @@ -7323,7 +7323,7 @@ AR_FLAGS="cru" LTCC="gcc" # LTCC compiler flags. -LTCFLAGS="-g -O2" +LTCFLAGS="-pg" # A language-specific compiler. CC="g++" diff --git a/src/cscope_db.cc b/src/cscope_db.cc new file mode 100644 index 0000000..5d1862c --- /dev/null +++ b/src/cscope_db.cc @@ -0,0 +1,59 @@ +/******************************************************************************* +******************************************************************************** + + Copyright (c) 2008 Ahmed S. Badran + + Licensed under the FreeBSD License (see LICENSE) + + Filename: cscope_db.cc + Description: Implementation. + Created: 09/17/2008 11:01:30 PM PDT + Author: Ahmed S. Badran (Ahmed B.), ahmed.badran@gmail.com + +******************************************************************************** +*******************************************************************************/ +#include "cscope_db.h" +#include "tree_builder.h" +#include "fs_item.h" + +cscope_db::cscope_db (const string& prj_, const string& prj_path_, const + string& prj_index_, const string& prj_flist_, const + string& prj_cscope_db_, const vector& + extensions_): + prj(prj_), prj_path(prj_path_), prj_index(prj_index_), + prj_flist(prj_flist_), prj_cscope_db(prj_cscope_db_), + extension_list(extensions_) +{ +} + +bool +cscope_db::create () +{ + tree_builder* builder = tree_builder::get_instance(); + const fs_item* tree = builder->build(prj_path, extension_list, + &file_list); + FILE* tmp; + if ((tmp = fopen(prj_flist.c_str(), "w")) == 0) { + perror("fopen"); + return false; + } + for (i = 0; i < file_list.size(); ++i) { + fprintf("%s\n", file_list[i].c_str()); + } + fclose(tmp); +} + +void +cscope_db::add_file (const string& new_file) +{ +} + +void +cscope_db::update () +{ +} + +cscope_db::~cscope_db () +{ +} + diff --git a/src/cscope_db.h b/src/cscope_db.h index a8b93e6..9806310 100644 --- a/src/cscope_db.h +++ b/src/cscope_db.h @@ -20,16 +20,22 @@ class cscope_db { public: cscope_db(const std::string& prj_, const std::string& prj_path_, const - std::string& prj_cache_dir_, const std::vector& - extensions_); - void update(); - void save(); + std::string& prj_index_, const std::string& prj_flist_, + const std::string& prj_cscope_db_, const + std::vector& extensions_); + bool create(); + void add_file(); + bool update(); ~cscope_db(); private: - const std::string prj, prj_path, prj_cache_dir; + const std::string prj, prj_path, prj_index, prj_flist, prj_cscope_db; const std::vector extension_list; + std::vector file_list; private: - cscope_db(const cscope_db& ); + cscope_db(const cscope_db&); cscope_db& operator=(const cscope_db&); + void invoke_cscope(const std::vector& args); + void build(const std::string& file_list_file); + void update(const std::string& file_list_file); }; #endif // ----- #ifndef CSCOPE_DB_INC ----- diff --git a/src/fs/tree_builder.cc b/src/fs/tree_builder.cc index 1d994a5..13d1b98 100644 --- a/src/fs/tree_builder.cc +++ b/src/fs/tree_builder.cc @@ -37,16 +37,18 @@ tree_builder::get_instance () } fs_item* -tree_builder::build (const string& path, const vector& patterns) const +tree_builder::build (const string& path, const vector& patterns, + vector* file_list) const { fs_item_dir* dir = new fs_item_dir(path); - build_dir_tree(path, dir, patterns); + build_dir_tree(path, dir, patterns, file_list); return dir; } void tree_builder::build_dir_tree (const string& path, fs_item* dir, const - vector& patterns) const + vector& patterns, vector* + file_list) const { DIR* dir_handle = 0; if ((dir_handle = opendir(path.c_str())) == 0) { @@ -71,18 +73,39 @@ tree_builder::build_dir_tree (const string& path, fs_item* dir, const (strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, "..") != 0)) { fs_item_dir* item = new fs_item_dir(entry->d_name); - build_dir_tree(tmp, item, patterns); + build_dir_tree(tmp, item, patterns, file_list); dir->add_child(item); - } else { + } else if (matches(entry->d_name, patterns)){ + file_list->push_back(tmp); fs_item_file* item = new fs_item_file(entry->d_name); dir->add_child(item); - } } delete [] buf; closedir(dir_handle); } +bool +tree_builder::matches (const char* entry, const vector& patterns) + const +{ + const unsigned entry_len = strlen(entry); + unsigned pattern_len = 0; + vector::const_iterator pos; + vector::const_iterator end = patterns.end(); + for (pos = patterns.begin(); pos != end; ++pos) { + pattern_len = (*pos).length(); + if (pattern_len > entry_len) { + continue; + } + if (strcmp(&entry[entry_len - pattern_len], (*pos).c_str()) == + 0) { + return true; + } + } + return false; +} + tree_builder::~tree_builder () { } diff --git a/src/fs/tree_builder.h b/src/fs/tree_builder.h index 700df0a..1a54663 100644 --- a/src/fs/tree_builder.h +++ b/src/fs/tree_builder.h @@ -22,12 +22,16 @@ class tree_builder public: static tree_builder* get_instance(); fs_item* build(const std::string& path, const - std::vector& patterns) const; + std::vector& patterns, + std::vector* file_list) const; ~tree_builder(); private: tree_builder(); static tree_builder* instance; void build_dir_tree(const std::string& path, fs_item* dir_item, const - std::vector& patterns) const; + std::vector& patterns, + std::vector* file_list) const; + bool matches(const char*, const std::vector& patterns) + const; }; #endif // ----- #ifndef TREE_BUILDER_INC ----- diff --git a/src/tests/test_dir_builder.cc b/src/tests/test_dir_builder.cc index 291d8e5..170cee9 100644 --- a/src/tests/test_dir_builder.cc +++ b/src/tests/test_dir_builder.cc @@ -18,16 +18,16 @@ #include "fs_item.h" #include using namespace std; -int main() +int main(int argc, char** argv) { - vector tmp; + vector tmp, file_list; tree_builder* builder = tree_builder::get_instance();; - fs_item* tree = builder->build("/home/ahmed/data", tmp); - const vector entries = tree->get_children(); - int i = 0; - while (i < entries.size()) { - printf("entry: %s\n", entries[i]->get_name().c_str()); - i++; + tmp.push_back(".h"); + tmp.push_back(".c"); + tmp.push_back(".cpp"); + fs_item* tree = builder->build(argv[1], tmp, &file_list); + for (int i = 0; i < file_list.size(); ++i) { + printf("%s\n", file_list[i].c_str()); } return 0; } -- 2.11.4.GIT