Lex Trotman schrieb:
Hi all,

During the development of the build-system branch there has been a suggestion that there needs to be an upgrade of the setting of the directory in which build menu commands are run.

Currently the operation is:

Filetype commands are intended to be run on the currently open file, so they always run in the source file directory. This allows them to be used for simple single file work without configuration, and allows movement around more complex source trees, again without configuration.

Non-filetype commands are a bit more complicated. Since this group is intended to run commands independent of the source file, in theory it could be any directory, But there are a couple of likely candidates: - for make type builders to build the entire package the top of the tree is the right place, that is a fixed directory (at least for each package it is) - for make type bulders that build lower levels than the whole package, then somewhere below the top of the tree is right, that isn't a fixed directory (an example of where you use this is make doc in geany's doc subdirectory)

The current behaviour of Geany is to provide an approximation of both, at least if you are using a project. A fixed directory for all commands for this package is provided by the base_dir of the project, otherwise the directory of the current file is used as the most likely place to run commands within the tree. (Note although it is called the project base directory, I am not aware of any reason why it can't be set to any arbitrary directory)

When running without a project there is no base_dir available, so Geany runs commands in the directory of the current file or not at all. This could be improved by having a preference for a common directory (a base_dir for non-project use) and by having per-command directories.

Suggested addition

Now that build menu items are fully configurable, Thomas has suggested that there be a directory configured per command and I agree with him for the non-filetype and execute commands, filetype commands should always run in the directory of the file. To select known directories such as the base_dir or the directory of the current file, substitutions such as %p for project could be used (like %e and %f in the commands).

If one of the substitutions is the directory of the project file, then all paths could effectively be made relative to the project file and if it is in the source tree, so allow it to be moved around with the source tree without re-configuration, and even checked into version control and checked out in a working directory somewhere else. This would be really useful when a project configured special commands as new users wouldn't have to re-configure them.

Please let me know agree/disagree.

There is a new commit in the build-system branch that makes the error regular expressions work, I think. I find it very hard to test since you need a compiler or other command that outputs errors in a format that Geany's built-in parsing doesn't recognise, and it recognises a lot. If you have such an animal please try it out.

Cheers
Lex
Ah, I see you begin to understand where I was coming from :)

I think %d (for the directory of the current file) and %p (for the project's base dir) would already be sufficient for most stuff.

Here's the patch (sync'd to your latest changes) that allows for easier plugging in the working dir GtkEntry. It doesn't implement it yet, just makes later adding easier (I'm in favor of atomic comm its where possible, so the actual addition would be a seperate patch).


Best regards.
Index: src/build.c
===================================================================
--- src/build.c	(Revision 3969)
+++ src/build.c	(Arbeitskopie)
@@ -76,12 +76,12 @@
 static const gchar RUN_SCRIPT_CMD[] = "./geany_run_script.sh";
 #endif
 
-
 /* pack group (<8) and command (<32) into a user_data pointer */
 #define GRP_CMD_TO_POINTER(grp, cmd) GINT_TO_POINTER((((grp)&7)<<5)|((cmd)&0x1f))
 #define GBO_TO_POINTER(gbo) (GRP_CMD_TO_POINTER(GBO_TO_GBG(gbo), GBO_TO_CMD(gbo)))
 #define GPOINTER_TO_CMD(gptr) (GPOINTER_TO_INT(gptr)&0x1f)
 #define GPOINTER_TO_GRP(gptr) ((GPOINTER_TO_INT(gptr)&0xe0)>>5)
+#define FOREACH_GEANYBUILDCMD_ENTRY(i) for(i = 0; i < BC_CMDENTRIES_COUNT; i++)
 
 static gpointer last_toolbutton_action = GBO_TO_POINTER(GBO_BUILD);
 
@@ -173,9 +173,10 @@
 	GeanyFiletype	*ft=NULL;
 	GeanyDocument	*doc;
 	gint i,j,k,l,m;
+    enum GeanyBuildCmdEntries n;
 	gint cc[BCS_COUNT];
 	gchar c;
-	if (doc==NULL)doc=document_get_current();
+    doc=document_get_current();
 	if (doc!=NULL)ft = doc->file_type;
 	if(ft!=NULL)
 	{
@@ -194,9 +195,12 @@
 		{
 			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;
+                {
+                    int n;
+                    FOREACH_GEANYBUILDCMD_ENTRY(n)
+                    {
+                        if((*(cl[j][i]))[k].entries[n]!=NULL && (l=strlen((*(cl[j][i]))[k].entries[n]))>m)m=l;
+                    }
 				}
 		}
 		cc[i]=m;
@@ -212,16 +216,13 @@
 				{
 					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]," ");
