Re: [Anjuta-devel] Re: [Anjuta-list] How do I import an existing project?
- From: Biswapesh Chattopadhyay <biswapesh_chatterjee tcscal co in>
- To: Anjuta Devel <anjuta-devel lists sourceforge net>
- Cc: Anjuta ML <anjuta-list lists sourceforge net>
- Subject: Re: [Anjuta-devel] Re: [Anjuta-list] How do I import an existing project?
- Date: Thu Nov 1 01:12:02 2001
On Thu, 2001-11-01 at 13:42, Biswapesh Chattopadhyay wrote:
<snip>>
> Here's a patch against my "old" CVS (:-() which adds simple Makefile.am
> import to project-manager. You may have to hand-apply the patch I'm
> afraid :-(
<snip>
Here is a better patch which should apply cleanly.
- Biswa.
Index: src/main.c
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/main.c,v
retrieving revision 1.8
diff -r1.8 main.c
179c179,181
< pm = project_manager_new ();
---
> if (argc < 2)
> {
> pm = project_manager_new ();
181,191c183,201
< project_manager_create_project (
< PROJECT_MANAGER (pm),
< "dummy_prj",
< "DUMPRJ",
< USER_HOME_DIR"/Projets/dummy",
< TRUE, TRUE
< );
<
< g_print ("< These warnings are for testing purpose, please don't report them as bugs.\n");
< fill_project_manager (PROJECT_MANAGER (pm));
< g_print (" Now, if there's warnings, you can begin to complain about ! >\n\n");
---
> project_manager_create_project (
> PROJECT_MANAGER (pm),
> "dummy_prj",
> "DUMPRJ",
> USER_HOME_DIR"/Projets/dummy",
> TRUE, TRUE
> );
> g_print ("< These warnings are for testing purpose, please don't report them as bugs.\n");
> fill_project_manager (PROJECT_MANAGER (pm));
> g_print (" Now, if there's warnings, you can begin to complain about ! >\n\n");
> }
> else
> {
> pm = project_manager_new_from_dir(argv[1]);
> if (NULL == pm)
> {
> g_error("Failed to create project from dir");
> }
> }
Index: src/modules_dialog.c
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/modules_dialog.c,v
retrieving revision 1.6
diff -r1.6 modules_dialog.c
965a966
> {
972a974,975
> g_warning("Found duplicate %s", text);
> }
Index: src/parse.c
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/parse.c,v
retrieving revision 1.2
diff -r1.2 parse.c
48c48
< static gboolean
---
> gboolean
Index: src/parse.h
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/parse.h,v
retrieving revision 1.2
diff -r1.2 parse.h
31c31
<
---
> gboolean read_one_line (FILE *stream, GString *str);
Index: src/project_manager.c
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/project_manager.c,v
retrieving revision 1.10
diff -r1.10 project_manager.c
24a25
> #include <ctype.h>
36a38
> #include "parse.h"
1943a1946,2292
> }
>
> /* Auto-import of project from a directory - added by Biswa */
> GtkWidget *project_manager_new_from_dir(const gchar *dir_name)
> {
> GtkWidget *pm;
> gchar *configure_in;
> FILE *f;
> GString *s;
> char *start, *end, *project_name = NULL;
>
> /* Check if this is a valid directory */
> if (FALSE == file_is_directory(dir_name))
> {
> g_warning("%s: No a valid directory.", dir_name);
> return NULL;
> }
>
> /* Check for existence of configure.in */
> configure_in = g_strdup_printf("%s/%s", dir_name, "configure.in");
>
> if (NULL == (f = fopen(configure_in, "r")))
> {
> g_warning("Unable to open configure.in");
> return NULL;
> }
> /* Done. Now extract basic project info from configure.in */
> s = g_string_new("");
> /* Look for a line like this: AM_INIT_AUTOMAKE(<Project Name>, <Version>) */
> while (read_one_line(f, s))
> {
> if (NULL != (start = strstr(s->str, "AM_INIT_AUTOMAKE")))
> {
> if (NULL != (start = strchr(start, '(')))
> {
> while (!isalnum(*start) && ('_' != *start) && ('\0' != *start))
> ++ start;
> if ('\0' != *start)
> {
> for (end = start + 1; (isalnum(*end) || ('_' == *end) || ('-' == *end)); ++ end);
> *end = '\0';
> project_name = g_strdup(start);
> break;
> }
> }
> }
> }
> fclose(f);
> g_string_free(s, TRUE);
> g_free(configure_in);
> if (NULL == project_name)
> {
> g_warning("Unable to get project name");
> return NULL;
> }
> /* Seems OK so far - let us create the basic project manager struct */
> pm = project_manager_new();
> project_manager_create_project (PROJECT_MANAGER (pm), project_name, project_name, dir_name, TRUE, TRUE);
> g_free(project_name);
>
> /* Now import the project from the top Makefile.am and the subdirectories */
> project_manager_import_makefile(PROJECT_MANAGER(pm), dir_name, "/");
> return pm;
> }
>
> typedef enum
> {
> state_start_t,
> state_subdirs_t,
> state_programs_t,
> state_libraries_t,
> state_ltlibraries_t,
> state_sources_t,
> state_headers_t,
> state_scripts_t,
> state_extra_t,
> state_data_t,
> state_rule_t,
> state_target_t,
> state_ldadd_t,
> state_mans_t,
> state_texinfos_t,
> state_lisp_t,
> state_token_t
> } MakeParseState;
>
> static char *get_source_lang(const char *source_file)
> {
> char *extn = NULL;
> if (NULL != source_file)
> {
> if (NULL != (extn = strrchr(source_file, '.')))
> {
> ++ extn;
> if (0 == strcmp(extn, "c"))
> return "C";
> else if ((0 == strcmp(extn, "cxx")) ||
> (0 == strcmp(extn, "C")) ||
> (0 == strcmp(extn, "cc")) ||
> (0 == strcmp(extn, "cpp")) ||
> (0 == strcmp(extn, "h")) ||
> (0 == strcmp(extn, "H")) ||
> (0 == strcmp(extn, "hh")) ||
> (0 == strcmp(extn, "hpp")))
> return "C++";
> else if (0 == strcmp(extn, "java"))
> return "Java";
> else if (0 == strcmp(extn, "l"))
> return "Lex";
> else if (0 == strcmp(extn, "y"))
> return "Yacc";
> }
> }
> return extn;
> }
>
> static char *canonical_target_name(const char *orig_target)
> {
> if (NULL != orig_target)
> {
> char *target;
> int i;
> target = g_strdup(orig_target);
> for (i = 0; target[i] != '\0'; ++i)
> {
> if (!isalnum(target[i]) && ('_' != target[i]))
> target[i] = '_';
> }
> return target;
> }
> else
> return NULL;
> }
>
> typedef struct
> {
> char *name;
> char *canonical_name;
> CompilationOptionsData *cod;
> } PMTarget;
>
> PMTarget *pm_target_new(const char *target_name, const char *canonical_name,
> CompilationOptionsData *cod)
> {
> PMTarget *pt = g_new(PMTarget, 1);
> pt->name = g_strdup(target_name);
> pt->canonical_name = g_strdup(canonical_name);
> pt->cod = cod;
> return pt;
> }
>
> void pm_target_free(PMTarget *pt)
> {
> if (NULL != pt)
> {
> g_free(pt->name);
> g_free(pt->canonical_name);
> /* Do not free the compiler options struct */
> g_free(pt);
> }
> }
>
> PMTarget *pm_target_find(GPtrArray *target_array, const char *canonical_name)
> {
> int i;
>
> for (i=0; i < target_array->len; ++i)
> {
> if (0 == strcmp(((PMTarget *) target_array->pdata[i])->canonical_name, canonical_name))
> return (PMTarget *) target_array->pdata[i];
> }
> return NULL;
> }
>
> void pm_target_array_free(GPtrArray *targets)
> {
> int i;
>
> for (i=0; i < targets->len; ++i)
> {
> pm_target_free((PMTarget *) targets->pdata[i]);
> }
> g_ptr_array_free(targets, TRUE);
> }
>
> gboolean project_manager_import_makefile(ProjectManager *pm, const char *dir, const char *root)
> {
> char *makefile_am;
> GPtrArray *targets;
> FILE *f;
> GString *s;
> GString *first_token;
> char *start, *end;
> MakeParseState state = state_start_t;
> int status;
> char saved_char;
> char *canonical_name;
> PMTarget *current_target;
> ProjectModule module;
>
> makefile_am = g_strdup_printf("%s/%s", dir, "Makefile.am");
> if (NULL == (f = fopen(makefile_am, "r")))
> {
> g_free(makefile_am);
> return FALSE;
> }
> s = g_string_new("");
> first_token = g_string_new(NULL);
> targets = g_ptr_array_new();
> while (read_one_line(f, s))
> {
> current_target = NULL;
> if (state_rule_t == state)
> {
> if ('\t' != s->str[0])
> state = state_start_t;
> }
> else
> {
> state = state_start_t;
> g_string_assign(first_token, "");
> }
> for (start = s->str, status = 1;status;)
> {
> for (; isspace(*start); ++ start);
> if (('=' == *start) || (':' == *start))
> end = start + 1;
> else
> {
> for (end = start + 1; ((!isspace(*end)) && ('=' != *end) &&
> (':' != *end) && (';' != *end) && ('\0' != *end)); ++ end);
> }
> if (('\0' == *end) || ('\n' == *end))
> status = 0;
> saved_char = *end;
> *end = '\0';
> if (state_start_t == state)
> {
> g_string_assign(first_token, start);
> if (0 == strcmp(start, "SUBDIRS"))
> state = state_subdirs_t;
> else if (NULL != strstr(start, "_PROGRAMS"))
> state = state_programs_t;
> else if (NULL != strstr(start, "_LIBRARIES"))
> state = state_libraries_t;
> else if (NULL != strstr(start, "_LTLIBRARIES"))
> state = state_ltlibraries_t;
> else if (NULL != strstr(start, "_SOURCES"))
> {
> char *can_end = strrchr(start, '_');
> state = state_sources_t;
> /* Extract the canonical name */
> *can_end = '\0';
> current_target = pm_target_find(targets, start);
> *can_end = '_';
> }
> else if (NULL != strstr(start, "_SCRIPTS"))
> state = state_scripts_t;
> else if (NULL != strstr(start, "_DATA"))
> state = state_data_t;
> else if ((NULL != strstr(start, "_HEADERS"))
> || (NULL != strstr(start, "_INCLUDES")))
> {
> char *can_end = strrchr(start, '_');
> state = state_headers_t;
> /* Extract the canonical name */
> *can_end = '\0';
> current_target = pm_target_find(targets, start);
> *can_end = '_';
> }
> else if (NULL != strstr(start, "_LDADD"))
> state = state_ldadd_t;
> else if (NULL != strstr(start, "_MANS"))
> state = state_mans_t;
> else if (NULL != strstr(start, "_TEXINFOS"))
> state = state_texinfos_t;
> else if (NULL != strstr(start, "_LISP"))
> state = state_lisp_t;
> else if (0 == strcmp(start, "EXTRA_DIST"))
> state = state_extra_t;
> else
> state = state_token_t;
> }
> else if (0 == strcmp(start, ":"))
> state = state_rule_t;
> else if (isalnum(*start) || ('_' == *start))
> {
> if (state_subdirs_t == state) /* This is a subdirectory */
> {
> char *next_dir;
> char *subdir;
>
> if (0 == strcmp(root, "/"))
> next_dir = g_strdup_printf("/%s", start);
> else
> next_dir = g_strdup_printf("%s/%s", root, start);
> subdir = g_strdup_printf("%s/%s", dir, start);
> project_manager_add_module (pm, start, MODULE_DIRECTORY, OPTIONS_END,
> (gpointer) 1, NULL, root);
> project_manager_import_makefile(pm, subdir, next_dir);
> g_free(next_dir);
> g_free(subdir);
> }
> else if ((state_programs_t == state) /* Executables */
> || (state_libraries_t == state) /* Static libs */
> || (state_ltlibraries_t == state)) /* Shared (libtool) libs */
> {
> CompilationOptionsData *cod = g_new0(CompilationOptionsData, 1);
> if (state_programs_t == state)
> module = MODULE_EXECUTABLE;
> else if (state_libraries_t == state)
> module = MODULE_STATICLIB;
> else
> module = MODULE_SHAREDLIB;
> canonical_name = canonical_target_name(start);
> cod->target_name = convert_element_to_target_name (canonical_name);
> cod->warnings_type = ALL_WARNINGS;
> cod->optimization_level = 2;
> cod->debugging = TRUE;
> g_ptr_array_add(targets, pm_target_new(start, canonical_name, cod));
> project_manager_add_module (pm, start, module, OPTIONS_END
> , (gpointer) 1, cod, root);
> g_free(canonical_name);
> }
> else if ((state_sources_t == state) /* Sources */
> || (state_headers_t == state)) /* Headers */
> {
> char *target_root;
> if (NULL != current_target)
> target_root = g_strdup_printf("%s/%s", root, current_target->name);
> else
> target_root = g_strdup(root);
> if (state_sources_t == state)
> module = MODULE_SOURCE;
> else
> module = MODULE_HEADER;
> project_manager_add_module (pm, start, module, OPTIONS_LANG,
> (gpointer) get_source_lang(start), NULL, target_root);
> g_free(target_root);
> }
> }
> *end = saved_char;
> start = end;
> }
> }
> pm_target_array_free(targets);
> return TRUE;
Index: src/project_manager.h
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/project_manager.h,v
retrieving revision 1.6
diff -r1.6 project_manager.h
233a234,236
> GtkWidget *project_manager_new_from_dir(const gchar *dir_name);
> gboolean project_manager_import_makefile(ProjectManager *pm, const char *dir, const char *root);
>
Index: src/supports.c
===================================================================
RCS file: /var/opt/cvs/anjuta/project-manager/src/supports.c,v
retrieving revision 1.5
diff -r1.5 supports.c
31a32
> #include "utilities.h"
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]