Adjust coding style (no code changes).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4159 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2009-09-06 16:50:20 +00:00
parent 2c7c2b91fc
commit 210fa0018a
4 changed files with 447 additions and 334 deletions

View File

@ -12,6 +12,8 @@
Fix a compiler warning.
* src/document.c:
Fix crash when opening documents.
* src/build.c, src/build.h, src/project.c:
Adjust coding style (no code changes).
2009-09-04 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -135,6 +135,7 @@ void build_finalize(void)
gtk_widget_destroy(latex_menu_items.menu); */
}
/* note: copied from keybindings.c, may be able to go away */
static void add_menu_accel(GeanyKeyGroup *group, guint kb_id,
GtkAccelGroup *accel_group, GtkWidget *menuitem)
@ -146,31 +147,36 @@ static void add_menu_accel(GeanyKeyGroup *group, guint kb_id,
kb->key, kb->mods, GTK_ACCEL_VISIBLE);
}
/* convenience routines to access parts of GeanyBuildCommand */
static gchar *id_to_str(GeanyBuildCommand *bc, gint id)
{
return bc->entries[id];
}
static gchar *buildcmd_label(GeanyBuildCommand *bc)
{
return id_to_str(bc, GEANY_BC_LABEL);
}
static gchar *buildcmd_cmd(GeanyBuildCommand *bc)
{
return id_to_str(bc, GEANY_BC_COMMAND);
}
static gchar *buildcmd_working_dir(GeanyBuildCommand *bc)
{
return id_to_str(bc, GEANY_BC_WORKING_DIR);
}
static const gchar *config_keys[] = {
[GEANY_BC_LABEL] = "LB",
[GEANY_BC_COMMAND] = "CM",
[GEANY_BC_WORKING_DIR]= "WD",
[GEANY_BC_WORKING_DIR] = "WD"
};
/*-----------------------------------------------------
@ -180,10 +186,16 @@ static const gchar* config_keys[] = {
*-----------------------------------------------------*/
/* 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;
GeanyBuildCommand *ft_def = NULL;
GeanyBuildCommand *non_ft_proj = NULL;
GeanyBuildCommand *non_ft_pref = NULL;
GeanyBuildCommand *non_ft_def = NULL;
GeanyBuildCommand *exec_proj = NULL;
GeanyBuildCommand *exec_pref = NULL;
GeanyBuildCommand *exec_def = NULL;
/* and the regexen not in the filetype structure */
gchar *regex_pref=NULL, *regex_proj=NULL;
gchar *regex_pref = NULL;
gchar *regex_proj = NULL;
/* control if build commands are printed by get_build_cmd, for debug purposes only*/
#ifndef PRINTBUILDCMDS
@ -198,6 +210,7 @@ static GeanyBuildCommand **cl[GEANY_GBG_COUNT][GEANY_BCS_COUNT] = {
{ &exec_def, NULL, NULL, &exec_pref, &exec_proj }
};
/* for debug only, print the commands structures in priority order */
static void printfcmds()
{
@ -208,7 +221,8 @@ static void printfcmds()
gint cc[GEANY_BCS_COUNT];
gchar c;
doc=document_get_current();
if (doc!=NULL)ft = doc->file_type;
if (doc != NULL)
ft = doc->file_type;
if (ft != NULL)
{
printf("filetype %s\n",ft->name);
@ -229,7 +243,11 @@ static void printfcmds()
{
FOREACH_GEANYBUILDCMD_ENTRY(n)
{
if ((*(cl[j][i]))[k].entries[n]!=NULL && (l=strlen((*(cl[j][i]))[k].entries[n]))>m)m=l;
if ((*(cl[j][i]))[k].entries[n] != NULL &&
(l=strlen((*(cl[j][i]))[k].entries[n])) > m)
{
m = l;
}
}
}
}
@ -265,6 +283,7 @@ static void printfcmds()
}
}
/* macros to save typing and make the logic visible */
#define return_cmd_if(src, cmds) if (cmds != NULL && cmds[cmdindex].exists && below>src)\
{ \
@ -282,6 +301,7 @@ static void printfcmds()
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)
@ -289,11 +309,16 @@ static GeanyBuildCommand *get_next_build_cmd(GeanyDocument *doc, gint cmdgrp, gi
GeanyFiletype *ft=NULL;
gint sink, *fr = &sink;
if (printbuildcmds)printfcmds();
if (cmdgrp>=GEANY_GBG_COUNT)return NULL;
if (from!=NULL)fr = from;
if (doc==NULL)doc = document_get_current();
if (doc!=NULL)ft = doc->file_type;
if (printbuildcmds)
printfcmds();
if (cmdgrp >= GEANY_GBG_COUNT)
return NULL;
if (from != NULL)
fr = from;
if (doc == NULL)
doc = document_get_current();
if (doc != NULL)
ft = doc->file_type;
switch(cmdgrp)
{
case GEANY_GBG_FT: /* order proj ft, home ft, ft, defft */
@ -330,21 +355,26 @@ static GeanyBuildCommand *get_build_cmd(GeanyDocument *doc, gint grp, gint cmdin
return get_next_build_cmd(doc, grp, cmdindex, GEANY_BCS_COUNT, from);
}
#define return_nonblank_regex(src, ptr) if ((ptr)!=NULL && strlen(ptr)>0){ *fr = (src); return &(ptr); }
#define return_nonblank_regex(src, ptr) if ((ptr) != NULL && strlen(ptr) > 0) \
{ *fr = (src); return &(ptr); }
/* like get_build_cmd, but for regexen, used by filetypes */
gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from)
{
gint sink, *fr = &sink;
if (from!=NULL) fr=from;
if (from != NULL)
fr=from;
if (grp == GEANY_GBG_FT)
{
if (ft == NULL)
{
GeanyDocument *doc=document_get_current();
if (doc!=NULL)ft=doc->file_type;
if (doc != NULL)
ft=doc->file_type;
}
if (ft==NULL) return NULL;
if (ft == NULL)
return NULL;
return_nonblank_regex(GEANY_BCS_PROJ, ft->projerror_regex_string);
return_nonblank_regex(GEANY_BCS_HOME_FT, ft->homeerror_regex_string);
return_nonblank_regex(GEANY_BCS_FT, ft->error_regex_string);
@ -357,6 +387,7 @@ gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from)
return NULL;
}
/* get pointer to the command group array */
static GeanyBuildCommand *get_build_group(GeanyBuildSource src, GeanyBuildGroup grp)
{
@ -406,37 +437,47 @@ static GeanyBuildCommand *get_build_group(GeanyBuildSource src, GeanyBuildGroup
}
}
/* remove the specified command, cmd < 0 remove whole group */
void build_remove_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd)
{
GeanyBuildCommand *bc;
gint i;
bc = get_build_group(src, grp);
if (bc==NULL)return;
if (bc == NULL)
return;
if (cmd < 0)
{
for (i = 0; i < build_groups_count[grp]; ++i)
bc[i].exists = FALSE;
}
else if(cmd < build_groups_count[grp])
bc[cmd].exists = FALSE;
}
/* get the build build command for the specified menu item */
GeanyBuildCommand *build_get_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd)
{
GeanyBuildCommand *bc;
if (src>=GEANY_BCS_COUNT || grp>=GEANY_GBG_COUNT || cmd>=build_groups_count[grp]) return NULL;
if (src >= GEANY_BCS_COUNT || grp >= GEANY_GBG_COUNT || cmd >= build_groups_count[grp])
return NULL;
bc = get_build_group(src, grp);
if (bc==NULL) return NULL;
if (bc == NULL)
return NULL;
return &(bc[cmd]);
}
/* parameter checked version of get_build_cmd for external interface */
GeanyBuildCommand *build_get_current_menu_item(GeanyBuildGroup grp, gint cmd, gint *src)
{
if (*src>=GEANY_BCS_COUNT || grp>=GEANY_GBG_COUNT || cmd>=build_groups_count[grp]) return NULL;
if (*src >= GEANY_BCS_COUNT || grp >= GEANY_GBG_COUNT || cmd >= build_groups_count[grp])
return NULL;
return get_build_cmd(NULL, grp, cmd, src);
}
/* Clear all error indicators in all documents. */
static void clear_errors(GeanyDocument *doc)
{
@ -491,9 +532,7 @@ static void parse_build_output(const gchar **output, gint status)
#endif
/*
* Replaces occurences of %e and %p with the appropriate filenames,
*
/* Replaces occurences of %e and %p with the appropriate filenames,
* %d and %p replacements should be in UTF8 */
static gchar *build_replace_placeholder(const GeanyDocument *doc, const gchar *src)
{
@ -549,8 +588,8 @@ static gchar* build_replace_placeholder(const GeanyDocument* doc, const gchar* s
return ret_str; /* don't forget to free src also if needed */
}
/*
* dir is the UTF-8 working directory to run cmd in. It can be NULL to use the
/* dir is the UTF-8 working directory to run cmd in. It can be NULL to use the
* idx document directory */
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir)
{
@ -592,8 +631,8 @@ static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *d
#endif
utf8_cmd_string = utils_get_utf8_from_locale(cmd_string);
utf8_working_dir = (dir != NULL && strlen(dir)>0) ? g_strdup(dir) :
g_path_get_dirname(doc->file_name);
utf8_working_dir = (dir != NULL && strlen(dir) > 0) ?
g_strdup(dir) : g_path_get_dirname(doc->file_name);
working_dir = utils_get_locale_from_utf8(utf8_working_dir);
gtk_list_store_clear(msgwindow.store_compiler);
@ -675,10 +714,10 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
have_project = project != NULL;
cmd = get_build_cmd(doc, GEANY_GBG_EXEC, cmdindex, NULL);
cmd_string = build_replace_placeholder(doc, buildcmd_cmd(cmd));
cmd_working_dir = buildcmd_working_dir(cmd);
if (!NZV(cmd_working_dir)) cmd_working_dir = "%d";
if (! NZV(cmd_working_dir))
cmd_working_dir = "%d";
working_dir = build_replace_placeholder(doc, cmd_working_dir); /* in utf-8 */
/* only test whether working dir exists, don't change it or else Windows support will break
@ -1079,6 +1118,7 @@ static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, g
return TRUE;
}
typedef void Callback(GtkWidget *w, gpointer u);
/* run the command catenating cmd_cat if present */
@ -1104,7 +1144,6 @@ static void build_command(GeanyDocument *doc, GeanyBuildGroup grp, gint cmd, gch
else
full_command = cmdstr;
dir = build_replace_placeholder(doc, buildcmd_working_dir(buildcmd));
subs_command = build_replace_placeholder(doc, full_command);
build_info.grp = grp;
@ -1112,7 +1151,8 @@ static void build_command(GeanyDocument *doc, GeanyBuildGroup grp, gint cmd, gch
build_spawn_cmd(doc, subs_command, dir);
g_free(subs_command);
g_free(dir);
if (cmd_cat != NULL) g_free(full_command);
if (cmd_cat != NULL)
g_free(full_command);
build_menu_update(doc);
}
@ -1123,7 +1163,6 @@ static void build_command(GeanyDocument *doc, GeanyBuildGroup grp, gint cmd, gch
* Create build menu and handle callbacks (&toolbar callbacks)
*
*----------------------------------------------------------------*/
static void on_make_custom_input_response(const gchar *input)
{
GeanyDocument *doc = document_get_current();
@ -1132,6 +1171,7 @@ static void on_make_custom_input_response(const gchar *input)
build_info.custom_target);
}
static void on_build_menu_item(GtkWidget *w, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
@ -1146,9 +1186,11 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data)
static GtkWidget *dialog = NULL; /* keep dialog for combo history */
if (! dialog)
{
dialog = dialogs_show_input(_("Custom Text"),
_("Enter custom text here, all entered text is appended to the command."),
build_info.custom_target, TRUE, &on_make_custom_input_response);
}
else
{
gtk_widget_show(dialog);
@ -1166,7 +1208,8 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data)
if (bc != NULL && strcmp(buildcmd_cmd(bc), "builtin") == 0)
{
gchar *uri;
if (doc==NULL)return;
if (doc == NULL)
return;
uri = g_strconcat("file:///", g_path_skip_root(doc->file_name), NULL);
utils_open_browser(uri);
g_free(uri);
@ -1179,6 +1222,7 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data)
build_command(doc, grp, cmd, NULL);
};
/* group codes for menu items other than the known commands
* value order is important, see the following table for use */
@ -1198,7 +1242,8 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data)
static struct BuildMenuItemSpec {
const gchar *stock_id;
const gint key_binding;
const gint build_grp, build_cmd;
const gint build_grp;
const gint build_cmd;
const gchar *fix_label;
Callback *cb;
} build_menu_specs[] = {
@ -1238,6 +1283,7 @@ static struct BuildMenuItemSpec {
0, NULL, NULL }
};
static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAccelGroup *ag,
struct BuildMenuItemSpec *bs, gchar *lbl, gint grp, gint cmd)
{
@ -1259,6 +1305,7 @@ static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAcc
menu_items.menu_item[grp][cmd] = item;
}
static void create_build_menu(BuildMenuItems *build_menu_items)
{
GtkWidget *menu;
@ -1309,6 +1356,7 @@ static void create_build_menu(BuildMenuItems *build_menu_items)
gtk_menu_item_set_submenu(GTK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_build1")), menu);
}
/* portability to various GTK versions needs checking
* conforms to description of gtk_accel_label as child of menu item
* NB 2.16 adds set_label but not yet set_label_mnemonic */
@ -1318,6 +1366,7 @@ static void geany_menu_item_set_label(GtkWidget *w, gchar *label)
gtk_label_set_text_with_mnemonic(GTK_LABEL(c), label);
}
/* Call this whenever build menu items need to be enabled/disabled.
* Uses current document (if there is one) when idx == -1 */
void build_menu_update(GeanyDocument *doc)
@ -1384,8 +1433,7 @@ void build_menu_update(GeanyDocument *doc)
(grp == GEANY_GBG_FT && bc != NULL && have_path && ! build_running) ||
(grp == GEANY_GBG_NON_FT && bc != NULL && ! build_running);
gtk_widget_set_sensitive(menu_item, cmd_sensitivity);
if (bc != NULL && label != NULL
&& strlen(label) > 0)
if (bc != NULL && label != NULL && strlen(label) > 0)
{
geany_menu_item_set_label(menu_item, label);
gtk_widget_show_all(menu_item);
@ -1398,9 +1446,10 @@ void build_menu_update(GeanyDocument *doc)
{
GtkWidget *image;
exec_running = run_info[cmd].pid > (GPid) 1;
cmd_sensitivity = bc!=NULL || exec_running;
cmd_sensitivity = (bc != NULL) || exec_running;
gtk_widget_set_sensitive(menu_item, cmd_sensitivity);
if (cmd==GBO_TO_CMD(GEANY_GBO_EXEC)) run_sensitivity = cmd_sensitivity;
if (cmd == GBO_TO_CMD(GEANY_GBO_EXEC))
run_sensitivity = cmd_sensitivity;
if (! exec_running)
{
image = gtk_image_new_from_stock(bs->stock_id, GTK_ICON_SIZE_MENU);
@ -1409,10 +1458,10 @@ void build_menu_update(GeanyDocument *doc)
{
image = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
}
if (cmd==GBO_TO_CMD(GEANY_GBO_EXEC)) run_running = exec_running;
if (cmd == GBO_TO_CMD(GEANY_GBO_EXEC))
run_running = exec_running;
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image);
if (bc != NULL && label != NULL
&& strlen(label) > 0)
if (bc != NULL && label != NULL && strlen(label) > 0)
{
geany_menu_item_set_label(menu_item, label);
gtk_widget_show_all(menu_item);
@ -1454,6 +1503,7 @@ void build_menu_update(GeanyDocument *doc)
}
/* Call build_menu_update() instead of calling this directly. */
static void set_stop_button(gboolean stop)
{
@ -1482,13 +1532,14 @@ static void set_stop_button(gboolean stop)
}
}
static void on_set_build_commands_activate(GtkWidget *w, gpointer u)
{
show_build_commands_dialog();
}
static void
on_toolbutton_build_activate(GtkWidget *menuitem, gpointer user_data)
static void on_toolbutton_build_activate(GtkWidget *menuitem, gpointer user_data)
{
last_toolbutton_action = user_data;
g_object_set(widgets.build_action, "tooltip", _("Build the current file"), NULL);
@ -1496,8 +1547,7 @@ on_toolbutton_build_activate(GtkWidget *menuitem, gpointer user_data)
}
static void
on_toolbutton_make_activate (GtkWidget *menuitem, gpointer user_data)
static void on_toolbutton_make_activate(GtkWidget *menuitem, gpointer user_data)
{
gchar *msg;
gint grp,cmd;
@ -1517,12 +1567,12 @@ on_toolbutton_make_activate (GtkWidget *menuitem, gpointer user_data)
on_build_menu_item(menuitem, user_data);
}
static void kill_process(GPid *pid)
{
/* Unix: SIGQUIT is not the best signal to use because it causes a core dump (this should not
* perforce necessary for just killing a process). But we must use a signal which we can
* ignore because the main process get it too, it is declared to ignore in main.c. */
gint result;
#ifdef G_OS_WIN32
@ -1546,9 +1596,7 @@ static void kill_process(GPid *pid)
}
static void
on_build_next_error (GtkWidget *menuitem,
gpointer user_data)
static void on_build_next_error(GtkWidget *menuitem,gpointer user_data)
{
if (ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_compiler),
msgwin_goto_compiler_file_line))
@ -1560,9 +1608,7 @@ on_build_next_error (GtkWidget *menuitem,
}
static void
on_build_previous_error (GtkWidget *menuitem,
gpointer user_data)
static void on_build_previous_error(GtkWidget *menuitem, gpointer user_data)
{
if (ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow.tree_compiler),
msgwin_goto_compiler_file_line))
@ -1573,6 +1619,7 @@ on_build_previous_error (GtkWidget *menuitem,
ui_set_statusbar(FALSE, _("No more build errors."));
}
void build_toolbutton_build_clicked(GtkAction *action, gpointer unused)
{
if (last_toolbutton_action == GBO_TO_POINTER(GEANY_GBO_BUILD))
@ -1585,33 +1632,39 @@ void build_toolbutton_build_clicked(GtkAction *action, gpointer unused)
}
}
/*------------------------------------------------------
*
* Create and handle the build menu configuration dialog
*
*-------------------------------------------------------*/
typedef struct RowWidgets {
typedef struct RowWidgets
{
GtkWidget *entries[GEANY_BC_CMDENTRIES_COUNT];
GeanyBuildSource src, dst;
GeanyBuildSource src;
GeanyBuildSource dst;
GeanyBuildCommand *cmdsrc;
gint grp,cmd;
gint grp;
gint cmd;
gboolean cleared;
} RowWidgets;
static void on_clear_dialog_row(GtkWidget *unused, gpointer user_data)
{
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)
{
r->cmdsrc = bc;
r->src = src;
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_entry_set_text(GTK_ENTRY(r->entries[i]),
id_to_str(bc,i) != NULL ? id_to_str(bc,i) : "");
}
}
else
@ -1625,13 +1678,16 @@ static void on_clear_dialog_row( GtkWidget *unused, gpointer user_data )
r->cleared = TRUE;
}
static void on_clear_dialog_regex_row(GtkEntry *regex, gpointer unused)
{
gtk_entry_set_text(regex,"");
}
/* Column headings, array NULL-terminated */
static gchar *colheads[] = {
static gchar *colheads[] =
{
N_("Item"),
N_("Label"),
N_("Command"),
@ -1647,6 +1703,7 @@ static gchar *colheads[] = {
static const int entry_x_padding = 3;
static const int entry_y_padding = 0;
static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gint row,
GeanyBuildSource dst, gint grp, gint cmd, gboolean dir)
{
@ -1655,12 +1712,11 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin
GeanyBuildCommand *bc;
gint src;
enum GeanyBuildCmdEntries i;
gint column = 0;
label = gtk_label_new(g_strdup_printf("%d:", cmd + 1));
gtk_table_attach(table, label, column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
gtk_table_attach(table, label, column, column + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
roww = g_new0(RowWidgets, 1);
roww->src = GEANY_BCS_COUNT;
roww->grp = grp;
@ -1677,16 +1733,18 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin
clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
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, column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
g_signal_connect(clear, "clicked", G_CALLBACK(on_clear_dialog_row), roww);
gtk_table_attach(table, clear, column, column + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
roww->cmdsrc = bc = get_build_cmd(doc, grp, cmd, &src);
if (bc!=NULL)roww->src = src;
if (bc != NULL)
roww->src = src;
FOREACH_GEANYBUILDCMD_ENTRY(i)
{
gchar *str = "";
if (bc!=NULL && (str = bc->entries[i])==NULL)str="";
if (bc != NULL && (str = bc->entries[i]) == NULL)
str = "";
gtk_entry_set_text(GTK_ENTRY(roww->entries[i]), str);
}
if (src > (gint)dst || (grp == GEANY_GBG_FT && (doc == NULL || doc->file_type == NULL)))
@ -1698,12 +1756,17 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin
return roww;
}
typedef struct TableFields {
typedef struct TableFields
{
RowWidgets **rows;
GtkWidget *fileregex, *nonfileregex;
gchar **fileregexstring, **nonfileregexstring;
GtkWidget *fileregex;
GtkWidget *nonfileregex;
gchar **fileregexstring;
gchar **nonfileregexstring;
} TableFields;
GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableData *table_data,
GeanyFiletype *ft)
{
@ -1727,9 +1790,11 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
sep = gtk_hseparator_new();
gtk_table_attach(table, sep, 0, DC_N_COL, 1, 2, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
if (ft!=NULL){
if (ft != NULL)
{
txt = g_strdup_printf(_("%s commands"), ft->title);
} else
}
else
txt = g_strdup(_("No Filetype"));
label = gtk_label_new(txt);
g_free(txt);
@ -1743,21 +1808,22 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
entry_x_padding, entry_y_padding);
fields->fileregex = gtk_entry_new();
fields->fileregexstring = build_get_regex(GEANY_GBG_FT, NULL, &src);
sensitivity = ft==NULL?FALSE:TRUE;
sensitivity = (ft == NULL) ? FALSE : TRUE;
if (fields->fileregexstring != NULL && *(fields->fileregexstring) != NULL)
{
gtk_entry_set_text(GTK_ENTRY(fields->fileregex), *(fields->fileregexstring));
if (src>(gint)dst) sensitivity = FALSE;
if (src > (gint)dst)
sensitivity = FALSE;
}
gtk_table_attach(table, fields->fileregex, DC_ENTRIES + 1, DC_CLEAR, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
clear = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(clear), clearicon);
g_signal_connect_swapped((gpointer)clear, "clicked", G_CALLBACK(on_clear_dialog_regex_row),
(gpointer)(fields->fileregex));
gtk_table_attach(table, clear, DC_CLEAR, DC_CLEAR+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
g_signal_connect_swapped(clear, "clicked",
G_CALLBACK(on_clear_dialog_regex_row), (fields->fileregex));
gtk_table_attach(table, clear, DC_CLEAR, DC_CLEAR + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
gtk_widget_set_sensitive(fields->fileregex, sensitivity);
gtk_widget_set_sensitive(clear, sensitivity);
++row;
@ -1770,10 +1836,11 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
gtk_table_attach(table, label, 0, DC_N_COL, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
for (++row, cmd = 0; cmd < build_groups_count[GEANY_GBG_NON_FT]; ++row,++cmdindex, ++cmd)
fields->rows[cmdindex] = build_add_dialog_row(doc, table, row, dst, GEANY_GBG_NON_FT, cmd, TRUE);
fields->rows[cmdindex] = build_add_dialog_row(
doc, table, row, dst, GEANY_GBG_NON_FT, cmd, TRUE);
label = gtk_label_new(_("Error Regular Expression"));
gtk_table_attach(table, label, 0, DC_ENTRIES+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
gtk_table_attach(table, label, 0, DC_ENTRIES + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
fields->nonfileregex = gtk_entry_new();
fields->nonfileregexstring = build_get_regex(GEANY_GBG_NON_FT, NULL, &src);
sensitivity = TRUE;
@ -1787,10 +1854,10 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
clear = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(clear), clearicon);
g_signal_connect_swapped((gpointer)clear, "clicked", G_CALLBACK(on_clear_dialog_regex_row),
(gpointer)(fields->nonfileregex));
gtk_table_attach(table, clear, DC_CLEAR, DC_CLEAR+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
g_signal_connect_swapped(clear, "clicked",
G_CALLBACK(on_clear_dialog_regex_row), (fields->nonfileregex));
gtk_table_attach(table, clear, DC_CLEAR, DC_CLEAR + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
gtk_widget_set_sensitive(fields->nonfileregex, sensitivity);
gtk_widget_set_sensitive(clear, sensitivity);
++row;
@ -1825,6 +1892,7 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
return GTK_WIDGET(table);
}
void build_free_fields(TableData table_data)
{
gint cmdindex;
@ -1834,15 +1902,20 @@ void build_free_fields(TableData table_data)
g_free(table_data);
}
/* string compare where null pointers match null or 0 length strings */
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 0;
if (a == NULL && b != NULL)
return strlen(b);
if (a != NULL && b == NULL)
return strlen(a);
return strcmp(a, b);
}
static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow, gint grp, gint cmd)
{
gchar *entries[GEANY_BC_CMDENTRIES_COUNT];
@ -1860,7 +1933,8 @@ static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow,
{
if (dst->dst[grp] != NULL)
{
if (*(dst->dst[grp])==NULL)*(dst->dst[grp])=g_new0(GeanyBuildCommand, build_groups_count[grp]);
if (*(dst->dst[grp]) == NULL)
*(dst->dst[grp]) = g_new0(GeanyBuildCommand, build_groups_count[grp]);
(*(dst->dst[grp]))[cmd].exists = FALSE;
(*(dst->dst[grp]))[cmd].changed = TRUE;
changed = TRUE;
@ -1908,6 +1982,7 @@ static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow,
return changed;
}
static gboolean read_regex(GtkWidget *regexentry, gchar **src, gchar **dst)
{
gboolean changed = FALSE;
@ -1919,8 +1994,7 @@ static gboolean read_regex(GtkWidget *regexentry, gchar **src, gchar **dst)
)
&& strlen(reg) > 0 /* and something was typed */
)
||( /* or */
src!=NULL /* originally there was a regex*/
||(src != NULL /* originally there was a regex*/
&& strcmp(*src, reg) != 0 /* and it has been changed */
)
)
@ -1934,6 +2008,7 @@ static gboolean read_regex(GtkWidget *regexentry, gchar **src, gchar **dst)
return changed;
}
gboolean build_read_commands(BuildDestination *dst, TableData table_data, gint response)
{
gint cmdindex, cmd;
@ -1953,7 +2028,8 @@ gboolean build_read_commands(BuildDestination *dst, TableData table_data, gint r
return changed;
}
static void show_build_commands_dialog()
static void show_build_commands_dialog(void)
{
GtkWidget *dialog, *table, *vbox;
GeanyDocument *doc = document_get_current();
@ -1997,16 +2073,19 @@ static void show_build_commands_dialog()
gtk_widget_destroy(dialog);
}
/* Creates the relevant build menu if necessary. */
BuildMenuItems *build_get_menu_items(gint filetype_idx)
{
BuildMenuItems *items;
items = &menu_items;
if (items->menu == NULL) create_build_menu(items);
if (items->menu == NULL)
create_build_menu(items);
return items;
}
/* set non_ft working directory entries to %p for project */
void build_set_non_ft_wd_to_proj(TableData table_data)
{
@ -2017,12 +2096,12 @@ void build_set_non_ft_wd_to_proj(TableData table_data)
gtk_entry_set_text(GTK_ENTRY(table_data->rows[i]->entries[GEANY_BC_WORKING_DIR]), "%p");
}
/*----------------------------------------------------------
*
* Load and store configuration
*
* ---------------------------------------------------------*/
static const gchar *build_grp_name = "build-menu";
/* config format for build-menu group is prefix_gg_nn_xx=value
@ -2044,14 +2123,16 @@ static void build_load_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint
gchar *key;
static gchar cmdbuf[3] = " ";
if (*dst==NULL)*dst = g_new0(GeanyBuildCommand, build_groups_count[grp]);
if (*dst == NULL)
*dst = g_new0(GeanyBuildCommand, build_groups_count[grp]);
dstcmd = *dst;
prefixlen = prefix == NULL ? 0 : strlen(prefix);
key = g_strconcat(prefix == NULL ? "" : prefix, fixedkey, NULL);
for (cmd = 0; cmd < build_groups_count[grp]; ++cmd)
{
gchar *label;
if (cmd<0 || cmd>=100)return; /* ensure no buffer overflow */
if (cmd < 0 || cmd >= 100)
return; /* ensure no buffer overflow */
sprintf(cmdbuf, "%02d", cmd);
set_key_grp(key, groups[grp]);
set_key_cmd(key, cmdbuf);
@ -2076,6 +2157,7 @@ static void build_load_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint
g_free(key);
}
/* for the specified source load new format build menu items or try to make some sense of
* old format setings, not done perfectly but better than ignoring them */
void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
@ -2093,7 +2175,8 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
{
case GEANY_BCS_FT:
ft = (GeanyFiletype*)p;
if (ft==NULL)return;
if (ft == NULL)
return;
build_load_menu_grp(config, &(ft->filecmds), GEANY_GBG_FT, NULL, TRUE);
build_load_menu_grp(config, &(ft->ftdefcmds), GEANY_GBG_NON_FT, NULL, TRUE);
build_load_menu_grp(config, &(ft->execcmds), GEANY_GBG_EXEC, NULL, TRUE);
@ -2102,7 +2185,8 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
break;
case GEANY_BCS_HOME_FT:
ft = (GeanyFiletype*)p;
if (ft==NULL)return;
if (ft == NULL)
return;
build_load_menu_grp(config, &(ft->homefilecmds), GEANY_GBG_FT, NULL, FALSE);
build_load_menu_grp(config, &(ft->homeexeccmds), GEANY_GBG_EXEC, NULL, FALSE);
setptr(ft->homeerror_regex_string,
@ -2118,12 +2202,14 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
build_load_menu_grp(config, &exec_proj, GEANY_GBG_EXEC, NULL, FALSE);
setptr(regex_proj, g_key_file_get_string(config, build_grp_name, "error_regex", NULL));
pj = (GeanyProject*)p;
if (p==NULL)return;
if (p == NULL)
return;
ftlist = g_key_file_get_string_list(config, build_grp_name, "filetypes", NULL, NULL);
if (ftlist != NULL)
{
gchar **ftname;
if (pj->build_filetypes_list==NULL) pj->build_filetypes_list = g_ptr_array_new();
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)
{
@ -2163,24 +2249,30 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
{
case GEANY_BCS_FT:
ft = (GeanyFiletype*)p;
if (ft->filecmds==NULL)ft->filecmds = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_FT]);
if (ft->filecmds == NULL)
ft->filecmds = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_FT]);
value = g_key_file_get_string(config, "build_settings", "compiler", NULL);
ASSIGNIF(ft->filecmds, GEANY_GBO_COMPILE, "_Compile", value);
value = g_key_file_get_string(config, "build_settings", "linker", NULL);
ASSIGNIF(ft->filecmds, GEANY_GBO_BUILD, "_Build", value);
if (ft->execcmds==NULL)ft->execcmds = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_EXEC]);
if (ft->execcmds == NULL)
ft->execcmds = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_EXEC]);
value = g_key_file_get_string(config, "build_settings", "run_cmd", NULL);
ASSIGNIF(ft->execcmds, GEANY_GBO_EXEC, "_Execute", value);
if (ft->error_regex_string == NULL)
ft->error_regex_string = g_key_file_get_string(config, "build_settings", "error_regex", NULL);
break;
case GEANY_BCS_PROJ:
if (non_ft_proj==NULL)non_ft_proj = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_NON_FT]);
if (non_ft_proj == NULL)
non_ft_proj = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_NON_FT]);
basedir = project_get_base_path();
if (basedir==NULL) basedir = g_strdup("%d");
if (basedir == NULL)
basedir = g_strdup("%d");
bvalue = g_key_file_get_boolean(config, "project", "make_in_base_path", NULL);
if (bvalue) makebasedir = g_strdup(basedir);
else makebasedir = g_strdup("%d");
if (bvalue)
makebasedir = g_strdup(basedir);
else
makebasedir = g_strdup("%d");
if (non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_ALL)].old)
setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_ALL)].entries[GEANY_BC_WORKING_DIR], g_strdup(makebasedir));
if (non_ft_pref[GBO_TO_CMD(GEANY_GBO_CUSTOM)].old)
@ -2190,7 +2282,8 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
value = g_key_file_get_string(config, "project", "run_cmd", NULL);
if (value != NULL && strlen(value) > 0)
{
if (exec_proj==NULL)exec_proj = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_EXEC]);
if (exec_proj == NULL)
exec_proj = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_EXEC]);
if (! exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].exists)
{
exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].exists = TRUE;
@ -2204,7 +2297,8 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
g_free(basedir);
break;
case GEANY_BCS_PREF:
if (non_ft_pref==NULL)non_ft_pref = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_NON_FT]);
if (non_ft_pref == NULL)
non_ft_pref = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_NON_FT]);
value = g_key_file_get_string(config, "tools", "make_cmd", NULL);
ASSIGNIF(non_ft_pref, GEANY_GBO_CUSTOM, "Make Custom _Target",
g_strdup_printf("%s ", value));
@ -2217,6 +2311,7 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
}
}
static gint build_save_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint grp, gchar *prefix)
{
gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
@ -2224,7 +2319,8 @@ static gint build_save_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint g
gint count = 0;
enum GeanyBuildCmdEntries i;
if (src==NULL)return 0;
if (src == NULL)
return 0;
prefixlen = prefix == NULL ? 0 : strlen(prefix);
key = g_strconcat(prefix == NULL ? "" : prefix, fixedkey, NULL);
for (cmd = 0; cmd < build_groups_count[grp]; ++cmd)
@ -2232,7 +2328,8 @@ static gint build_save_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint g
if (src[cmd].changed)
{
static gchar cmdbuf[4] = " ";
if (cmd<0 || cmd>=100)return count; /* ensure no buffer overflow */
if (cmd < 0 || cmd >= 100)
return count; /* ensure no buffer overflow */
sprintf(cmdbuf, "%02d", cmd);
set_key_grp(key, groups[grp]);
set_key_cmd(key, cmdbuf);
@ -2259,12 +2356,14 @@ static gint build_save_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint g
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;
@ -2276,12 +2375,13 @@ static void foreach_project_filetype(gpointer data, gpointer user_data)
if (ft->projerror_regex_string != NULL && strlen(ft->projerror_regex_string) > 0)
{
g_key_file_set_string(d->config, build_grp_name, regkey, ft->projerror_regex_string);
i+=1;
i++;
}
else
g_key_file_remove_key(d->config, build_grp_name,regkey, NULL);
g_free(regkey);
if (i>0)g_ptr_array_add(d->ft_names, ft->name);
if (i > 0)
g_ptr_array_add(d->ft_names, ft->name);
}
void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
@ -2295,7 +2395,8 @@ void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
{
case GEANY_BCS_HOME_FT:
ft = (GeanyFiletype*)ptr;
if (ft==NULL)return;
if (ft == NULL)
return;
build_save_menu_grp(config, ft->homefilecmds, GEANY_GBG_FT, NULL);
build_save_menu_grp(config, ft->homeexeccmds, GEANY_GBG_EXEC, NULL);
regkey = g_strdup_printf("%serror_regex", ft->name);
@ -2339,21 +2440,26 @@ void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
}
}
void build_set_group_count(GeanyBuildGroup grp, gint count)
{
gint i, sum;
if (count>build_groups_count[grp])
build_groups_count[grp] = count;
for (i=0, sum=0; i<GEANY_GBG_COUNT; ++i)sum+=build_groups_count[i];
for (i = 0, sum = 0; i < GEANY_GBG_COUNT; ++i)
sum += build_groups_count[i];
build_items_count = sum;
}
gint build_get_group_count(GeanyBuildGroup grp)
{
return build_groups_count[grp];
}
static struct {
static struct
{
gchar *entries[GEANY_BC_CMDENTRIES_COUNT];
GeanyBuildCommand **ptr;
gint index;
@ -2365,6 +2471,7 @@ static struct {
{ {NULL, NULL, NULL}, NULL, 0 }
};
void build_init(void)
{
GtkWidget *item;
@ -2386,7 +2493,6 @@ void build_init(void)
}
}
/* create the toolbar Build item sub menu */
toolmenu = gtk_menu_new();
g_object_ref(toolmenu);

View File

@ -140,7 +140,9 @@ typedef struct GeanyBuildCommand
gboolean old; /**< Converted from old format. */
} GeanyBuildCommand;
extern GeanyBuildCommand *non_ft_proj, *exec_proj; /* project command array pointers */
/* project command array pointers */
extern GeanyBuildCommand *non_ft_proj;
extern GeanyBuildCommand *exec_proj;
extern gchar *regex_proj; /* project non-fileregex string */
typedef struct BuildMenuItems