+                        FOREACH_GEANYBUILDCMD_ENTRY(n)
+                        {
+                            if((*(cl[i][j]))[k].entries[i]!=NULL)
+                                printf("%c %*.*s",c,cc[j],cc[j],(*(cl[i][j]))[k].entries[i]);
+                            else
+                                printf("%c %*.*s",c,cc[j],cc[j]," ");
+                        }
 					}
 					else
 						printf("%c %*.*s",c,cc[j],cc[j]," ");
@@ -537,7 +538,26 @@
 	return build_info.pid;
 }
 
+static gchar* id_to_str(GeanyBuildCommand *bc, gint id)
+{
+    return bc->entries[id];
+}
 
+static gchar* buildcmd_label(GeanyBuildCommand *bc)
+{
+    return id_to_str(bc, BC_LABEL);
+}
+
+static gchar* buildcmd_cmd(GeanyBuildCommand *bc)
+{
+    return id_to_str(bc, BC_COMMAND);
+}
+
+static const gchar* config_keys[] = {
+    [BC_LABEL]      = "CM",
+    [BC_COMMAND]    = "BD",
+};
+
 /* Returns: NULL if there was an error, or the working directory the script was created in.
  * vte_cmd_nonscript is the location of a string which is filled with the command to be used
  * when vc->skip_run_script is set, otherwise it will be set to NULL */
@@ -560,7 +580,7 @@
 	locale_filename = utils_get_locale_from_utf8(doc->file_name);
 
 	have_project = (project != NULL && NZV(project->run_cmd));
-	cmd = get_build_cmd(doc, GBG_EXEC, 0, NULL)->command;
+	cmd = buildcmd_cmd(get_build_cmd(doc, GBG_EXEC, 0, NULL));
 	/* TODO fix all this stuff */
 
 	if (strstr(cmd, "%e") != NULL)
@@ -987,17 +1007,22 @@
 	gchar *dir;
 	gchar *full_command;
 	GeanyBuildCommand *buildcmd = get_build_cmd(doc, grp, cmd, NULL);
+    gchar* cmdstr;
 	
-	if (buildcmd==NULL)return;
+	if (buildcmd==NULL)
+        return;
+
+    cmdstr = buildcmd_cmd(buildcmd);
+
 	if (cmd_cat != NULL)
 	{
-		if (buildcmd->command != NULL)
-			full_command = g_strconcat(buildcmd->command, cmd_cat, NULL);
+		if (cmdstr != NULL)
+			full_command = g_strconcat(cmdstr, cmd_cat, NULL);
 		else
 			full_command = g_strdup(cmd_cat);
 	}
 	else
-		full_command = buildcmd->command;
+		full_command = cmdstr;
 	if (grp == GBG_FT)
 	{
 		dir=NULL; /* allways run in doc dir */
@@ -1063,7 +1088,7 @@
 			return;
 		}
 		GeanyBuildCommand *bc = get_build_cmd(doc, grp, cmd, NULL);
-		if (bc!=NULL && strcmp(bc->command, "builtin")==0)
+		if (bc!=NULL && strcmp(buildcmd_cmd(bc), "builtin")==0)
 		{
 			if (doc==NULL)return;
 			gchar *uri = g_strconcat("file:///", g_path_skip_root(doc->file_name), NULL);
@@ -1174,14 +1199,14 @@
 			for (j=bs->build_cmd; j<build_groups_count[grp]; ++j)
 			{
 				GeanyBuildCommand *bc = get_build_cmd(NULL, grp, j, NULL);
-				gchar *lbl = (bc==NULL)?"":bc->label;
+				gchar *lbl = (bc==NULL)?"":buildcmd_label(bc);
 				create_build_menu_item(menu, keygroup, accel_group, bs, lbl, grp, j);
 			}
 		}
 		else
 		{
 			GeanyBuildCommand *bc = get_build_cmd(NULL, bs->build_grp, bs->build_cmd, NULL);
-			gchar *lbl = (bc==NULL)?"":bc->label;
+			gchar *lbl = (bc==NULL)?"":buildcmd_label(bc);
 			create_build_menu_item(menu, keygroup, accel_group, bs, lbl, bs->build_grp, bs->build_cmd);
 		}
 	}
