Branch: refs/heads/master Author: Dimitar Zhekov dimitar.zhekov@gmail.com Committer: Dimitar Zhekov dimitar.zhekov@gmail.com Date: Mon, 06 May 2013 13:56:18 UTC Commit: a1bd3e69b8151606e0c5acaaae3d1643ab80db88 https://github.com/geany/geany-plugins/commit/a1bd3e69b8151606e0c5acaaae3d16...
Log Message: ----------- scope - GArray parse_modes, recent_programs, thread_groups -> ScpTreeStore
Modified Paths: -------------- scope/ChangeLog scope/data/scope.glade scope/src/break.c scope/src/gtk216.c scope/src/gtk216.h scope/src/inspect.c scope/src/local.c scope/src/memory.c scope/src/menu.c scope/src/parse.c scope/src/parse.h scope/src/program.c scope/src/scope.c scope/src/stack.c scope/src/thread.c scope/src/tooltip.c scope/src/utils.c scope/src/utils.h scope/src/watch.c
Modified: scope/ChangeLog 14 files changed, 13 insertions(+), 1 deletions(-) =================================================================== @@ -1,3 +1,15 @@ +2013-05-04 Dimitar Zhekov dimitar.zhekov@gmail.com + + * data/scope.glade, src/break.c, src/gtk216.c, src/gtk216.h, + src/inspect.c, src/local.c, src/memory.c, src/menu.c, src/parse.c, + src/parse.h, src/program.c, src/scope.c, src/stack.c, src/thread.c, + src/tooltip.c, src/utils.c, src/utils.h, src/watch.c: + GArray parse_modes -> ScpTreeStore. + GArray recent_programs -> ScpTreeStore. + Removed get array element size emulation. + Removed all array utility functions. + + 2013-05-02 Dimitar Zhekov dimitar.zhekov@gmail.com
* data/scope.glade, src/thread.c: @@ -46,7 +58,7 @@ 2013-03-07 Dimitar Zhekov dimitar.zhekov@gmail.com
* src/gtk216.c: - Fixed a bug in array size emulation + Fixed a bug in array size emulation.
2013-02-21 Dimitar Zhekov dimitar.zhekov@gmail.com
Modified: scope/data/scope.glade 22 files changed, 22 insertions(+), 0 deletions(-) =================================================================== @@ -1227,6 +1227,28 @@ </object> </child> </object> + <object class="ScpTreeStore" id="recent_program_store"> + <property name="sublevels">False</property> + <columns> + <!-- column-name recent_program_store_name --> + <column type="gchararray" utf8_collate="false"/> + <!-- column-name recent_program_store_id --> + <column type="gint"/> + </columns> + </object> + <object class="ScpTreeStore" id="parse_mode_store"> + <property name="sublevels">False</property> + <columns> + <!-- column-name parse_mode_store_hbit --> + <column type="gint"/> + <!-- column-name parse_mode_store_member --> + <column type="gint"/> + <!-- column-name parse_mode_store_entry --> + <column type="gboolean"/> + <!-- column-name parse_mode_store_name --> + <column type="gchararray" utf8_collate="false"/> + </columns> + </object> <object class="ScpTreeStore" id="thread_group_store"> <property name="sublevels">False</property> <columns>
Modified: scope/src/break.c 10 files changed, 5 insertions(+), 5 deletions(-) =================================================================== @@ -424,7 +424,7 @@ static void break_node_parse(const ParseNode *node, BreakData *bd) append_script_command(script, string); else { - array_foreach((GArray *) script->value, + parse_foreach((GArray *) script->value, (GFunc) append_script_command, string); }
@@ -485,7 +485,7 @@ void on_break_inserted(GArray *nodes) bd.stage = BG_DISCARD; }
- array_foreach(nodes, (GFunc) break_node_parse, &bd); + parse_foreach(nodes, (GFunc) break_node_parse, &bd); }
static void break_apply(GtkTreeIter *iter, gboolean thread) @@ -669,7 +669,7 @@ void on_break_list(GArray *nodes) store_foreach(store, (GFunc) break_iter_missing, NULL);
bd.stage = BG_DISCARD; - array_foreach(nodes, (GFunc) break_node_parse, &bd); + parse_foreach(nodes, (GFunc) break_node_parse, &bd);
if (refresh) breaks_missing(); @@ -710,7 +710,7 @@ void on_break_created(GArray *nodes) { BreakData bd; bd.stage = BG_DISCARD; - array_foreach(nodes, (GFunc) break_node_parse, &bd); + parse_foreach(nodes, (GFunc) break_node_parse, &bd); }
break_async = TRUE; @@ -730,7 +730,7 @@ static void break_feature_node_check(const ParseNode *node, G_GNUC_UNUSED gpoint
void on_break_features(GArray *nodes) { - array_foreach(parse_lead_array(nodes), (GFunc) break_feature_node_check, NULL); + parse_foreach(parse_lead_array(nodes), (GFunc) break_feature_node_check, NULL); }
static void break_delete(GtkTreeIter *iter)
Modified: scope/src/gtk216.c 59 files changed, 0 insertions(+), 59 deletions(-) =================================================================== @@ -19,54 +19,6 @@
#include "common.h"
-#if !GLIB_CHECK_VERSION(2, 22, 0) -/* :-( */ -typedef struct _ArraySize -{ - GArray *array; - guint element_size; -} ArraySize; - -GArray *array_sizes; - -static ArraySize *find_array_size(GArray *array) -{ - gchar *end = array_sizes->data + sizeof(ArraySize) * array_sizes->len; - gchar *data; - - for (data = array_sizes->data; data < end; data += sizeof(ArraySize)) - if (*(GArray **) data == array) - return (ArraySize *) data; - - return NULL; -} - -#undef g_array_sized_new -GArray *scope_array_sized_new(gboolean zero_terminated, gboolean clear, guint element_size, - guint reserved_size) -{ - GArray *array = g_array_sized_new(zero_terminated, clear, element_size, reserved_size); - ArraySize array_size = { array, element_size }; - - g_array_append_val(array_sizes, array_size); - return array; -} - -guint scope_array_get_element_size(GArray *array) -{ - return find_array_size(array)->element_size; -} - -#undef g_array_free -gchar *scope_array_free(GArray *array, gboolean free_segment) -{ - g_array_remove_index(array_sizes, - find_array_size(array) - (ArraySize *) array_sizes->data); - - return g_array_free(array, free_segment); -} -#endif /* GLIB 2.22.0 */ - #if !GTK_CHECK_VERSION(2, 18, 0) void gtk_widget_set_visible(GtkWidget *widget, gboolean visible) { @@ -123,15 +75,4 @@ void gtk216_init(void)
for (scd = sort_column_ids; scd->id; scd++) gtk_tree_view_column_set_sort_column_id(get_column(scd->id), scd->sort_column_id); - -#if !GLIB_CHECK_VERSION(2, 22, 0) - array_sizes = g_array_sized_new(FALSE, FALSE, sizeof(ArraySize), 0x10); -#endif -} - -void gtk216_finalize(void) -{ -#if !GLIB_CHECK_VERSION(2, 22, 0) - g_array_free(array_sizes, TRUE); -#endif }
Modified: scope/src/gtk216.h 13 files changed, 0 insertions(+), 13 deletions(-) =================================================================== @@ -19,19 +19,6 @@
#ifndef GTK216_H
-#if !GLIB_CHECK_VERSION(2, 22, 0) -GArray *scope_array_sized_new(gboolean zero_terminated, gboolean clear, guint element_size, - guint reserved_size); -#define g_array_sized_new(zero_terminated, clear, element_size, reserved_size) \ - scope_array_sized_new((zero_terminated), (clear), (element_size), (reserved_size)) -#define g_array_new(zero_terminated, clear, elt_size) \ - g_array_sized_new((zero_terminated), (clear), (elt_size), 0) -guint scope_array_get_element_size(GArray *array); -#define g_array_get_element_size(array) scope_array_get_element_size(array) -gchar *scope_array_free(GArray *array, gboolean free_segment); -#define g_array_free(array, free_segment) scope_array_free((array), (free_segment)) -#endif /* GLIB 2.22.0 */ - #if !GTK_CHECK_VERSION(2, 18, 0) #define gtk_widget_get_visible(widget) GTK_WIDGET_VISIBLE(widget) #define gtk_widget_get_sensitive(widget) GTK_WIDGET_SENSITIVE(widget)
Modified: scope/src/inspect.c 12 files changed, 6 insertions(+), 6 deletions(-) =================================================================== @@ -351,7 +351,7 @@ void on_inspect_children(GArray *nodes) scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, INSPECT_NUMCHILD, &numchild, -1);
- array_foreach(nodes, (GFunc) inspect_node_append, &iter); + parse_foreach(nodes, (GFunc) inspect_node_append, &iter); end = from + nodes->len;
if (nodes->len && (from || end < numchild)) @@ -453,7 +453,7 @@ static void inspect_node_change(const ParseNode *node, G_GNUC_UNUSED gpointer gd
void on_inspect_changelist(GArray *nodes) { - array_foreach(parse_lead_array(nodes), (GFunc) inspect_node_change, NULL); + parse_foreach(parse_lead_array(nodes), (GFunc) inspect_node_change, NULL); }
static void inspect_apply(GtkTreeIter *iter) @@ -593,11 +593,11 @@ void inspect_add(const gchar *text) { GtkTreeIter iter; const gchar *expr = gtk_entry_get_text(inspect_expr); - const ParseMode *pm = parse_mode_find(expr);
- scp_tree_store_append_with_values(store, &iter, NULL, INSPECT_HB_MODE, pm->hb_mode, - INSPECT_SCID, ++scid_gen, INSPECT_FORMAT, FORMAT_NATURAL, INSPECT_COUNT, - option_inspect_count, INSPECT_EXPAND, option_inspect_expand, -1); + scp_tree_store_append_with_values(store, &iter, NULL, INSPECT_HB_MODE, + parse_mode_get(expr, MODE_HBIT), INSPECT_SCID, ++scid_gen, INSPECT_FORMAT, + FORMAT_NATURAL, INSPECT_COUNT, option_inspect_count, INSPECT_EXPAND, + option_inspect_expand, -1); inspect_dialog_store(&iter); utils_tree_set_cursor(selection, &iter, -1);
Modified: scope/src/local.c 2 files changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -95,7 +95,7 @@ void on_local_variables(GArray *nodes) gtk_tree_model_get((GtkTreeModel *) store, &iter, LOCAL_NAME, &ld.name, -1);
locals_clear(); - array_foreach(parse_lead_array(nodes), (GFunc) local_node_variable, &ld); + parse_foreach(parse_lead_array(nodes), (GFunc) local_node_variable, &ld); g_free(ld.name); } }
Modified: scope/src/memory.c 12 files changed, 6 insertions(+), 6 deletions(-) =================================================================== @@ -243,7 +243,7 @@ void on_memory_read_bytes(GArray *nodes) gtk_tree_view_column_queue_resize(get_column("memory_ascii_column")); }
- array_foreach(parse_lead_array(nodes), (GFunc) memory_node_read, + parse_foreach(parse_lead_array(nodes), (GFunc) memory_node_read, GINT_TO_POINTER(TRUE));
if (addr) @@ -345,11 +345,11 @@ static void on_memory_group_update(const MenuItem *menu_item)
static MenuItem memory_menu_items[] = { - { "memory_refresh", on_memory_refresh, DS_FRESHABLE, NULL, NULL }, - { "memory_read", on_memory_read, DS_SENDABLE, NULL, NULL }, - { "memory_copy", on_memory_copy, DS_COPYABLE, NULL, NULL }, - { "memory_clear", on_memory_clear, DS_CLEARABLE, NULL, NULL }, - { "memory_group", on_memory_group_display, DS_SENDABLE, NULL, NULL }, + { "memory_refresh", on_memory_refresh, DS_FRESHABLE, NULL, NULL }, + { "memory_read", on_memory_read, DS_SENDABLE, NULL, NULL }, + { "memory_copy", on_memory_copy, DS_COPYABLE, NULL, NULL }, + { "memory_clear", on_memory_clear, DS_CLEARABLE, NULL, NULL }, + { "memory_group", on_memory_group_display, DS_SENDABLE, NULL, NULL }, GROUP_ITEM("1", 0), GROUP_ITEM("2", 1), GROUP_ITEM("4", 2),
Modified: scope/src/menu.c 3 files changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -412,11 +412,10 @@ void on_menu_evaluate_value(GArray *nodes) { if (atoi(parse_grab_token(nodes)) == scid_gen && !gtk_widget_get_visible(modify_dialog)) { - const ParseMode *pm = parse_mode_find(input); gchar *expr = utils_get_utf8_from_locale(input);
menu_evaluate_modify(expr, parse_lead_value(nodes), "Evaluate/Modify", - pm->hb_mode, eval_mr_mode, NULL); + parse_mode_get(input, MODE_HBIT), eval_mr_mode, NULL); g_free(expr); } }
Modified: scope/src/parse.c 166 files changed, 85 insertions(+), 81 deletions(-) =================================================================== @@ -23,6 +23,24 @@
#include "common.h"
+static void parse_node_free(ParseNode *node, G_GNUC_UNUSED gpointer gdata) +{ + if (node->type == PT_ARRAY) + { + parse_foreach((GArray *) node->value, (GFunc) parse_node_free, NULL); + g_array_free((GArray *) node->value, TRUE); + } +} + +void parse_foreach(GArray *nodes, GFunc func, gpointer gdata) +{ + const ParseNode *node = (const ParseNode *) nodes->data; + const ParseNode *end = node + nodes->len; + + for (; node < end; node++) + func((gpointer) node, gdata); +} + static void target_feature_node_check(const ParseNode *node, G_GNUC_UNUSED gpointer gdata) { if (!strcmp((const char *) node->value, "async")) @@ -32,7 +50,7 @@ static void target_feature_node_check(const ParseNode *node, G_GNUC_UNUSED gpoin static void on_target_features(GArray *nodes) { pref_gdb_async_mode = FALSE; - array_foreach(parse_lead_array(nodes), (GFunc) target_feature_node_check, NULL); + parse_foreach(parse_lead_array(nodes), (GFunc) target_feature_node_check, NULL); }
static void on_quiet_error(G_GNUC_UNUSED GArray *nodes) @@ -109,21 +127,6 @@ static void on_data_modified(G_GNUC_UNUSED GArray *nodes) { NULL, NULL, '\0', '\0', 0 } };
-static void parse_array_append(GArray *nodes, const char *name, ParseNodeType type, void *value) -{ - ParseNode *node = (ParseNode *) array_append(nodes); - - node->name = name; - node->type = type; - node->value = value; -} - -static void parse_node_free(ParseNode *node) -{ - if (node->type == PT_ARRAY) - array_free((GArray *) node->value, (GFreeFunc) parse_node_free); -} - static char *parse_error(const char *text) { dc_error("%s", text); @@ -189,7 +192,8 @@ static char *parse_text(GArray *nodes, char *text, char end, char newline)
if (!text && !newline) { - array_clear(nodes, (GFreeFunc) parse_node_free); + parse_foreach(nodes, (GFunc) parse_node_free, NULL); + g_array_set_size(nodes, 0); return NULL; } } @@ -203,7 +207,7 @@ static char *parse_text(GArray *nodes, char *text, char end, char newline) if (!brace && *text != '[') return parse_error("" { or [ expected");
- array = array_new(ParseNode, 0x10); + array = g_array_new(FALSE, FALSE, sizeof(ParseNode)); node.type = PT_ARRAY; node.value = array;
@@ -235,7 +239,7 @@ void parse_message(char *message, const char *token)
if (route->callback) { - GArray *nodes = array_new(ParseNode, 0x10); + GArray *nodes = g_array_new(FALSE, FALSE, sizeof(ParseNode)); const char *comma = strchr(route->prefix, ',');
if (comma) @@ -244,12 +248,16 @@ void parse_message(char *message, const char *token) iff (nodes->len >= route->args, "missing argument(s)") { if (token) - parse_array_append(nodes, "=token", PT_VALUE, (char *) token + 1); + { + ParseNode node = { "=token", PT_VALUE, (char *) token + 1 }; + g_array_append_val(nodes, node); + }
route->callback(nodes); }
- array_free(nodes, (GFreeFunc) parse_node_free); + parse_foreach(nodes, (GFunc) parse_node_free, NULL); + g_array_free(nodes, TRUE); } }
@@ -379,7 +387,14 @@ gchar *parse_get_display_from_7bit(const char *text, gint hb_mode, gint mr_mode)
const ParseNode *parse_find_node(GArray *nodes, const char *name) { - return (const ParseNode *) array_find(nodes, name, FALSE); + const ParseNode *node = (const ParseNode *) nodes->data; + const ParseNode *end = node + nodes->len; + + for (; node < end; node++) + if (!strcmp(node->name, name)) + return node; + + return NULL; }
const void *parse_find_node_type(GArray *nodes, const char *name, ParseNodeType type) @@ -403,13 +418,13 @@ const char *parse_grab_token(GArray *nodes) if (node) { token = (const char *) node->value; - array_remove(nodes, node); + g_array_remove_index(nodes, node - (const ParseNode *) nodes->data); }
return token; }
-gchar *parse_find_error(GArray *nodes) +gchar *parse_get_error(GArray *nodes) { gchar *error = parse_find_value(nodes, "msg"); return error && *error ? utils_get_utf8_from_locale(error) : @@ -431,7 +446,7 @@ static gboolean errors_show(G_GNUC_UNUSED gpointer gdata)
void on_error(GArray *nodes) { - gchar *error = parse_find_error(nodes); + gchar *error = parse_get_error(nodes);
if (errors_id) g_string_append_c(errors, '\n'); @@ -478,12 +493,8 @@ void parse_location(GArray *nodes, ParseLocation *loc) loc->line = 0; }
-static GArray *parse_modes; - -static void parse_mode_free(ParseMode *pm) -{ - g_free(pm->name); -} +static ScpTreeStore *parse_modes; +enum { MODE_NAME = MODE_ENTRY + 1 };
static gboolean parse_mode_load(GKeyFile *config, const char *section) { @@ -491,33 +502,38 @@ static gboolean parse_mode_load(GKeyFile *config, const char *section) gint hb_mode = utils_get_setting_integer(config, section, "hbit", HB_DEFAULT); gint mr_mode = utils_get_setting_integer(config, section, "member", MR_DEFAULT); gboolean entry = utils_get_setting_boolean(config, section, "entry", TRUE); + gboolean valid = FALSE;
if (name && (unsigned) hb_mode < HB_COUNT && (unsigned) mr_mode < MR_MODIFY) { - ParseMode *pm = (ParseMode *) array_append(parse_modes); - - pm->name = name; - pm->hb_mode = hb_mode; - pm->mr_mode = mr_mode; - pm->entry = entry; - return TRUE; + scp_tree_store_append_with_values(parse_modes, NULL, NULL, MODE_NAME, name, + MODE_HBIT, hb_mode, MODE_MEMBER, mr_mode, MODE_ENTRY, entry, -1); + valid = TRUE; }
g_free(name); - return FALSE; + return valid; }
-static gboolean parse_mode_save(GKeyFile *config, const char *section, ParseMode *pm) +static gboolean parse_mode_save(GKeyFile *config, const char *section, GtkTreeIter *iter) { - g_key_file_set_string(config, section, "name", pm->name); - g_key_file_set_integer(config, section, "hbit", pm->hb_mode); - g_key_file_set_integer(config, section, "member", pm->mr_mode); - g_key_file_set_boolean(config, section, "entry", pm->entry); + const char *name; + gint hb_mode, mr_mode; + gboolean entry; + + scp_tree_store_get(parse_modes, iter, MODE_NAME, &name, MODE_HBIT, &hb_mode, + MODE_MEMBER, &mr_mode, MODE_ENTRY, &entry, -1); + + if (hb_mode == HB_DEFAULT && mr_mode == MR_DEFAULT && entry) + return FALSE; + + g_key_file_set_string(config, section, "name", name); + g_key_file_set_integer(config, section, "hbit", hb_mode); + g_key_file_set_integer(config, section, "member", mr_mode); + g_key_file_set_boolean(config, section, "entry", entry); return TRUE; }
-static ParseMode parse_mode_default = { NULL, HB_DEFAULT, MR_DEFAULT, TRUE }; - char *parse_mode_reentry(const char *name) { return g_str_has_suffix(name, "@entry") ? g_strndup(name, strlen(name) - 6) : @@ -529,42 +545,34 @@ static char *parse_mode_pm_name(const char *name) return g_strndup(name, strlen(name) - (g_str_has_suffix(name, "@entry") ? 6 : 0)); }
-const ParseMode *parse_mode_find(const char *name) +gint parse_mode_get(const char *name, gint mode) { char *pm_name = parse_mode_pm_name(name); - ParseMode *pm = (ParseMode *) array_find(parse_modes, pm_name, FALSE); + GtkTreeIter iter; + gint value; + + if (store_find(parse_modes, &iter, MODE_NAME, pm_name)) + scp_tree_store_get(parse_modes, &iter, mode, &value, -1); + else + value = mode == MODE_HBIT ? HB_DEFAULT : mode == MODE_MEMBER ? MR_DEFAULT : TRUE; + g_free(pm_name); - return pm ? pm : &parse_mode_default; + return value; }
void parse_mode_update(const char *name, gint mode, gint value) { char *pm_name = parse_mode_pm_name(name); - ParseMode *pm = (ParseMode *) array_find(parse_modes, pm_name, FALSE); + GtkTreeIter iter;
- if (!pm) + if (!store_find(parse_modes, &iter, MODE_NAME, name)) { - pm = (ParseMode *) array_append(parse_modes); - pm->name = g_strdup(pm_name); - pm->hb_mode = HB_DEFAULT; - pm->mr_mode = MR_DEFAULT; - pm->entry = TRUE; + scp_tree_store_append_with_values(parse_modes, &iter, NULL, MODE_NAME, pm_name, + MODE_HBIT, HB_DEFAULT, MODE_MEMBER, MR_DEFAULT, MODE_ENTRY, TRUE, -1); } - g_free(pm_name);
- switch (mode) - { - case MODE_HBIT : pm->hb_mode = value; break; - case MODE_MEMBER : pm->mr_mode = value; break; - default : - { - g_assert(mode == MODE_ENTRY); - pm->entry = value; - } - } - - if (pm->hb_mode == HB_DEFAULT && pm->mr_mode == MR_DEFAULT && pm->entry) - array_remove(parse_modes, pm); + g_free(pm_name); + scp_tree_store_set(parse_modes, &iter, mode, value, -1); }
gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children) @@ -573,8 +581,6 @@ gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children)
iff (name, "no name") { - const ParseMode *pm = parse_mode_find(name); - var->name = name; var->value = parse_find_value(nodes, "value"); var->expr = NULL; @@ -586,11 +592,9 @@ gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children) var->numchild = utils_atoi0(var->children); }
- pm = parse_mode_find(var->expr ? var->expr : name); - var->hb_mode = pm->hb_mode; - var->mr_mode = pm->mr_mode; - var->display = parse_get_display_from_7bit(var->value, pm->hb_mode, pm->mr_mode); - + var->hb_mode = parse_mode_get(var->expr ? var->expr : name, MODE_HBIT); + var->mr_mode = parse_mode_get(var->expr ? var->expr : name, MODE_MEMBER); + var->display = parse_get_display_from_7bit(var->value, var->hb_mode, var->mr_mode); return TRUE; }
@@ -599,23 +603,23 @@ gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children)
void parse_load(GKeyFile *config) { - array_clear(parse_modes, (GFreeFunc) parse_mode_free); + store_clear(parse_modes); utils_load(config, "parse", parse_mode_load); }
void parse_save(GKeyFile *config) { - array_save(parse_modes, config, "parse", (ASaveFunc) parse_mode_save); + store_save(parse_modes, config, "parse", parse_mode_save); }
void parse_init(void) { errors = g_string_sized_new(MAXLEN); - parse_modes = array_new(ParseMode, 0x10); + parse_modes = SCP_TREE_STORE(get_object("parse_mode_store")); + scp_tree_store_set_sort_column_id(parse_modes, MODE_NAME, GTK_SORT_ASCENDING); }
void parse_finalize(void) { g_string_free(errors, TRUE); - array_free(parse_modes, (GFreeFunc) parse_mode_free); }
Modified: scope/src/parse.h 7 files changed, 4 insertions(+), 3 deletions(-) =================================================================== @@ -32,6 +32,7 @@ void *value; } ParseNode;
+void parse_foreach(GArray *nodes, GFunc func, gpointer gdata); char *parse_string(char *text, char newline); void parse_message(char *message, const char *token); gchar *parse_get_display_from_7bit(const char *text, gint hb_mode, gint mr_mode); @@ -43,11 +44,11 @@ #define parse_find_locale(nodes, name) utils_7bit_to_locale(parse_find_value((nodes), (name))) #define parse_find_array(nodes, name) \ ((GArray *) parse_find_node_type((nodes), (name), PT_ARRAY)) -const char *parse_grab_token(GArray *nodes); /* removes from nodes */ +const char *parse_grab_token(GArray *nodes); /* removes token from nodes */ #define parse_lead_array(nodes) ((GArray *) ((ParseNode *) nodes->data)->value) #define parse_lead_value(nodes) ((char *) ((ParseNode *) nodes->data)->value)
-gchar *parse_find_error(GArray *nodes); +gchar *parse_get_error(GArray *nodes); void on_error(GArray *nodes);
typedef struct _ParseLocation @@ -110,7 +111,7 @@ enum } ParseVariable;
char *parse_mode_reentry(const char *name); -const ParseMode *parse_mode_find(const char *name); +gint parse_mode_get(const char *name, gint mode); void parse_mode_update(const char *name, gint mode, gint value); gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children); #define parse_variable_free(var) g_free((var)->display)
Modified: scope/src/program.c 142 files changed, 83 insertions(+), 59 deletions(-) =================================================================== @@ -41,48 +41,44 @@ static void stash_group_destroy(StashGroup *group, G_GNUC_UNUSED gpointer gdata) utils_stash_group_free(group); }
-typedef struct _RecentProgram +enum { - gchar *name; - guint id; -} RecentProgram; + PROGRAM_NAME, + PROGRAM_ID /* 1-based */ +};
#define RECENT_COUNT 28
-static GArray *recent_programs; +static ScpTreeStore *recent_programs; static guint recent_bitmap; static GtkWidget *recent_menu;
-static void recent_program_free(RecentProgram *program) -{ - g_free(program->name); -} - static gboolean recent_program_load(GKeyFile *config, const char *section) { gchar *name = utils_get_setting_string(config, section, "name", NULL); gint id = utils_get_setting_integer(config, section, "id", 0); + gboolean valid = FALSE;
- if (name && *name && id > 0 && (recent_bitmap & (1 << id)) == 0 && - recent_programs->len < RECENT_COUNT) + if (name && id > 0 && id <= RECENT_COUNT && (recent_bitmap & (1 << id)) == 0) { - RecentProgram *recent = (RecentProgram *) array_append(recent_programs); - - recent->name = name; - recent->id = id; + scp_tree_store_append_with_values(recent_programs, NULL, NULL, PROGRAM_NAME, name, + PROGRAM_ID, id, -1); recent_bitmap |= 1 << id; - return TRUE; + valid = TRUE; }
g_free(name); - return FALSE; + return valid; }
-static gboolean recent_program_save(GKeyFile *config, const char *section, - RecentProgram *recent) +static gboolean recent_program_save(GKeyFile *config, const char *section, GtkTreeIter *iter) { - g_key_file_set_string(config, section, "name", recent->name); - g_key_file_set_integer(config, section, "id", recent->id); + const gchar *name; + gint id; + + scp_tree_store_get(recent_programs, iter, PROGRAM_NAME, &name, PROGRAM_ID, &id, -1); + g_key_file_set_string(config, section, "name", name); + g_key_file_set_integer(config, section, "id", id); return TRUE; }
@@ -95,15 +91,18 @@ static void recent_menu_item_destroy(GtkWidget *widget, G_GNUC_UNUSED gpointer g
static gint recent_menu_count;
-static void recent_menu_item_create(RecentProgram *recent, G_GNUC_UNUSED gpointer gdata) +static void recent_menu_item_create(GtkTreeIter *iter, G_GNUC_UNUSED gpointer gdata) { if (recent_menu_count < pref_show_recent_items) { - GtkWidget *item = gtk_menu_item_new_with_label(recent->name); + const gchar *name; + GtkWidget *item;
+ scp_tree_store_get(recent_programs, iter, PROGRAM_NAME, &name, -1); + item = gtk_menu_item_new_with_label(name); gtk_menu_shell_append(GTK_MENU_SHELL(recent_menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_recent_menu_item_activate), - recent->name); + (gpointer) name); recent_menu_count++; } } @@ -112,7 +111,7 @@ static void recent_menu_create(void) { gtk_container_foreach(GTK_CONTAINER(recent_menu), recent_menu_item_destroy, NULL); recent_menu_count = 0; - array_foreach(recent_programs, (GFunc) recent_menu_item_create, NULL); + store_foreach(recent_programs, (GFunc) recent_menu_item_create, NULL); gtk_widget_show_all(GTK_WIDGET(recent_menu)); }
@@ -136,6 +135,23 @@ static char *recent_file_name(gint id) gboolean program_temp_breakpoint; gchar *program_temp_break_location;
+static gboolean program_find(GtkTreeIter *iter, const char *name) +{ + gboolean valid = scp_tree_store_get_iter_first(recent_programs, iter); + + while (valid) + { + const char *name1; + + scp_tree_store_get(recent_programs, iter, PROGRAM_NAME, &name1, -1); + if (!utils_filenamecmp(name1, name)) + break; + valid = scp_tree_store_iter_next(recent_programs, iter); + } + + return valid; +} + static void save_program_settings(void) { const gchar *program_name = *program_executable ? program_executable : @@ -143,24 +159,38 @@ static void save_program_settings(void)
if (*program_name) { - RecentProgram *recent = (RecentProgram *) array_find(recent_programs, program_name, - TRUE); + GtkTreeIter iter; + gint id; GKeyFile *config = g_key_file_new(); char *configfile;
- if (!recent) + if (program_find(&iter, program_name)) { - recent = (RecentProgram *) array_append(recent_programs); - recent->name = g_strdup(program_name); - - for (recent->id = 1; recent->id < RECENT_COUNT; recent->id++) - if ((recent_bitmap & (1 << recent->id)) == 0) - break; - - recent_bitmap |= 1 << recent->id; + scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); + scp_tree_store_move(recent_programs, &iter, 0); + } + else + { + if (scp_tree_store_iter_nth_child(recent_programs, &iter, NULL, + RECENT_COUNT - 1)) + { + scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); + scp_tree_store_remove(recent_programs, &iter); + } + else + { + for (id = 1; id < RECENT_COUNT; id++) + if ((recent_bitmap & (1 << id)) == 0) + break; + + recent_bitmap |= 1 << id; + } + + scp_tree_store_prepend_with_values(recent_programs, &iter, NULL, + PROGRAM_NAME, program_name, PROGRAM_ID, id, -1); }
- configfile = recent_file_name(recent->id); + configfile = recent_file_name(id); stash_foreach((GFunc) stash_group_save_to_key_file, config); breaks_save(config); watches_save(config); @@ -169,16 +199,6 @@ static void save_program_settings(void) utils_key_file_write_to_file(config, configfile); g_free(configfile); g_key_file_free(config); - - g_array_insert_vals(recent_programs, 0, ++recent, 1); - array_remove(recent_programs, recent); - recent_menu_create(); - - if (recent_programs->len > RECENT_COUNT) - { - recent_bitmap &= ~(1 << recent->id); - array_remove(recent_programs, recent); - } } }
@@ -207,20 +227,24 @@ static void program_configure(void)
static void on_recent_menu_item_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, const gchar *name) { - RecentProgram *recent = (RecentProgram *) array_find(recent_programs, name, TRUE); + GtkTreeIter iter;
- if (recent && utils_filenamecmp(recent->name, *program_executable ? program_executable : - program_load_script)) + if (utils_filenamecmp(name, *program_executable ? program_executable : + program_load_script) && program_find(&iter, name)) { - char *configfile = recent_file_name(recent->id); + gint id; + char *configfile; GKeyFile *config = g_key_file_new(); GError *gerror = NULL; gchar *message;
+ scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); + configfile = recent_file_name(id); + if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, &gerror)) { + scp_tree_store_move(recent_programs, &iter, 0); save_program_settings(); - recent = (RecentProgram *) array_find(recent_programs, name, TRUE); stash_foreach((GFunc) stash_group_load_from_key_file, config); if ((unsigned) option_inspect_expand > EXPAND_MAX) option_inspect_expand = 100; @@ -228,9 +252,9 @@ static void on_recent_menu_item_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, co watches_load(config); inspects_load(config); parse_load(config); - message = g_strdup_printf(_("Loaded debug settings for %s."), recent->name); - g_array_insert_vals(recent_programs, 0, ++recent, 1); - array_remove(recent_programs, recent); + message = g_strdup_printf(_("Loaded debug settings for %s."), name); + program_find(&iter, name); + scp_tree_store_move(recent_programs, &iter, 0); recent_menu_create(); program_configure(); } @@ -387,6 +411,7 @@ static void on_program_ok_button_clicked(G_GNUC_UNUSED GtkButton *button, g_free(program_environment); program_environment = utils_text_buffer_get_text(environment, -1); save_program_settings(); + recent_menu_create(); program_configure(); gtk_widget_hide(program_dialog);
@@ -531,7 +556,7 @@ void program_init(void) stash_group_add_boolean(group, &thread_show_core, "show_core", TRUE); thread_group = group;
- recent_programs = array_new(RecentProgram, RECENT_COUNT + 2); + recent_programs = SCP_TREE_STORE(get_object("recent_program_store")); recent_bitmap = 0; recent_menu = get_widget("program_recent_menu"); } @@ -543,12 +568,11 @@ void program_finalize(void)
save_program_settings(); g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); - array_save(recent_programs, config, "recent", (ASaveFunc) recent_program_save); + store_save(recent_programs, config, "recent", recent_program_save); utils_key_file_write_to_file(config, configfile); g_key_file_free(config); g_free(configfile);
- array_free(recent_programs, (GFreeFunc) recent_program_free); gtk_widget_destroy(program_dialog); stash_foreach((GFunc) stash_group_destroy, NULL); }
Modified: scope/src/scope.c 1 files changed, 0 insertions(+), 1 deletions(-) =================================================================== @@ -623,7 +623,6 @@ void plugin_cleanup(void) parse_finalize(); prefs_finalize(); debug_finalize(); - gtk216_finalize();
gtk_widget_destroy(debug_statusbar); g_object_unref(builder);
Modified: scope/src/stack.c 10 files changed, 5 insertions(+), 5 deletions(-) =================================================================== @@ -52,8 +52,8 @@ static void stack_node_location(const ParseNode *node, const char *fid) scp_tree_store_append_with_values(store, &iter, NULL, STACK_ID, id, STACK_FILE, loc.file, STACK_LINE, loc.line, STACK_BASE_NAME, loc.base_name, STACK_FUNC, loc.func, STACK_ARGS, NULL, STACK_ADDR, - loc.addr, STACK_ENTRY, !loc.func || parse_mode_find(loc.func)->entry, - -1); + loc.addr, STACK_ENTRY, !loc.func || + parse_mode_get(loc.func, MODE_ENTRY), -1); parse_location_free(&loc);
if (!g_strcmp0(id, fid)) @@ -71,7 +71,7 @@ void on_stack_frames(GArray *nodes) char *fid = g_strdup(frame_id);
stack_clear(); - array_foreach(parse_lead_array(nodes), (GFunc) stack_node_location, fid); + parse_foreach(parse_lead_array(nodes), (GFunc) stack_node_location, fid); g_free(fid);
if (!frame_id) @@ -132,7 +132,7 @@ static void stack_node_arguments(const ParseNode *node, G_GNUC_UNUSED gpointer g
sd.string = g_string_sized_new(0xFF); scp_tree_store_get(store, &iter, STACK_ENTRY, &sd.entry, -1); - array_foreach(nodes, (GFunc) append_argument_variable, &sd); + parse_foreach(nodes, (GFunc) append_argument_variable, &sd); scp_tree_store_set(store, &iter, STACK_ARGS, sd.string->str, -1); g_string_free(sd.string, TRUE); } @@ -143,7 +143,7 @@ static void stack_node_arguments(const ParseNode *node, G_GNUC_UNUSED gpointer g void on_stack_arguments(GArray *nodes) { if (!g_strcmp0(parse_grab_token(nodes), thread_id)) - array_foreach(parse_lead_array(nodes), (GFunc) stack_node_arguments, NULL); + parse_foreach(parse_lead_array(nodes), (GFunc) stack_node_arguments, NULL); }
void on_stack_follow(GArray *nodes)
Modified: scope/src/thread.c 4 files changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -388,7 +388,7 @@ void on_thread_stopped(GArray *nodes) } } else - array_foreach((GArray *) stopped->value, (GFunc) thread_node_stopped, &sd); + parse_foreach((GArray *) stopped->value, (GFunc) thread_node_stopped, &sd); }
if (thread_select_on_stopped && thread_state <= THREAD_RUNNING && sd.found) @@ -541,7 +541,7 @@ static const char *thread_info_parse(GArray *nodes, gboolean select) { const char *tid = parse_find_value(nodes, "current-thread-id");
- array_foreach(parse_lead_array(nodes), (GFunc) thread_node_parse, NULL); + parse_foreach(parse_lead_array(nodes), (GFunc) thread_node_parse, NULL);
if (tid) set_gdb_thread(tid, select);
Modified: scope/src/tooltip.c 7 files changed, 3 insertions(+), 4 deletions(-) =================================================================== @@ -76,7 +76,7 @@ void on_tooltip_error(GArray *nodes) if (atoi(parse_grab_token(nodes)) == scid_gen) { if (pref_tooltips_fail_action == 1) - tooltip_set(parse_find_error(nodes)); + tooltip_set(parse_get_error(nodes)); else { tooltip_set(NULL); @@ -92,9 +92,8 @@ void on_tooltip_value(GArray *nodes) { if (atoi(parse_grab_token(nodes)) == scid_gen) { - const ParseMode *pm = parse_mode_find(input); - tooltip_set(parse_get_display_from_7bit(parse_lead_value(nodes), pm->hb_mode, - pm->mr_mode)); + tooltip_set(parse_get_display_from_7bit(parse_lead_value(nodes), + parse_mode_get(input, MODE_HBIT), parse_mode_get(input, MODE_MEMBER))); } }
Modified: scope/src/utils.c 101 files changed, 6 insertions(+), 95 deletions(-) =================================================================== @@ -134,100 +134,6 @@ void utils_strchrepl(char *text, char c, char rep) *p = '\0'; }
-gchar *array_append(GArray *array) -{ - g_array_set_size(array, array->len + 1); - return array->data + g_array_get_element_size(array) * (array->len - 1); -} - -#ifdef G_OS_UNIX -gchar *array_find(GArray *array, const char *key, G_GNUC_UNUSED gboolean filename) -#else -gchar *array_find(GArray *array, const char *key, gboolean filename) -#endif -{ - guint size = g_array_get_element_size(array); - gchar *end = array->data + size * array->len; - gchar *data; -#ifdef G_OS_UNIX - int (*const compare)(const char *s1, const char *s2) = strcmp; -#else - int (*compare)(const char *s1, const char *s2) = filename ? utils_str_casecmp : strcmp; -#endif - - for (data = array->data; data < end; data += size) - if (!compare(*(const char **) data, key)) - return data; - - return NULL; -} - -void array_foreach(GArray *array, GFunc each_func, gpointer gdata) -{ - guint size = g_array_get_element_size(array); - gchar *end = array->data + size * array->len; - gchar *data; - - for (data = array->data; data < end; data += size) - each_func(data, gdata); -} - -guint array_index(GArray *array, gconstpointer element) -{ - return ((const gchar *) element - array->data) / g_array_get_element_size(array); -} - -void array_remove(GArray *array, gconstpointer element) -{ - g_array_remove_index(array, array_index(array, element)); -} - -static void array_free_element(gpointer element, GFreeFunc free_func) -{ - free_func(element); -} - -void array_clear(GArray *array, GFreeFunc free_func) -{ - array_foreach(array, (GFunc) array_free_element, free_func); - g_array_set_size(array, 0); -} - -void array_free(GArray *array, GFreeFunc free_func) -{ - array_foreach(array, (GFunc) array_free_element, free_func); - g_array_free(array, TRUE); -} - -static void utils_clear_sections(GKeyFile *config, const char *prefix, guint i) -{ - gboolean valid; - - do - { - char *section = g_strdup_printf("%s_%d", prefix, i++); - valid = g_key_file_remove_group(config, section, NULL); - g_free(section); - } while (valid); -} - -void array_save(GArray *array, GKeyFile *config, const gchar *prefix, ASaveFunc save_func) -{ - guint size = g_array_get_element_size(array); - gchar *end = array->data + size * array->len; - gchar *data; - guint n = 0; - - for (data = array->data; data < end; data += size) - { - char *section = g_strdup_printf("%s_%d", prefix, n); - n += save_func(config, section, data); - g_free(section); - } - - utils_clear_sections(config, prefix, n); -} - gboolean store_find(ScpTreeStore *store, GtkTreeIter *iter, guint column, const char *key) { if (scp_tree_store_get_column_type(store, column) == G_TYPE_STRING) @@ -264,7 +170,12 @@ void store_save(ScpTreeStore *store, GKeyFile *config, const gchar *prefix, g_free(section); }
- utils_clear_sections(config, prefix, i); + do + { + char *section = g_strdup_printf("%s_%d", prefix, i++); + valid = g_key_file_remove_group(config, section, NULL); + g_free(section); + } while (valid); }
gint store_gint_compare(ScpTreeStore *store, GtkTreeIter *a, GtkTreeIter *b, gpointer gdata)
Modified: scope/src/utils.h 11 files changed, 0 insertions(+), 11 deletions(-) =================================================================== @@ -29,17 +29,6 @@ const gchar *utils_skip_spaces(const gchar *text); void utils_strchrepl(char *text, char c, char repl);
-#define array_new(type, start) g_array_sized_new(FALSE, FALSE, sizeof(type), (start)) -gchar *array_append(GArray *array); -gchar *array_find(GArray *array, const char *key, gboolean filename); -void array_foreach(GArray *array, GFunc each_func, gpointer gdata); -guint array_index(GArray *array, const void *data); -void array_remove(GArray *array, const void *data); -void array_clear(GArray *array, GFreeFunc free_func); -void array_free(GArray *array, GFreeFunc free_func); -typedef gboolean (*ASaveFunc)(GKeyFile *config, const char *section, void *data); -void array_save(GArray *array, GKeyFile *config, const char *prefix, ASaveFunc save_func); - #define iff(expr, ...) if (G_UNLIKELY(!(expr))) dc_error(__VA_ARGS__); else #define utils_atoi0(s) ((s) ? atoi(s) : 0) /* note: 2 references to s */
Modified: scope/src/watch.c 18 files changed, 7 insertions(+), 11 deletions(-) =================================================================== @@ -75,11 +75,9 @@ static void on_watch_expr_edited(G_GNUC_UNUSED GtkCellRendererText *renderer,
if (strcmp(new_text, expr)) { - const ParseMode *pm = parse_mode_find(new_text); - scp_tree_store_set(store, &iter, WATCH_EXPR, new_text, WATCH_DISPLAY, NULL, - WATCH_VALUE, NULL, WATCH_HB_MODE, pm->hb_mode, WATCH_MR_MODE, - pm->mr_mode, -1); + WATCH_VALUE, NULL, WATCH_HB_MODE, parse_mode_get(new_text, MODE_HBIT), + WATCH_MR_MODE, parse_mode_get(new_text, MODE_MEMBER), -1);
if (enabled && (debug_state() & DS_DEBUG)) watch_iter_update(&iter, GINT_TO_POINTER(TRUE)); @@ -131,7 +129,7 @@ void on_watch_value(GArray *nodes)
void on_watch_error(GArray *nodes) { - watch_set(nodes, parse_find_error(nodes), NULL); + watch_set(nodes, parse_get_error(nodes), NULL); }
static void watch_iter_clear(GtkTreeIter *iter, G_GNUC_UNUSED gpointer gdata) @@ -160,12 +158,12 @@ void watch_add(const gchar *text)
if (validate_column(expr, TRUE)) { - const ParseMode *pm = parse_mode_find(expr); GtkTreeIter iter;
scp_tree_store_append_with_values(store, &iter, NULL, WATCH_EXPR, expr, - WATCH_HB_MODE, pm->hb_mode, WATCH_MR_MODE, pm->mr_mode, WATCH_SCID, - ++scid_gen, WATCH_ENABLED, TRUE, -1); + WATCH_HB_MODE, parse_mode_get(expr, MODE_HBIT), WATCH_MR_MODE, + parse_mode_get(expr, MODE_MEMBER), WATCH_SCID, ++scid_gen, WATCH_ENABLED, + TRUE, -1); utils_tree_set_cursor(selection, &iter, 0.5);
if (debug_state() & DS_DEBUG) @@ -198,9 +196,7 @@ static gboolean watch_load(GKeyFile *config, const char *section)
if (expr && (unsigned) hb_mode < HB_COUNT && (unsigned) mr_mode < MR_MODIFY) { - GtkTreeIter iter; - - scp_tree_store_append_with_values(store, &iter, NULL, WATCH_EXPR, expr, + scp_tree_store_append_with_values(store, NULL, NULL, WATCH_EXPR, expr, WATCH_HB_MODE, hb_mode, WATCH_MR_MODE, mr_mode, WATCH_SCID, ++scid_gen, WATCH_ENABLED, enabled, -1); valid = TRUE;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).