View File

@ -109,7 +109,8 @@ void project_new(void)
PropertyDialogElements *e;
gint response;
if (! project_ask_close()) return;
if (! project_ask_close())
return;
g_return_if_fail(app->project == NULL);
@ -332,6 +333,7 @@ static void remove_foreach_project_filetype( gpointer data, gpointer user_data )
}
}
/* open_default will make function reload default session files on close */
void project_close(gboolean open_default)
{
@ -383,13 +385,13 @@ void project_close(gboolean open_default)
update_ui();
}
static void on_set_use_base_path_clicked(GtkWidget *unused1, gpointer user_data)
{
TableData td = (TableData)user_data;
build_set_non_ft_wd_to_proj(td);
build_set_non_ft_wd_to_proj((TableData)user_data);
}
static void create_properties_dialog(PropertyDialogElements *e)
{
GtkWidget *table, *notebook, *build_table;
@ -733,7 +735,8 @@ static gboolean update_config(const PropertyDialogElements *e)
setptr(p->description, g_strdup(gtk_text_buffer_get_text(buffer, &start, &end, FALSE)));
/* read the project build menu */
if ( doc!=NULL )ft=doc->file_type;
if ( doc!=NULL )
ft = doc->file_type;
if ( ft!=NULL )
{
menu_dst.dst[GEANY_GBG_FT] = &(ft->projfilecmds);
@ -752,7 +755,8 @@ static gboolean update_config(const PropertyDialogElements *e)
build_read_commands( &menu_dst, e->build_properties, GTK_RESPONSE_ACCEPT );
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();
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);
}
@ -813,8 +817,7 @@ static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
g_free(locale_dir);
}
}
else
if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
else if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
{
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
}