@@ -1252,16 +1277,23 @@
 				for (cmd=bs->build_cmd; cmd<cmdcount; ++cmd)
 				{
 					GtkWidget *menu_item = menu_items.menu_item[grp][cmd];
+                    gchar* label;
 					bc = get_build_cmd(doc, grp, cmd, NULL);
+                    if (bc)
+                        label = buildcmd_label(bc);
+                    else
+                        label = NULL;
+
 					if (grp < GBG_EXEC)
 					{
 						cmd_sensitivity = 
 							(grp == GBG_FT && bc!=NULL && have_path && ! build_running) ||
 							(grp == GBG_NON_FT && bc!=NULL && ! build_running);
 						gtk_widget_set_sensitive(menu_item, cmd_sensitivity);
-						if (bc!=NULL && bc->label!=NULL && strlen(bc->label)>0)
+						if (bc != NULL && label != NULL
+                                && strlen(label) > 0)
 						{
-							geany_menu_item_set_label(menu_item, bc->label);
+							geany_menu_item_set_label(menu_item, label);
 							gtk_widget_show_all(menu_item);
 							vis |= TRUE;
 						}
@@ -1282,9 +1314,10 @@
 							image = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
 						}
 						gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image);
-						if (bc!=NULL && bc->label!=NULL && strlen(bc->label)>0)
+						if (bc != NULL && label != NULL
+                                && strlen(label) > 0)
 						{
-							geany_menu_item_set_label(menu_item, bc->label);
+							geany_menu_item_set_label(menu_item, label);
 							gtk_widget_show_all(menu_item);
 							vis |= TRUE;
 						}
@@ -1415,7 +1448,8 @@
  *-------------------------------------------------------*/
 
 typedef struct RowWidgets {
-	GtkWidget *label, *command, *dir;
+	GtkWidget *entries[BC_CMDENTRIES_COUNT];
+    GtkWidget *dir;
 	GeanyBuildSource src, dst;
 	GeanyBuildCommand *cmdsrc;
 	gint grp,cmd;
@@ -1426,19 +1460,24 @@
 {
 	RowWidgets *r = (RowWidgets*)user_data;
 	gint src;
+    enum GeanyBuildCmdEntries i;
 	GeanyBuildCommand *bc = get_next_build_cmd(NULL, r->grp, r->cmd, r->dst, &src);
-	if(bc!=NULL)
+	if(bc != NULL)
 	{
 		r->cmdsrc = bc;
 		r->src = src;
-		gtk_entry_set_text(GTK_ENTRY(r->label), bc->label!=NULL?bc->label:"");
-		gtk_entry_set_text(GTK_ENTRY(r->command), bc->command!=NULL?bc->command:"");
+        FOREACH_GEANYBUILDCMD_ENTRY(i)
+        {
+            gtk_entry_set_text(GTK_ENTRY(r->entries[i]), id_to_str(bc,i) != NULL? id_to_str(bc,i):"");
+        }
 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(r->dir), bc->run_in_base_dir);
 	}
 	else
 	{
-		gtk_entry_set_text(GTK_ENTRY(r->label), "");
-		gtk_entry_set_text(GTK_ENTRY(r->command), "");
+        FOREACH_GEANYBUILDCMD_ENTRY(i)
+        {
+            gtk_entry_set_text(GTK_ENTRY(r->entries[i]), "");
+        }
 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(r->dir), FALSE);
 	}
 	r->cleared = TRUE;
@@ -1457,55 +1496,70 @@
 	gchar 	*labeltxt, *cmdtxt;
 	GeanyBuildCommand *bc;
 	gint src;
+    enum GeanyBuildCmdEntries i;
 	gboolean ribd; /* run in base directory */
+
+    gint column = 0;
 	
 	if (grp == GBO_TO_GBG(GBO_MAKE_CUSTOM) && cmd == GBO_TO_CMD(GBO_MAKE_CUSTOM)){ labeltxt = g_strdup_printf("%d:*", cmd+1); }
 	else labeltxt = g_strdup_printf("%d:", cmd+1);
 	label = gtk_label_new(labeltxt);
 	g_free(labeltxt);
