[anjuta] symbol-db: added symbol_db_util_get_source_files_by_mime () and improved benchmark prg.
- From: Massimo Cora' <mcora src gnome org>
- To: svn-commits-list gnome org
- Subject: [anjuta] symbol-db: added symbol_db_util_get_source_files_by_mime () and improved benchmark prg.
- Date: Tue, 28 Jul 2009 22:49:26 +0000 (UTC)
commit eb78cf51837496608781d5d794a96ed0fddac472
Author: Massimo Corà <mcora src gnome org>
Date: Wed Jul 29 00:45:35 2009 +0200
symbol-db: added symbol_db_util_get_source_files_by_mime () and improved benchmark prg.
fixed also some mem leaks on symbol_db_util_get_c_source_files ().
plugins/symbol-db/benchmark/benchmark.c | 29 ++++++++++++++++--
plugins/symbol-db/symbol-db-engine-utils.c | 42 ++++++++++++++++++++++-----
plugins/symbol-db/symbol-db-engine-utils.h | 14 +++++++++
3 files changed, 73 insertions(+), 12 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/benchmark.c b/plugins/symbol-db/benchmark/benchmark.c
index 99ad7d3..2da9819 100644
--- a/plugins/symbol-db/benchmark/benchmark.c
+++ b/plugins/symbol-db/benchmark/benchmark.c
@@ -25,7 +25,9 @@ int main (int argc, char** argv)
SymbolDBEngine* engine;
GPtrArray* files;
GPtrArray* languages = g_ptr_array_new();
- const gchar* root_dir;
+ gchar* root_dir;
+ GFile *g_dir;
+ GHashTable *mimes;
int i;
gtk_init(&argc, &argv);
@@ -37,9 +39,17 @@ int main (int argc, char** argv)
g_message ("Usage: benchmark <source_directory>");
return 1;
}
- root_dir = argv[1];
+
+ g_dir = g_file_new_for_path (argv[1]);
+ if (g_dir == NULL)
+ {
+ g_warning ("%s doesn't exist", argv[1]);
+ return -1;
+ }
+
+ root_dir = g_file_get_path (g_dir);
- engine = symbol_db_engine_new ("anjuta-tags");
+ engine = symbol_db_engine_new_full ("anjuta-tags", "benchmark-db");
if (!symbol_db_engine_open_db (engine, root_dir, root_dir))
{
@@ -49,7 +59,15 @@ int main (int argc, char** argv)
symbol_db_engine_add_new_project (engine, NULL, root_dir);
- files = symbol_db_util_get_c_source_files (root_dir);
+ mimes = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (mimes, "text/x-csrc", "text/x-csrc");
+ g_hash_table_insert (mimes, "text/x-chdr", "text/x-chdr");
+ g_hash_table_insert (mimes, "text/x-c++src", "text/x-c++src");
+ g_hash_table_insert (mimes, "text/x-c+++hdr", "text/x-c++hdr");
+
+ files = symbol_db_util_get_source_files_by_mime (root_dir, mimes);
+ g_hash_table_destroy (mimes);
+
for (i = 0; i < files->len; i++)
g_ptr_array_add (languages, "C");
@@ -58,6 +76,9 @@ int main (int argc, char** argv)
G_CALLBACK (on_single_file_scan_end), files);
symbol_db_engine_add_new_files_full (engine, root_dir, files, languages, TRUE);
+
+ g_free (root_dir);
+ g_object_unref (g_dir);
gtk_main();
diff --git a/plugins/symbol-db/symbol-db-engine-utils.c b/plugins/symbol-db/symbol-db-engine-utils.c
index 9e5a469..1bb1a85 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.c
+++ b/plugins/symbol-db/symbol-db-engine-utils.c
@@ -451,19 +451,41 @@ symbol_db_util_get_sym_type_conversion_hash (SymbolDBEngine *dbe)
GPtrArray*
symbol_db_util_get_c_source_files (const gchar* dir)
{
+ GHashTable *mimes;
+ GPtrArray *res;
+
+ mimes = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (mimes, "text/x-csrc", "text/x-csrc");
+ g_hash_table_insert (mimes, "text/x-chdr", "text/x-chdr");
+
+ res = symbol_db_util_get_source_files_by_mime (dir, mimes);
+
+ g_hash_table_destroy (mimes);
+ return res;
+}
+
+GPtrArray *
+symbol_db_util_get_source_files_by_mime (const gchar* dir, const GHashTable *mimes)
+{
GPtrArray* files = g_ptr_array_new();
GFile *file;
GFileEnumerator *enumerator;
GFileInfo* info;
GError *error = NULL;
-
- file = g_file_new_for_commandline_arg (dir);
+ gchar *buildable_dir;
+
+ g_return_val_if_fail (dir != NULL, NULL);
+ g_return_val_if_fail (mimes != NULL, NULL);
+
+ if ((file = g_file_new_for_commandline_arg (dir)) == NULL)
+ return NULL;
+
enumerator = g_file_enumerate_children (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_NAME,
G_FILE_QUERY_INFO_NONE,
NULL, &error);
-
+
if (!enumerator)
{
g_warning ("Could not enumerate: %s %s\n",
@@ -474,19 +496,23 @@ symbol_db_util_get_c_source_files (const gchar* dir)
return files;
}
+ buildable_dir = g_file_get_path (file);
+
for (info = g_file_enumerator_next_file (enumerator, NULL, NULL); info != NULL;
info = g_file_enumerator_next_file (enumerator, NULL, NULL))
{
const gchar *mime_type = g_file_info_get_content_type (info);
if (!mime_type)
continue;
- if (g_str_equal (mime_type, "text/x-csrc") ||
- g_str_equal (mime_type, "text/x-chdr"))
+ if (g_hash_table_lookup ((GHashTable*)mimes, mime_type) != NULL)
{
- DEBUG_PRINT ("File: %s", g_file_info_get_name (info));
- g_ptr_array_add (files, g_build_filename (dir, g_file_info_get_name (info), NULL));
+ g_ptr_array_add (files, g_build_filename (buildable_dir, g_file_info_get_name (info), NULL));
}
}
-
+
+ g_free (buildable_dir);
+ g_object_unref (enumerator);
+ g_object_unref (file);
+
return files;
}
diff --git a/plugins/symbol-db/symbol-db-engine-utils.h b/plugins/symbol-db/symbol-db-engine-utils.h
index 080f7ad..da3493e 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.h
+++ b/plugins/symbol-db/symbol-db-engine-utils.h
@@ -108,4 +108,18 @@ symbol_db_util_is_pattern_exact_match (const gchar *pattern);
GPtrArray *
symbol_db_util_get_c_source_files (const gchar* dir);
+/**
+ * This function gets all the source files in the specified dir that match mime type
+ * specified in the hashtable and returns the GPtrArray associated.
+ *
+ * @param dir Directory of the files
+ * @param mimes Hash table where the keys must be the mimes of the source files.
+ * for convenience set the values to the same value of the keys.
+ * @return A GPtrArray composed by gchar * strings like "dir + g_file_info_get_name ()"
+ */
+GPtrArray *
+symbol_db_util_get_source_files_by_mime (const gchar* dir, const GHashTable *mimes);
+
+
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]