SF.net SVN: geany:[3952] branches/build-system

elextr at users.sourceforge.net elextr at xxxxx
Sat Jul 11 12:46:18 UTC 2009


Revision: 3952
          http://geany.svn.sourceforge.net/geany/?rev=3952&view=rev
Author:   elextr
Date:     2009-07-11 12:46:17 +0000 (Sat, 11 Jul 2009)

Log Message:
-----------
Fixed filetype priorities with project menu items

Modified Paths:
--------------
    branches/build-system/ChangeLog
    branches/build-system/src/build.c
    branches/build-system/src/build.h
    branches/build-system/src/filetypes.h
    branches/build-system/src/project.c

Modified: branches/build-system/ChangeLog
===================================================================
--- branches/build-system/ChangeLog	2009-07-10 15:57:12 UTC (rev 3951)
+++ branches/build-system/ChangeLog	2009-07-11 12:46:17 UTC (rev 3952)
@@ -1,6 +1,17 @@
-2009-07-10  geany test  <elextr(at)gmail(dot)com>
+2009-07-11  Lex Trotman  <elextr(at)gmail(dot)com>
 
+ * src/filetypes.h, src/filetypes.c, src/build.c, src/build.h, 
+   src/project.c
+   Removal of build menu item source made redundant by the following fix
  * src/build.c
+   Corrected priority oreder and loading of filetype dependent build
+   menu items saved in the project file.  Added print routine for 
+   debugging command sources and priorities set compile symbol 
+   PRINTBUILDCMDS true to enable
+
+2009-07-10  Lex Trotman  <elextr(at)gmail(dot)com>
+
+ * src/build.c
    fixed problem loading old format filetype files, some formatting fixes
    fixed saving new format files
    added operation for clear button on build commands dialog
@@ -8,7 +19,7 @@
    fixed loading and saving filetype files
 
 
-2009-07-09  geany test  <elextr(at)gmail(dot)com>
+2009-07-09  Lex Trotman  <elextr(at)gmail(dot)com>
 
 Configurable Build Menu Changes
 

Modified: branches/build-system/src/build.c
===================================================================
--- branches/build-system/src/build.c	2009-07-10 15:57:12 UTC (rev 3951)
+++ branches/build-system/src/build.c	2009-07-11 12:46:17 UTC (rev 3952)
@@ -153,10 +153,90 @@
 /* the various groups of commands not in the filetype struct */
 GeanyBuildCommand *ft_def=NULL, *non_ft_proj=NULL, *non_ft_pref=NULL, *non_ft_def=NULL, *exec_proj=NULL, *exec_pref=NULL, *exec_def=NULL;
 
+/* control if build commands are printed by get_build_cmd for debug */
+#ifndef PRINTBUILDCMDS
+#define PRINTBUILDCMDS FALSE
+#endif
+gboolean printbuildcmds=PRINTBUILDCMDS;
+
+static GeanyBuildCommand **cl[GBG_COUNT][BCS_COUNT] = {
+	/* 	BCS_DEF,     BCS_FT, BCS_HOME_FT, BCS_PREF,	    BCS_PROJ */
+	{   &ft_def,     NULL,   NULL,        NULL,         NULL },
+	{   &non_ft_def, NULL,   NULL,        &non_ft_pref, &non_ft_proj },
+	{   &exec_def,   NULL,   NULL,        &exec_pref,   &exec_proj } };
+
+/* for debug only, print the commands structures in priority order */
+static void printfcmds()
+{
+	GeanyFiletype	*ft=NULL;
+	GeanyDocument	*doc;
+	gint i,j,k,l,m;
+	gint cc[BCS_COUNT];
+	gchar c;
+	if (doc==NULL)doc=document_get_current();
+	if (doc!=NULL)ft = doc->file_type;
+	if(ft!=NULL)
+	{
+		printf("filetype %s\n",ft->name);
+		cl[GBG_FT][BCS_FT] = &(ft->filecmds);
+		cl[GBG_FT][BCS_HOME_FT] = &(ft->homefilecmds);
+		cl[GBG_FT][BCS_PROJ] = &(ft->projfilecmds);
+		cl[GBG_NON_FT][BCS_FT] = &(ft->ftdefcmds);
+		cl[GBG_EXEC][BCS_FT] = &(ft->execcmds);
+		cl[GBG_EXEC][BCS_HOME_FT] = &(ft->homeexeccmds);
+	}
+	for(i=0;i<BCS_COUNT;++i)
+	{
+		m=1;
+		for(j=0;j<GBG_COUNT;++j)
+		{
+			for(k=0;k<build_groups_count[j];++k)
+				if(cl[j][i]!=NULL && *(cl[j][i])!=NULL && (*(cl[j][i]))[k].exists)
+				{
+					if((*(cl[j][i]))[k].label!=NULL && (l=strlen((*(cl[j][i]))[k].label))>m)m=l;
+					if((*(cl[j][i]))[k].command!=NULL && (l=strlen((*(cl[j][i]))[k].command))>m)m=l;
+				}
+		}
+		cc[i]=m;
+	}
+	for(i=0;i<GBG_COUNT;++i)
+	{
+		for(k=0;k<build_groups_count[i];++k)
+		{
+			for(l=0;l<2;++l)
+			{
+				c=' ';
+				for(j=0;j<BCS_COUNT;++j)
+				{
+					if(cl[i][j]!=NULL && *(cl[i][j])!=NULL && (*(cl[i][j]))[k].exists)
+					{
+						if(l==0)
+							if((*(cl[i][j]))[k].label!=NULL)
+								printf("%c %*.*s",c,cc[j],cc[j],(*(cl[i][j]))[k].label);
+							else
+								printf("%c %*.*s",c,cc[j],cc[j]," ");
+						else
+							if((*(cl[i][j]))[k].command!=NULL)
+								printf("%c %*.*s",c,cc[j],cc[j],(*(cl[i][j]))[k].command);
+							else
+								printf("%c %*.*s",c,cc[j],cc[j]," ");
+					}
+					else
+						printf("%c %*.*s",c,cc[j],cc[j]," ");
+					c=',';
+				}
+				printf("\n");
+			}
+		}
+		printf("\n");
+	}
+}
+
+/* macros to save typing and make the logic visible */
 #define return_cmd_if(src, cmds) if (cmds!=NULL && cmds[cmdindex].exists && below>src)\