-	gtk_table_attach(table, label, 0, 1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
+	gtk_table_attach(table, label, column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
 	roww = g_new0(RowWidgets, 1);
 	roww->src = BCS_COUNT;
 	roww->grp = grp;
 	roww->cmd = cmd;
 	roww->dst = dst;
-	roww->label = gtk_entry_new();
-	gtk_table_attach(table, roww->label, 1, 2, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
-	roww->command = gtk_entry_new();
-	gtk_table_attach(table, roww->command, 2, 3, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
+    FOREACH_GEANYBUILDCMD_ENTRY(i)
+    {
+        column+=1;
+        roww->entries[i] = gtk_entry_new();
+        gtk_table_attach(table, roww->entries[i], column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
+    }
+    column++;
 	if (dir)
 	{
 		check = gtk_check_button_new();
-		gtk_table_attach(table, check, 3, 4, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
+		gtk_table_attach(table, check, column, column+1,row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
 	}
 	else check = NULL;
+
+    column++;
 	roww->dir = check;
 	clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_SMALL_TOOLBAR);
 	clear = gtk_button_new();
 	gtk_button_set_image(GTK_BUTTON(clear), clearicon);
 	g_signal_connect((gpointer)clear, "clicked", G_CALLBACK(on_clear_dialog_row), (gpointer)roww);
-	gtk_table_attach(table, clear, 4, 5, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
+	gtk_table_attach(table, clear, column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0);
 	roww->cmdsrc = bc = get_build_cmd(doc, grp, cmd, &src);
-	if (bc!=NULL)
-	{
-		if ((labeltxt = bc->label)==NULL)labeltxt="";
-		if ((cmdtxt = bc->command)==NULL)cmdtxt="";
-		ribd = bc->run_in_base_dir;
-		roww->src = src;
-	}
-	else
-	{
-		labeltxt = cmdtxt = "";
-		ribd = FALSE;
-	}
-	gtk_entry_set_text(GTK_ENTRY(roww->label), labeltxt);
-	gtk_entry_set_text(GTK_ENTRY(roww->command), cmdtxt);
+
+    FOREACH_GEANYBUILDCMD_ENTRY(i)
+    {
+        gchar *str;
+        if (bc!=NULL)
+        {
+            if ((str = bc->entries[i])==NULL)str="";
+            if (i == 0)
+            {
+                ribd = bc->run_in_base_dir;
+                roww->src = src;
+            }
+        }
+        else
+        {
+            str = "";
+            if (i == 0)
+                ribd = FALSE;
+        }
+        gtk_entry_set_text(GTK_ENTRY(roww->entries[i]), str);
+    }
 	if (dir)
 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), ribd);
 	if (src>dst || (grp==GBG_FT && (doc==NULL || doc->file_type==NULL)))
 	{
-		gtk_widget_set_sensitive(roww->label, FALSE);
-		gtk_widget_set_sensitive(roww->command, FALSE);
+        FOREACH_GEANYBUILDCMD_ENTRY(i)
+            gtk_widget_set_sensitive(roww->entries[i], FALSE);
 		gtk_widget_set_sensitive(check, FALSE);
 		gtk_widget_set_sensitive(clear, FALSE);
 	}
@@ -1629,8 +1683,8 @@
 static int stcmp(const gchar *a, const gchar *b)
 {
 	if (a==NULL && b==NULL) return 0;
-	if (a==NULL && b!=NULL) return strlen(b);
-	if (a!=NULL && b==NULL) return strlen(a);
+	if (a==NULL && b!=NULL) return -1;
+	if (a!=NULL && b==NULL) return 1;
 	return strcmp(a, b);
 }
 
@@ -1645,14 +1699,18 @@
 
 static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow, gint grp, gint cmd)
 {
-	gchar			*label, *command;
+	gchar			*entries[BC_CMDENTRIES_COUNT];
 	gboolean		 dir;
 	gboolean		 changed = FALSE;
 	GeanyBuildSource src;
+    enum GeanyBuildCmdEntries i;
 
 	src = table_data->rows[drow]->src;
-	label = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->label)));
-	command = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->command)));
+
+    FOREACH_GEANYBUILDCMD_ENTRY(i)
+    {
+        entries[i] = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->entries[i])));
+    }
 	dir = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(table_data->rows[drow]->dir));
 	if (table_data->rows[drow]->cleared)
 	{
@@ -1665,18 +1723,18 @@
 		}
 	}
 	if ((table_data->rows[drow]->cmdsrc==NULL &&                          /* originally there was no content */
-		  (strlen(label)>0 || strlen(command)>0  || dir)) ||              /* and now there is some  or */
+		  (entries[BC_LABEL] || entries[BC_COMMAND] || dir)) ||              /* and now there is some  or */
 		(table_data->rows[drow]->cmdsrc!=NULL &&                          /* originally there was content and */
-		  (stcmp(label, table_data->rows[drow]->cmdsrc->label)!=0 ||      /* label is different or */
-		    stcmp(command, table_data->rows[drow]->cmdsrc->command)!=0 || /* command is different or */
+		  (stcmp(entries[BC_LABEL], table_data->rows[drow]->cmdsrc->entries[BC_LABEL])!=0 ||      /* label is different or */
+		    stcmp(entries[BC_COMMAND], table_data->rows[drow]->cmdsrc->entries[BC_COMMAND])!=0 || /* command is different or */
 		    dir != table_data->rows[drow]->cmdsrc->run_in_base_dir)))     /* runinbasedir is different */
 	{
 		if (dst->dst[grp]!=NULL)
 		{
 			if (*(dst->dst[grp])==NULL)
 				*(dst->dst[grp]) = g_new0(GeanyBuildCommand, build_groups_count[grp]);
-			setptr((*(dst->dst[grp]))[cmd].label, label);
-			setptr((*(dst->dst[grp]))[cmd].command, command);
+            FOREACH_GEANYBUILDCMD_ENTRY(i)
+                setptr((*(dst->dst[grp]))[cmd].entries[i], entries[i]);
 			(*(dst->dst[grp]))[cmd].run_in_base_dir = dir;
 			(*(dst->dst[grp]))[cmd].exists = TRUE;
 			(*(dst->dst[grp]))[cmd].changed=TRUE;
@@ -1685,7 +1743,8 @@
 	}
 	else
 	{
-		g_free(label); g_free(command);
+        FOREACH_GEANYBUILDCMD_ENTRY(i)
+            g_free(entries[i]);
 	}
 	return changed;
 }
