[anjuta] project-wizard: Add search paths for files included in autogen template
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] project-wizard: Add search paths for files included in autogen template
- Date: Sat, 28 Jan 2012 18:46:27 +0000 (UTC)
commit fc56c114a0a986e5a3b38f522d569147b66efbdc
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sat Jan 28 11:15:49 2012 +0100
project-wizard: Add search paths for files included in autogen template
plugins/project-wizard/autogen.c | 56 +++++++++++++++++++++++++++++++++----
plugins/project-wizard/autogen.h | 3 ++
plugins/project-wizard/druid.c | 37 +++++++++++++++++++------
plugins/project-wizard/install.c | 39 +++++++++++++++-----------
plugins/project-wizard/install.h | 1 +
5 files changed, 105 insertions(+), 31 deletions(-)
---
diff --git a/plugins/project-wizard/autogen.c b/plugins/project-wizard/autogen.c
index 21d388b..d0cecc9 100644
--- a/plugins/project-wizard/autogen.c
+++ b/plugins/project-wizard/autogen.c
@@ -60,6 +60,7 @@ struct _NPWAutogen
* previous file doesn't contains
* autogen marker */
+ GList *library_paths; /* List of paths for searching include files */
/* Output file name and handle used
* when autogen output is written
* in a file */
@@ -169,6 +170,31 @@ npw_autogen_write_definition_file (NPWAutogen* this, GHashTable* values)
return TRUE;
}
+/* Set library path
+ *---------------------------------------------------------------------------*/
+
+void
+npw_autogen_set_library_path (NPWAutogen* this, const gchar *directory)
+{
+ g_return_if_fail (directory != NULL);
+
+ this->library_paths = g_list_prepend (this->library_paths, g_strdup (directory));
+}
+
+void
+npw_autogen_clear_library_path (NPWAutogen* this)
+{
+ g_list_foreach (this->library_paths, (GFunc)g_free, NULL);
+ g_list_free (this->library_paths);
+ this->library_paths = NULL;
+}
+
+GList *
+npw_autogen_get_library_paths (NPWAutogen* this)
+{
+ return this->library_paths;
+}
+
/* Set input and output
*---------------------------------------------------------------------------*/
@@ -247,7 +273,7 @@ npw_autogen_set_input_file (NPWAutogen* this, const gchar* filename, const gchar
fclose (tpl);
return ok;
-}
+}
gboolean
npw_autogen_set_output_file (NPWAutogen* this, const gchar* filename)
@@ -320,9 +346,11 @@ on_autogen_terminated (AnjutaLauncher* launcher, gint pid, gint status, gulong t
}
gboolean
-npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GError** error)
+npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GError** error)
{
- gchar* args[] = {"autogen", "-T", NULL, NULL, NULL};
+ gchar** args;
+ guint arg;
+ GList *path;
/* Autogen should not be running */
g_return_val_if_fail (this->busy == FALSE, FALSE);
@@ -339,8 +367,18 @@ npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GErro
{
this->endfunc = NULL;
}
- args[2] = (gchar *)this->tplfilename;
- args[3] = (gchar *)this->deffilename;
+ args = g_new (gchar *, 5 + g_list_length (this->library_paths) * 2);
+ args[0] = "autogen";
+ arg = 1;
+ for (path = g_list_first (this->library_paths); path != NULL; path = g_list_next (path))
+ {
+ args[arg++] = "-L";
+ args[arg++] = (gchar *)(path->data);
+ }
+ args[arg++] = "-T";
+ args[arg++] = (gchar *)this->tplfilename;
+ args[arg++] = (gchar *)this->deffilename;
+ args[arg] = NULL;
/* Check if output file can be written */
if (this->outfilename != NULL)
@@ -357,6 +395,7 @@ npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GErro
this->outfilename,
g_strerror(errno)
);
+ g_free (args);
return FALSE;
}
@@ -365,12 +404,15 @@ npw_autogen_execute (NPWAutogen* this, NPWAutogenFunc func, gpointer data, GErro
/* The template and definition file are in UTF-8 so the output too */
anjuta_launcher_set_encoding (this->launcher, "UTF-8");
-
+
this->busy = TRUE;
if (!anjuta_launcher_execute_v (this->launcher, NULL, args, NULL, on_autogen_output, this))
{
+ g_free (args);
+
return FALSE;
}
+ g_free (args);
return TRUE;
}
@@ -412,6 +454,8 @@ void npw_autogen_free (NPWAutogen* this)
g_free (this->temptplfilename);
}
+ g_list_foreach (this->library_paths, (GFunc)g_free, NULL);
+ g_list_free (this->library_paths);
/* deffilename should always be here (created in new) */
g_return_if_fail (this->deffilename);
diff --git a/plugins/project-wizard/autogen.h b/plugins/project-wizard/autogen.h
index d0ed9ee..fd7c33d 100644
--- a/plugins/project-wizard/autogen.h
+++ b/plugins/project-wizard/autogen.h
@@ -36,6 +36,9 @@ void npw_autogen_free (NPWAutogen* this);
gboolean npw_autogen_write_definition_file (NPWAutogen* this, GHashTable* values);
+void npw_autogen_set_library_path (NPWAutogen* this, const gchar *directory);
+void npw_autogen_clear_library_path (NPWAutogen* this);
+GList *npw_autogen_get_library_paths (NPWAutogen* this);
gboolean npw_autogen_set_input_file (NPWAutogen* this, const gchar* filename, const gchar* start_marker, const gchar* end_marker);
gboolean npw_autogen_set_output_file (NPWAutogen* this, const gchar* filename);
gboolean npw_autogen_set_output_callback (NPWAutogen* this, NPWAutogenOutputFunc func, gpointer user_data);
diff --git a/plugins/project-wizard/druid.c b/plugins/project-wizard/druid.c
index 090a9d9..7f17cc9 100644
--- a/plugins/project-wizard/druid.c
+++ b/plugins/project-wizard/druid.c
@@ -382,35 +382,49 @@ npw_druid_fill_selection_page (NPWDruid* druid, const gchar *directory)
/* Remove all previous data */
gtk_notebook_remove_page(druid->project_book, 0);
npw_header_list_free (druid->header_list);
+ npw_autogen_clear_library_path (druid->gen);
/* Create list of projects */
druid->header_list = npw_header_list_new ();
if (directory != NULL)
{
- /* Read project template only in specified directory */
+ /* Read project template only in specified directory,
+ * other directories can still be used to get included
+ * files */
npw_header_list_readdir (&druid->header_list, directory);
+ npw_autogen_set_library_path (druid->gen, directory);
}
- else
+
+ dir = g_build_filename (g_get_user_data_dir (), "anjuta", "project", NULL);
+ if (directory == NULL)
{
/* Read project template in user directory,
* normally ~/.local/share/anjuta/project,
- * the first template read override the others */
- dir = g_build_filename (g_get_user_data_dir (), "anjuta", "project", NULL);
+ * the first template read override the others */
npw_header_list_readdir (&druid->header_list, dir);
- g_free (dir);
+ }
+ npw_autogen_set_library_path (druid->gen, dir);
+ g_free (dir);
- /* Read project template in system directory */
- for (sys_dir = g_get_system_data_dirs (); *sys_dir != NULL; sys_dir++)
+ for (sys_dir = g_get_system_data_dirs (); *sys_dir != NULL; sys_dir++)
+ {
+ dir = g_build_filename (*sys_dir, "anjuta", "project", NULL);
+ if (directory == NULL)
{
- dir = g_build_filename (*sys_dir, "anjuta", "project", NULL);
+ /* Read project template in system directory */
npw_header_list_readdir (&druid->header_list, dir);
- g_free (dir);
}
+ npw_autogen_set_library_path (druid->gen, dir);
+ g_free (dir);
+ }
+ if (directory == NULL)
+ {
/* Read anjuta installation directory */
npw_header_list_readdir (&druid->header_list, PROJECT_WIZARD_DIRECTORY);
}
+ npw_autogen_set_library_path (druid->gen, PROJECT_WIZARD_DIRECTORY);
if (g_list_length (druid->header_list) == 0)
{
@@ -1101,10 +1115,15 @@ static void
on_druid_finish (GtkAssistant* assistant, NPWDruid* druid)
{
NPWInstall* inst;
+ GList *path;
inst = npw_install_new (druid->plugin);
npw_install_set_property (inst, druid->values);
npw_install_set_wizard_file (inst, npw_header_get_filename (druid->header));
+ for (path = g_list_last (npw_autogen_get_library_paths (druid->gen)); path != NULL; path = g_list_previous (path))
+ {
+ npw_install_set_library_path (inst, (const gchar *)path->data);
+ }
npw_install_launch (inst);
}
diff --git a/plugins/project-wizard/install.c b/plugins/project-wizard/install.c
index e954895..d689b9c 100644
--- a/plugins/project-wizard/install.c
+++ b/plugins/project-wizard/install.c
@@ -180,7 +180,7 @@ npw_copy_file (const gchar* destination, const gchar* source)
g_free (buffer);
return ok;
-}
+}
/* Installer object
*---------------------------------------------------------------------------*/
@@ -233,7 +233,6 @@ void npw_install_free (NPWInstall* this)
g_free (this);
}
-
gboolean
npw_install_set_property (NPWInstall* this, GHashTable* values)
{
@@ -262,6 +261,14 @@ npw_install_set_wizard_file (NPWInstall* this, const gchar* filename)
return TRUE;
}
+gboolean
+npw_install_set_library_path (NPWInstall* this, const gchar *directory)
+{
+ npw_autogen_set_library_path (this->gen, directory);
+
+ return TRUE;
+}
+
static void
on_install_read_action_list (const gchar* output, gpointer data)
{
@@ -278,7 +285,7 @@ on_install_end_action (gpointer data)
for (;;)
{
NPWAction *action;
-
+
if (this->action == NULL)
{
if (this->success)
@@ -303,7 +310,7 @@ on_install_end_action (gpointer data)
return;
}
action = (NPWAction *)this->action->data;
-
+
switch (npw_action_get_type (action))
{
case NPW_RUN_ACTION:
@@ -367,11 +374,11 @@ on_install_end_install_file (NPWAutogen* gen, gpointer data)
NPWInstall* this = (NPWInstall*)data;
/* Warning gen could be invalid */
-
+
for (;;)
{
NPWFile *file;
-
+
if (this->current_file == NULL)
{
this->current_file = g_list_first (this->file_list);
@@ -379,7 +386,7 @@ on_install_end_install_file (NPWAutogen* gen, gpointer data)
else
{
NPWFile *file = (NPWFile *)this->current_file->data;
-
+
if (npw_file_get_execute (file))
{
gint previous;
@@ -414,7 +421,7 @@ on_install_end_install_file (NPWAutogen* gen, gpointer data)
"");
}
on_install_end_action (this);
-
+
return;
}
file = (NPWFile *)this->current_file->data;
@@ -451,8 +458,8 @@ npw_install_install_file (NPWInstall* this)
gboolean use_autogen;
gboolean ok = TRUE;
NPWFile *file = (NPWFile *)this->current_file->data;
-
-
+
+
destination = npw_file_get_destination (file);
source = npw_file_get_source (file);
@@ -465,7 +472,7 @@ npw_install_install_file (NPWInstall* this)
on_install_end_install_file (this->gen, this);
return FALSE;
- }
+ }
/* Check if autogen is needed */
switch (npw_file_get_autogen (file))
@@ -483,11 +490,11 @@ npw_install_install_file (NPWInstall* this)
use_autogen = FALSE;
}
- len = strlen (destination) + 1;
+ len = strlen (destination) + 1;
buffer = g_new (gchar, MAX (FILE_BUFFER_SIZE, len));
- strcpy (buffer, destination);
+ strcpy (buffer, destination);
sep = buffer;
- for (;;)
+ for (;;)
{
/* Get directory one by one */
sep = strstr (sep,G_DIR_SEPARATOR_S);
@@ -526,7 +533,7 @@ npw_install_install_file (NPWInstall* this)
}
/* Record failure and display error message */
- if (!ok)
+ if (!ok)
{
this->success = FALSE;
}
@@ -559,7 +566,7 @@ npw_run_action (NPWInstall* this)
{
gchar *msg;
NPWAction *action = (NPWAction *)this->action->data;
-
+
if (this->launcher == NULL)
{
this->launcher = anjuta_launcher_new ();
diff --git a/plugins/project-wizard/install.h b/plugins/project-wizard/install.h
index 3d6088a..303963f 100644
--- a/plugins/project-wizard/install.h
+++ b/plugins/project-wizard/install.h
@@ -36,6 +36,7 @@ void npw_install_free (NPWInstall* this);
gboolean npw_install_set_property (NPWInstall* this, GHashTable* values);
gboolean npw_install_set_wizard_file (NPWInstall* this, const gchar* filename);
+gboolean npw_install_set_libray_path (NPWInstall *this, const gchar *directory);
gboolean npw_install_launch (NPWInstall* this);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]