-									{*fr=src; return &(cmds[cmdindex]);}
+									{*fr=src; if(printbuildcmds)printf("cmd[%d,%d]=%d\n",cmdgrp,cmdindex,src); return &(cmds[cmdindex]);}
 #define return_ft_cmd_if(src, cmds) if (ft!=NULL && ft->cmds!=NULL && ft->cmds[cmdindex].exists && below>src)\
-										{*fr=src; return &(ft->cmds[cmdindex]);}
+										{*fr=src; if(printbuildcmds)printf("cmd[%d,%d]=%d\n",cmdgrp,cmdindex,src); return &(ft->cmds[cmdindex]);}
 
 /* get the next lowest command taking priority into account */
 static GeanyBuildCommand *get_next_build_cmd(GeanyDocument *doc, gint cmdgrp, gint cmdindex, gint below, gint *from)
@@ -164,7 +244,8 @@
 	GeanyBuildSource	 srcindex;
 	GeanyFiletype		*ft=NULL;
 	gint				 sink, *fr = &sink;
-	
+
+	if(printbuildcmds)printfcmds();
 	if (cmdgrp>=GBG_COUNT)return NULL;
 	if (from!=NULL)fr=from;
 	if (doc==NULL)doc=document_get_current();
@@ -174,7 +255,7 @@
 		case GBG_FT: /* order proj ft, home ft, ft, defft */
 			if (ft!=NULL)
 			{
-				return_ft_cmd_if(BCS_PROJ_FT, projfilecmds);
+				return_ft_cmd_if(BCS_PROJ, projfilecmds);
 				return_ft_cmd_if(BCS_PREF, homefilecmds);
 				return_ft_cmd_if(BCS_FT, filecmds);
 			}
@@ -188,7 +269,6 @@
 			break;
 		case GBG_EXEC: /* order proj, proj ft, pref, home ft, ft, def */
 			return_cmd_if(BCS_PROJ, exec_proj);
-			return_ft_cmd_if(BCS_PROJ_FT, projexeccmds);
 			return_cmd_if(BCS_PREF, exec_pref);
 			return_ft_cmd_if(BCS_FT, homeexeccmds);
 			return_ft_cmd_if(BCS_FT, execcmds);
@@ -226,7 +306,6 @@
 				case BCS_HOME_FT: bc=ft->homefilecmds; break;
 				case BCS_PREF:    bc=ft->homefilecmds; break;
 				case BCS_PROJ:    bc=ft->projfilecmds; break;
-				case BCS_PROJ_FT: bc=ft->projfilecmds; break;
 				default: return;
 			}
 			break;
@@ -249,7 +328,6 @@
 				case BCS_HOME_FT: bc=ft->homeexeccmds; break;
 				case BCS_PREF:    bc=exec_pref; break;
 				case BCS_PROJ:    bc=exec_proj; break;
-				case BCS_PROJ_FT: bc=ft->projexeccmds; break;
 				default: return;
 				
 			}
@@ -1708,14 +1786,13 @@
 					GeanyFiletype *ft;
 					if (pj->build_filetypes_list==NULL) pj->build_filetypes_list = g_ptr_array_new();
 					g_ptr_array_set_size(pj->build_filetypes_list, 0);
-					for (ftname=ftlist; ftname!=NULL; ++ftname)
+					for (ftname=ftlist; *ftname!=NULL; ++ftname)
 					{
 						ft=filetypes_lookup_by_name(*ftname);
 						if (ft!=NULL)
 						{
 							g_ptr_array_add(pj->build_filetypes_list, ft);
 							load_build_menu_grp(config, &(ft->projfilecmds), GBG_FT, *ftname, FALSE);
-							load_build_menu_grp(config, &(ft->projexeccmds), GBG_EXEC, *ftname, FALSE);
 						}
 					}
 					g_free(ftlist);
@@ -1797,10 +1874,11 @@
 	}
 }
 