@@ -1812,7 +1871,7 @@
 
 static void load_build_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint grp, gchar *prefix, gboolean loc)
 {
-	gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
+	gint i, cmd, prefixlen; /* NOTE prefixlen used in macros above */
 	GeanyBuildCommand *dstcmd;
 	gchar *key;
 	static gchar cmdbuf[3]="  ";
@@ -1836,10 +1895,10 @@
 		if (label!=NULL)
 		{
 			dstcmd[cmd].exists = TRUE;
-			setptr(dstcmd[cmd].label, label);
-			set_key_fld(key,"CM");
-			setptr(dstcmd[cmd].command, g_key_file_get_string(config, build_grp_name, key, NULL));
-			set_key_fld(key,"BD");
+            setptr(dstcmd[cmd].entries[BC_LABEL], label);
+            set_key_fld(key,"CM");
+            setptr(dstcmd[cmd].entries[BC_COMMAND], g_key_file_get_string(config, build_grp_name, key, NULL));
+            set_key_fld(key,"BD");
 			dstcmd[cmd].run_in_base_dir = g_key_file_get_boolean(config, build_grp_name, key, NULL);
 		}
 		else dstcmd[cmd].exists = FALSE;
@@ -1917,6 +1976,13 @@
 		gchar *value;
 		gboolean bvalue;
 		gint cmd;
+#define ASSIGN(type, id, string, value) \
+        do { \
+            type[GBO_TO_CMD(id)].exists = TRUE; \
+            type[GBO_TO_CMD(id)].entries[BC_LABEL] = g_strdup(_(string)); \
+            type[GBO_TO_CMD(id)].entries[BC_COMMAND] = value; \
+        } while (0)
+        
 		switch(src)
 		{
 			case BCS_FT:
@@ -1925,24 +1991,18 @@
 				value = g_key_file_get_string(config, "build_settings", "compiler", NULL);
 				if (value != NULL)
 				{
-					ft->filecmds[GBO_TO_CMD(GBO_COMPILE)].exists = TRUE;
-					ft->filecmds[GBO_TO_CMD(GBO_COMPILE)].label = g_strdup(_("_Compile"));
-					ft->filecmds[GBO_TO_CMD(GBO_COMPILE)].command = value;
+                    ASSIGN(ft->filecmds, GBO_COMPILE, "_Compile", value);
 				}
 				value = g_key_file_get_string(config, "build_settings", "linker", NULL);
 				if (value != NULL)
 				{
-					ft->filecmds[GBO_TO_CMD(GBO_BUILD)].exists = TRUE;
-					ft->filecmds[GBO_TO_CMD(GBO_BUILD)].label = g_strdup(_("_Build"));
-					ft->filecmds[GBO_TO_CMD(GBO_BUILD)].command = value;
+                    ASSIGN(ft->filecmds, GBO_BUILD, "_Build", value);
 				}
 				if (ft->execcmds==NULL)ft->execcmds = g_new0(GeanyBuildCommand, build_groups_count[GBG_EXEC]);
 				value = g_key_file_get_string(config, "build_settings", "run_cmd", NULL);
 				if (value != NULL)
 				{
-					ft->execcmds[GBO_TO_CMD(GBO_EXEC)].exists = TRUE;
-					ft->execcmds[GBO_TO_CMD(GBO_EXEC)].label = g_strdup(_("_Execute"));
-					ft->execcmds[GBO_TO_CMD(GBO_EXEC)].command = value;
+                    ASSIGN(ft->execcmds, GBO_EXEC, "_Execute", value);
 				}
 				setptr(ft->error_regex_string, g_key_file_get_string(config, "build_settings", "error_regex", NULL));
 				break;
@@ -1958,9 +2018,7 @@
 				if (value !=NULL)
 				{
 					if (exec_proj==NULL)exec_proj = g_new0(GeanyBuildCommand, build_groups_count[GBG_EXEC]);
-					exec_proj[GBO_TO_CMD(GBO_EXEC)].exists = TRUE;
-					exec_proj[GBO_TO_CMD(GBO_EXEC)].label = g_strdup(_("Execute"));
-					exec_proj[GBO_TO_CMD(GBO_EXEC)].command = value;
+                    ASSIGN(exec_proj, GBO_EXEC, "Execute", value);
 				}
 				break;
 			case BCS_PREF:
@@ -1968,15 +2026,9 @@
 				value = g_key_file_get_string(config, "tools", "make_cmd", NULL);
 				if (value!=NULL)
 				{
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_ALL)].exists = TRUE;
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_ALL)].label = g_strdup(_("_Make All"));
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_ALL)].command = value;
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_CUSTOM)].exists = TRUE;
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_CUSTOM)].label = g_strdup(_("Make Custom _Target"));
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_CUSTOM)].command = g_strdup_printf("%s ",value);
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_OBJECT)].exists = TRUE;
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_OBJECT)].label = g_strdup(_("Make _Object"));
-					non_ft_pref[GBO_TO_CMD(GBO_MAKE_OBJECT)].command = g_strdup_printf("%s %%e.o",value);
+                    ASSIGN(non_ft_pref, GBO_MAKE_ALL, g_strdup(_("_Make All")), value);
+                    ASSIGN(non_ft_pref, GBO_MAKE_CUSTOM, g_strdup(_("Make Custom _Target")), g_strdup_printf("%s ",value));
+                    ASSIGN(non_ft_pref, GBO_MAKE_OBJECT, g_strdup(_("Make _Object")), g_strdup_printf("%s %%e.o",value));
 				}
 				break;
 			default:
@@ -1990,6 +2042,7 @@
 	gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
 	gchar *key;
 	gint count=0;
+    enum GeanyBuildCmdEntries i;
 	
 	if (src==NULL)return;
 	prefixlen = prefix==NULL?0:strlen(prefix);
@@ -2006,20 +2059,22 @@
 			set_key_fld(key, "LB");
 			if (src[cmd].exists)
 			{
-				g_key_file_set_string(config, build_grp_name, key, src[cmd].label);
-				set_key_fld(key,"CM");
-				g_key_file_set_string(config, build_grp_name, key, src[cmd].command);
-				set_key_fld(key,"BD");
+                FOREACH_GEANYBUILDCMD_ENTRY(i)
+                {
+                    g_key_file_set_string(config, build_grp_name, key, src[cmd].entries[i]);
+                    set_key_fld(key, config_keys[i]);
+                }
 				g_key_file_set_boolean(config, build_grp_name, key, src[cmd].run_in_base_dir);
 				++count;
 			}
 			else
 			{
+                FOREACH_GEANYBUILDCMD_ENTRY(i)
+                {                    
+                    g_key_file_remove_key(config, build_grp_name, key, NULL);
+                    set_key_fld(key, config_keys[i]);
+                }
 				g_key_file_remove_key(config, build_grp_name, key, NULL);
-				set_key_fld(key,"CM");
-				g_key_file_remove_key(config, build_grp_name, key, NULL);
-				set_key_fld(key,"BD");
-				g_key_file_remove_key(config, build_grp_name, key, NULL);
 			}
 		}
 	}
@@ -2093,7 +2148,7 @@
 			data.ft_names = g_ptr_array_new();
 			g_ptr_array_foreach(pj->build_filetypes_list, foreach_project_filetype, (gpointer)(&data));
 			if (data.ft_names->pdata!=NULL)
-				g_key_file_set_string_list(config, build_grp_name, "filetypes", (gchar**)(data.ft_names->pdata), data.ft_names->len);
+				g_key_file_set_string_list(config, build_grp_name, "filetypes", (const gchar**)(data.ft_names->pdata), data.ft_names->len);
 			else
 				g_key_file_remove_key(config, build_grp_name, "filetypes", NULL);
 			g_ptr_array_free(data.ft_names, TRUE);
@@ -2113,33 +2168,36 @@
 }
 
 static struct {
-	gchar *label,*command;
+	gchar *entries[BC_CMDENTRIES_COUNT];
 	gboolean dir;
 	GeanyBuildCommand **ptr;
 	gint index;
 } default_cmds[] = { 
-	{N_("_Make"), "make", FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_ALL)}, 
-	{N_("Make Custom _Target"), "make ", FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_CUSTOM)}, 
-	{N_("Make _Object"), "make %e.o", FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_OBJECT)},
-	{N_("_Execute"), "./%e", FALSE, &exec_def, GBO_TO_CMD(GBO_EXEC)},
-	{NULL, NULL, FALSE, NULL, 0 }
+	{ {N_("_Make"), "make"}, FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_ALL)}, 
+	{ {N_("Make Custom _Target"), "make "}, FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_CUSTOM)}, 
+	{ {N_("Make _Object"), "make %e.o" }, FALSE, &non_ft_def, GBO_TO_CMD(GBO_MAKE_OBJECT)},
+	{ {N_("_Execute"), "./%e" }, FALSE, &exec_def, GBO_TO_CMD(GBO_EXEC)},
+	{ {NULL, NULL}, FALSE, NULL, 0 }
 };
 
 void build_init()
 {
 	GtkWidget *item;
 	GtkWidget *toolmenu;
-	gint cmdindex, defindex;
+	gint i, cmdindex, defindex;
 
 	ft_def = g_new0(GeanyBuildCommand, build_groups_count[GBG_FT]);
 	non_ft_def = g_new0(GeanyBuildCommand, build_groups_count[GBG_NON_FT]);
 	exec_def = g_new0(GeanyBuildCommand, build_groups_count[GBG_EXEC]);
-	for (cmdindex=0; default_cmds[cmdindex].label!=NULL; ++cmdindex)
+	for (cmdindex=0; default_cmds[cmdindex].entries[i] != NULL; ++cmdindex)
 	{
+        enum GeanyBuildCmdEntries k;
 		GeanyBuildCommand *cmd = &((*(default_cmds[cmdindex].ptr))[ default_cmds[cmdindex].index ]);
 		cmd->exists = TRUE;
-		cmd->label = g_strdup(default_cmds[cmdindex].label);
-		cmd->command = g_strdup(default_cmds[cmdindex].command);
+        FOREACH_GEANYBUILDCMD_ENTRY(k)
+        {
+            cmd->entries[k] = g_strdup(default_cmds[cmdindex].entries[k]);
+        }
 		cmd->run_in_base_dir = default_cmds[cmdindex].dir;
 	}
 
Index: src/build.h
===================================================================
--- src/build.h	(Revision 3969)
+++ src/build.h	(Arbeitskopie)
@@ -91,10 +91,16 @@
 
 extern GeanyBuildInfo build_info;
 
+typedef enum  GeanyBuildCmdEntries
+{
+    BC_LABEL,
+    BC_COMMAND,
+    BC_CMDENTRIES_COUNT,
+} GeanyBuildCmdEntries;
+
 typedef struct GeanyBuildCommand
 {
-	gchar		*label;
-	gchar		*command;
+	gchar *entries[BC_CMDENTRIES_COUNT];
 	gboolean	 exists;
 	gboolean	 run_in_base_dir;
 	gboolean	 changed;
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to