-static void save_build_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint grp, gchar *prefix)
+static gint save_build_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint grp, gchar *prefix)
 {
 	gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
 	gchar *key;
+	gint count=0;
 	
 	if (src==NULL)return;
 	prefixlen = prefix==NULL?0:strlen(prefix);
@@ -1822,6 +1900,7 @@
 				g_key_file_set_string(config, build_grp_name, key, src[cmd].command);
 				set_key_fld(key,"BD");
 				g_key_file_set_boolean(config, build_grp_name, key, src[cmd].run_in_base_dir);
+				++count;
 			}
 			else
 			{
@@ -1834,21 +1913,30 @@
 		}
 	}
 	g_free(key);
-	
+	return count;
 }
 
+typedef struct ForEachData
+{
+	GKeyFile *config;
+	GPtrArray *ft_names;
+}ForEachData;
+
 static void foreach_project_filetype(gpointer data, gpointer user_data)
 {
 	GeanyFiletype *ft = (GeanyFiletype*)data;
-	GKeyFile *config = (GKeyFile*)user_data;
-	save_build_menu_grp(config, ft->projfilecmds, GBG_FT, ft->name);
-	save_build_menu_grp(config, ft->projexeccmds, GBG_EXEC, ft->name);
+	ForEachData *d = (ForEachData*)user_data;
+	gint i=0;
+	i += save_build_menu_grp(d->config, ft->projfilecmds, GBG_FT, ft->name);
+	if(i>0)g_ptr_array_add(d->ft_names, ft->name);
 }
 
 void save_build_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
 {
-	GeanyFiletype *ft;
-	GeanyProject  *pj;
+	GeanyFiletype 	*ft;
+	GeanyProject  	*pj;
+	ForEachData		 data;
+	
 	switch(src)
 	{
 		case BCS_HOME_FT:
@@ -1865,7 +1953,10 @@
 			pj = (GeanyProject*)ptr;
 			save_build_menu_grp(config, non_ft_proj, GBG_NON_FT, NULL);
 			save_build_menu_grp(config, exec_proj, GBG_EXEC, NULL);
-			g_ptr_array_foreach(pj->build_filetypes_list, foreach_project_filetype, (gpointer)config);
+			data.config = config;
+			data.ft_names = g_ptr_array_new();
+			g_ptr_array_foreach(pj->build_filetypes_list, foreach_project_filetype, (gpointer)(&data));
+			g_key_file_set_string_list(config, build_grp_name, "filetypes", (gchar*)(data.ft_names->pdata), data.ft_names->len);
 			break;
 		default: /* defaults and BCS_FT can't save */
 			break;

Modified: branches/build-system/src/build.h
===================================================================
--- branches/build-system/src/build.h	2009-07-10 15:57:12 UTC (rev 3951)
+++ branches/build-system/src/build.h	2009-07-11 12:46:17 UTC (rev 3952)
@@ -73,7 +73,6 @@
 	BCS_FT,		/* filetype */
 	BCS_HOME_FT,/* filetypes in home */
 	BCS_PREF,	/* preferences */
-	BCS_PROJ_FT,/* filetype in project */
 	BCS_PROJ,	/* project */
 	BCS_COUNT	/* count of how many */
 } GeanyBuildSource;

Modified: branches/build-system/src/filetypes.h
===================================================================
--- branches/build-system/src/filetypes.h	2009-07-10 15:57:12 UTC (rev 3951)
+++ branches/build-system/src/filetypes.h	2009-07-11 12:46:17 UTC (rev 3952)
@@ -139,7 +139,6 @@
 	GeanyBuildCommand *homefilecmds;
 	GeanyBuildCommand *homeexeccmds;
 	GeanyBuildCommand *projfilecmds;
-	GeanyBuildCommand *projexeccmds;
 	gint			   project_list_entry;
 	GeanyFiletypeGroupID	group;
 	gchar			 *error_regex_string;

Modified: branches/build-system/src/project.c
===================================================================
--- branches/build-system/src/project.c	2009-07-10 15:57:12 UTC (rev 3951)
+++ branches/build-system/src/project.c	2009-07-11 12:46:17 UTC (rev 3952)
@@ -330,7 +330,6 @@
 	if(ft!=NULL)
 	{
 		setptr( ft->projfilecmds, NULL);
-		setptr(ft->projexeccmds, NULL);
 		ft->project_list_entry = -1;
 	}
 }
@@ -763,8 +762,9 @@
 		rbc_array[GBG_NON_FT] = &non_ft_proj;
 		rbc_array[GBG_EXEC] = &exec_proj;
 		read_build_commands( rbc_array, e->build_properties,  GTK_RESPONSE_ACCEPT );
-		if(ft!=NULL&&ft->projfilecmds!=oldvalue && ft->project_list_entry<0)
+		if(ft!=NULL && ft->projfilecmds!=oldvalue && ft->project_list_entry<0)
 		{
+			if(p->build_filetypes_list==NULL)p->build_filetypes_list = g_ptr_array_new();
 			ft->project_list_entry = p->build_filetypes_list->len; 
 			g_ptr_array_add( p->build_filetypes_list, ft );
 		}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list