diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-07-16 14:31:40 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-07-16 14:31:40 (GMT) |
commit | e0d03e3eddb9d240cc21ac1b7a7ade915fd17942 (patch) | |
tree | 9543a9d1330262239f3943b8459bde1429a35dbb /src/analysis/db/items | |
parent | 7a009c76657478c9270acec0c2b236523bfd68eb (diff) |
Updated the move entry from database items.
Diffstat (limited to 'src/analysis/db/items')
-rw-r--r-- | src/analysis/db/items/bookmark.c | 18 | ||||
-rw-r--r-- | src/analysis/db/items/bookmark.h | 2 | ||||
-rw-r--r-- | src/analysis/db/items/comment.c | 18 | ||||
-rw-r--r-- | src/analysis/db/items/comment.h | 2 | ||||
-rw-r--r-- | src/analysis/db/items/move.c | 135 | ||||
-rw-r--r-- | src/analysis/db/items/move.h | 16 | ||||
-rw-r--r-- | src/analysis/db/items/switcher.c | 26 | ||||
-rw-r--r-- | src/analysis/db/items/switcher.h | 2 |
8 files changed, 125 insertions, 94 deletions
diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c index 2fa2544..712a5eb 100644 --- a/src/analysis/db/items/bookmark.c +++ b/src/analysis/db/items/bookmark.c @@ -747,17 +747,27 @@ GBookmarkCollection *g_bookmark_collection_new(void) static bool g_bookmark_collection_create_db_table(const GBookmarkCollection *collec, sqlite3 *db) { - char *sql; /* Requête à exécuter */ - int ret; /* Bilan de la création */ + const char *sql; /* Patron de Requête SQL */ + char *addr_fields; /* Champs pour l'adresse */ + char *request; /* Requête à exécuter */ char *msg; /* Message d'erreur */ + int ret; /* Bilan de la création */ sql = "CREATE TABLE Bookmarks (" \ SQLITE_DB_ITEM_CREATE ", " \ - SQLITE_SIMPLE_VMPA_CREATE ", " \ + "%%s, " \ SQLITE_RLESTR_CREATE("comment") \ ");"; + addr_fields = create_vmpa_db_table(NULL); + + asprintf(&request, sql, addr_fields); + ret = sqlite3_exec(db, sql, NULL, NULL, &msg); + + free(addr_fields); + free(request); + if (ret != SQLITE_OK) { fprintf(stderr, "sqlite3_exec(): %s\n", msg); @@ -791,7 +801,7 @@ static bool g_bookmark_collection_setup_load(GBookmarkCollection *collec, bound_ values, count); if (!status) return false; - if (!setup_load_for_vmpa(NULL, NULL, values, count)) + if (!setup_load_for_vmpa(NULL, values, count)) return false; if (!setup_load_of_rle_string(NULL, "comment", values, count)) diff --git a/src/analysis/db/items/bookmark.h b/src/analysis/db/items/bookmark.h index 2dee2f2..a8526f7 100644 --- a/src/analysis/db/items/bookmark.h +++ b/src/analysis/db/items/bookmark.h @@ -27,8 +27,6 @@ #include <glib-object.h> -#include <sqlite3.h> -#include <stdbool.h> #include "../../../arch/vmpa.h" diff --git a/src/analysis/db/items/comment.c b/src/analysis/db/items/comment.c index 57bb017..182b2d0 100644 --- a/src/analysis/db/items/comment.c +++ b/src/analysis/db/items/comment.c @@ -1587,20 +1587,30 @@ GCommentCollection *g_comment_collection_new(void) static bool g_comment_collection_create_db_table(const GCommentCollection *collec, sqlite3 *db) { - char *sql; /* Requête à exécuter */ - int ret; /* Bilan de la création */ + const char *sql; /* Patron de Requête SQL */ + char *addr_fields; /* Champs pour l'adresse */ + char *request; /* Requête à exécuter */ char *msg; /* Message d'erreur */ + int ret; /* Bilan de la création */ sql = "CREATE TABLE Comments (" \ SQLITE_DB_ITEM_CREATE ", " \ - SQLITE_SIMPLE_VMPA_CREATE ", " \ + "%%s, " \ "flags INTEGER, " \ SQLITE_RLESTR_CREATE("text") ", " \ "inlined INTEGER, " \ "repeatable INTEGER" \ ");"; + addr_fields = create_vmpa_db_table(NULL); + + asprintf(&request, sql, addr_fields); + ret = sqlite3_exec(db, sql, NULL, NULL, &msg); + + free(addr_fields); + free(request); + if (ret != SQLITE_OK) { fprintf(stderr, "sqlite3_exec(): %s\n", msg); @@ -1635,7 +1645,7 @@ static bool g_comment_collection_setup_load(GCommentCollection *collec, bound_va values, count); if (!status) return false; - if (!setup_load_for_vmpa(NULL, NULL, values, count)) + if (!setup_load_for_vmpa(NULL, values, count)) return false; *count += 1; diff --git a/src/analysis/db/items/comment.h b/src/analysis/db/items/comment.h index 1558228..31124ac 100644 --- a/src/analysis/db/items/comment.h +++ b/src/analysis/db/items/comment.h @@ -27,8 +27,6 @@ #include <glib-object.h> -#include <sqlite3.h> -#include <stdbool.h> #include "../../../arch/vmpa.h" diff --git a/src/analysis/db/items/move.c b/src/analysis/db/items/move.c index e0e726a..5653649 100644 --- a/src/analysis/db/items/move.c +++ b/src/analysis/db/items/move.c @@ -36,10 +36,9 @@ #include "../collection-int.h" #include "../item-int.h" #include "../../../gui/core/global.h" -#include "../../../glibext/gbinarycursor.h" // REMME -#include "../../../gtkext/gtkdisplaypanel.h" - - +#include "../../../glibext/gbinarycursor.h" +#include "../../../glibext/gloadedpanel.h" +#include "../../../gtkext/gtkdisplaypanel.h" // REMME @@ -51,8 +50,8 @@ struct _GDbMove { GDbItem parent; /* A laisser en premier */ - vmpa2t src; /* Emplacement de départ */ - vmpa2t dest; /* Emplacement d'arrivée */ + GLineCursor *src; /* Emplacement de départ */ + GLineCursor *dest; /* Emplacement d'arrivée */ }; @@ -64,7 +63,6 @@ struct _GDbMoveClass }; - /* Initialise la classe des déplacements au sein de codes. */ static void g_db_move_class_init(GDbMoveClass *); @@ -90,7 +88,7 @@ static bool g_db_move_pack(const GDbMove *, packed_buffer *); static void g_db_move_build_label(GDbMove *); /* Exécute un déplacement dans une zone de code. */ -static bool g_db_move_run(const GDbMove *, const vmpa2t *); +static bool g_db_move_run(const GDbMove *, GLineCursor *); /* Applique un déplacement au sein d'une zone de code. */ static bool g_db_move_apply(GDbMove *, GLoadedBinary *); @@ -106,7 +104,6 @@ static bool g_db_move_load(GDbMove *, const bound_value *, size_t); - /* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */ @@ -230,6 +227,9 @@ static void g_db_move_init(GDbMove *move) static void g_db_move_dispose(GDbMove *move) { + g_object_unref(G_OBJECT(move->src)); + g_object_unref(G_OBJECT(move->dest)); + G_OBJECT_CLASS(g_db_move_parent_class)->dispose(G_OBJECT(move)); } @@ -267,14 +267,14 @@ static void g_db_move_finalize(GDbMove *move) * * ******************************************************************************/ -GDbMove *g_db_move_new(const vmpa2t *src, const vmpa2t *dest) +GDbMove *g_db_move_new(const GLineCursor *src, const GLineCursor *dest) { GDbMove *result; /* Instance à retourner */ result = g_object_new(G_TYPE_DB_MOVE, NULL); - copy_vmpa(&result->src, src); - copy_vmpa(&result->dest, dest); + result->src = g_line_cursor_duplicate(src); + result->dest = g_line_cursor_duplicate(dest); return result; @@ -299,10 +299,10 @@ static gint g_db_move_cmp(GDbMove *a, GDbMove *b, bool with) { gint result; /* Bilan de la comparaison */ - result = cmp_vmpa(&a->src, &b->src); + result = g_line_cursor_compare(a->src, b->src); if (result == 0) - result = cmp_vmpa(&a->dest, &b->dest); + result = g_line_cursor_compare(a->dest, b->dest); if (result == 0) result = G_DB_ITEM_CLASS(g_db_move_parent_class)->cmp(G_DB_ITEM(a), G_DB_ITEM(b), with); @@ -331,11 +331,14 @@ static bool g_db_move_unpack(GDbMove *move, packed_buffer *pbuf) result = G_DB_ITEM_CLASS(g_db_move_parent_class)->unpack(G_DB_ITEM(move), pbuf); + move->src = g_binary_cursor_new(); + move->dest = g_binary_cursor_new(); + if (result) - result = unpack_vmpa(&move->src, pbuf); + result = g_line_cursor_unserialize(move->src, pbuf); if (result) - result = unpack_vmpa(&move->dest, pbuf); + result = g_line_cursor_unserialize(move->dest, pbuf); return result; @@ -362,10 +365,10 @@ static bool g_db_move_pack(const GDbMove *move, packed_buffer *pbuf) result = G_DB_ITEM_CLASS(g_db_move_parent_class)->pack(G_DB_ITEM(move), pbuf); if (result) - result = pack_vmpa(&move->src, pbuf); + result = g_line_cursor_serialize(move->src, pbuf); if (result) - result = pack_vmpa(&move->dest, pbuf); + result = g_line_cursor_serialize(move->dest, pbuf); return result; @@ -386,22 +389,24 @@ static bool g_db_move_pack(const GDbMove *move, packed_buffer *pbuf) static void g_db_move_build_label(GDbMove *move) { - VMPA_BUFFER(src_loc); /* Indication de position #1 */ - VMPA_BUFFER(dest_loc); /* Indication de position #2 */ + char *src_label; /* Indication de position #1 */ + char *dest_label; /* Indication de position #2 */ - vmpa2_to_string(&move->src, MDS_UNDEFINED, src_loc, NULL); + src_label = g_line_cursor_build_label(move->src); + dest_label = g_line_cursor_build_label(move->dest); - vmpa2_to_string(&move->dest, MDS_UNDEFINED, dest_loc, NULL); + asprintf(&G_DB_ITEM(move)->label, _("Move from %s to %s"), src_label, dest_label); - asprintf(&G_DB_ITEM(move)->label, _("Move from %s to %s"), src_loc, dest_loc); + free(src_label); + free(dest_label); } /****************************************************************************** * * -* Paramètres : move = informations de déplacement à consulter. * -* addr = localisation à placer bien en évidence. * +* Paramètres : move = informations de déplacement à consulter. * +* cursor = localisation à placer bien en évidence. * * * * Description : Exécute un déplacement dans une zone de code. * * * @@ -411,14 +416,14 @@ static void g_db_move_build_label(GDbMove *move) * * ******************************************************************************/ -static bool g_db_move_run(const GDbMove *move, const vmpa2t *addr) +static bool g_db_move_run(const GDbMove *move, GLineCursor *cursor) { - GtkDisplayPanel *panel; /* Afficheur effectif de code */ + GLoadedPanel *panel; /* Afficheur effectif de code */ typedef struct _move_params { - GtkDisplayPanel *panel; /* Afficheur effectif de code */ - vmpa2t addr; /* Adresse de déplacement */ + GLoadedPanel *panel; /* Afficheur effectif de code */ + GLineCursor *cursor; /* Emplacement à rejoindre */ } move_params; @@ -429,6 +434,7 @@ static bool g_db_move_run(const GDbMove *move, const vmpa2t *addr) void delete_move_params(move_params *p) { g_object_unref(G_OBJECT(p->panel)); + g_object_unref(G_OBJECT(p->cursor)); free(p); @@ -438,14 +444,7 @@ static bool g_db_move_run(const GDbMove *move, const vmpa2t *addr) gboolean do_move_in_main_loop(move_params *p) { - GLineCursor *___tmp; - - ___tmp = g_binary_cursor_new(); - g_binary_cursor_update(G_BINARY_CURSOR(___tmp), &p->addr); - - gtk_display_panel_scroll_to_cursor(p->panel, ___tmp, SPT_CENTER); - - g_object_unref(G_OBJECT(___tmp)); + gtk_display_panel_scroll_to_cursor(p->panel, p->cursor, SPT_CENTER); return G_SOURCE_REMOVE; @@ -455,13 +454,15 @@ static bool g_db_move_run(const GDbMove *move, const vmpa2t *addr) panel = get_current_view(); - if (GTK_IS_DISPLAY_PANEL(panel)) + if (G_IS_LOADED_PANEL(panel)) { params = (move_params *)calloc(1, sizeof(move_params)); - params->panel = GTK_DISPLAY_PANEL(panel); + params->panel = panel; + params->cursor = cursor; - copy_vmpa(¶ms->addr, addr); + g_object_ref(G_OBJECT(params->panel)); + g_object_ref(G_OBJECT(params->cursor)); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)do_move_in_main_loop, @@ -469,6 +470,9 @@ static bool g_db_move_run(const GDbMove *move, const vmpa2t *addr) } + if (panel != NULL) + g_object_unref(G_OBJECT(panel)); + return true; } @@ -491,7 +495,7 @@ static bool g_db_move_apply(GDbMove *move, GLoadedBinary *binary) { bool result; /* Bilan à faire remonter */ - result = g_db_move_run(move, &move->dest); + result = g_db_move_run(move, move->dest); return result; @@ -515,7 +519,7 @@ static bool g_db_move_cancel(GDbMove *move, GLoadedBinary *binary) { bool result; /* Bilan à faire remonter */ - result = g_db_move_run(move, &move->src); + result = g_db_move_run(move, move->src); return result; @@ -543,10 +547,10 @@ static bool g_db_move_prepare_db_statement(const GDbMove *move, bound_value **va status = G_DB_ITEM_CLASS(g_db_move_parent_class)->prepare_stmt(G_DB_ITEM(move), values, count); if (!status) return false; - status = prepare_vmpa_db_statement(&move->src, "src", values, count); + status = g_line_cursor_prepare_db_statement(move->src, "src", values, count); if (!status) return false; - status = prepare_vmpa_db_statement(&move->dest, "dest", values, count); + status = g_line_cursor_prepare_db_statement(move->src, "dest", values, count); if (!status) return false; return true; @@ -574,9 +578,11 @@ static bool g_db_move_load(GDbMove *move, const bound_value *values, size_t coun result = G_DB_ITEM_CLASS(g_db_move_parent_class)->load(G_DB_ITEM(move), values, count); - result &= load_vmpa(&move->src, "src", values, count); + if (result) + result = g_line_cursor_load(move->src, "src", values, count); - result &= load_vmpa(&move->dest, "dest", values, count); + if (result) + result = g_line_cursor_load(move->dest, "dest", values, count); return result; @@ -721,17 +727,30 @@ GMoveCollection *g_move_collection_new(void) static bool g_move_collection_create_db_table(const GMoveCollection *collec, sqlite3 *db) { - char *sql; /* Requête à exécuter */ - int ret; /* Bilan de la création */ + const char *sql; /* Patron de Requête SQL */ + char *src_fields; /* Champs pour la source */ + char *dest_fields; /* Champs pour la destination */ + char *request; /* Requête à exécuter */ char *msg; /* Message d'erreur */ + int ret; /* Bilan de la création */ - sql = "CREATE TABLE Moves (" \ - SQLITE_DB_ITEM_CREATE ", " \ - SQLITE_VMPA_CREATE("src") ", " \ - SQLITE_VMPA_CREATE("dest") \ + sql = "CREATE TABLE Moves (" \ + SQLITE_DB_ITEM_CREATE ", " \ + "%%s, " \ + "%%s" \ ");"; + src_fields = g_binary_cursor_create_db_table("src"); + dest_fields = g_binary_cursor_create_db_table("dest"); + + asprintf(&request, sql, src_fields, dest_fields); + ret = sqlite3_exec(db, sql, NULL, NULL, &msg); + + free(src_fields); + free(dest_fields); + free(request); + if (ret != SQLITE_OK) { fprintf(stderr, "sqlite3_exec(): %s\n", msg); @@ -765,10 +784,10 @@ static bool g_move_collection_setup_load(GMoveCollection *collec, bound_value ** values, count); if (!status) return false; - if (!setup_load_for_vmpa(NULL, "src", values, count)) + if (!g_binary_cursor_setup_load("src", values, count)) return false; - if (!setup_load_for_vmpa(NULL, "dest", values, count)) + if (!g_binary_cursor_setup_load("dest", values, count)) return false; return true; @@ -793,14 +812,14 @@ static bool g_move_collection_setup_load(GMoveCollection *collec, bound_value ** static GDbItem *g_move_collection_has_key(GMoveCollection *collec, va_list ap) { GDbItem *result; /* Bilan à retourner */ - vmpa2t *ref; /* Adresse de référence */ + const GLineCursor *ref; /* Emplacement de référence */ GList *items; /* Eléments déjà en place */ GList *iter; /* Boucle de parcours */ - GDbMove *bm; /* Signet à consulter */ + GDbMove *bm; /* Signet à consulter */ result = NULL; - ref = va_arg(ap, vmpa2t *); + ref = va_arg(ap, const GLineCursor *); items = g_db_collection_list_items(G_DB_COLLECTION(collec)); @@ -808,7 +827,7 @@ static GDbItem *g_move_collection_has_key(GMoveCollection *collec, va_list ap) { bm = G_DB_MOVE(iter->data); - if (cmp_vmpa(&bm->src, ref) != 0) + if (g_line_cursor_compare(bm->src, ref) == 0) /** * Un verrou est sensé être posé, donc il n'y a pas besoin diff --git a/src/analysis/db/items/move.h b/src/analysis/db/items/move.h index 167b969..dbd24f9 100644 --- a/src/analysis/db/items/move.h +++ b/src/analysis/db/items/move.h @@ -26,11 +26,9 @@ #include <glib-object.h> -#include <sqlite3.h> -#include <stdbool.h> -#include "../../../arch/vmpa.h" +#include "../../../glibext/glinecursor.h" @@ -56,18 +54,8 @@ typedef struct _GDbMoveClass GDbMoveClass; GType g_db_move_get_type(void); /* Organise un déplacement d'une position à une autre. */ -GDbMove *g_db_move_new(const vmpa2t *, const vmpa2t *); +GDbMove *g_db_move_new(const GLineCursor *, const GLineCursor *); -#if 0 -/* Fournit l'adresse associée à un signet. */ -const vmpa2t *g_db_move_get_address(GDbMove *); - -/* Fournit le commentaire associé à un signet. */ -const char *g_db_move_get_comment(const GDbMove *); - -/* Définit le commentaire associé à un signet. */ -void g_db_move_set_comment(GDbMove *, const char *); -#endif /* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */ diff --git a/src/analysis/db/items/switcher.c b/src/analysis/db/items/switcher.c index b583b65..58e4c7f 100644 --- a/src/analysis/db/items/switcher.c +++ b/src/analysis/db/items/switcher.c @@ -871,18 +871,28 @@ GSwitcherCollection *g_switcher_collection_new(void) static bool g_switcher_collection_create_db_table(const GSwitcherCollection *collec, sqlite3 *db) { - char *sql; /* Requête à exécuter */ - int ret; /* Bilan de la création */ + const char *sql; /* Patron de Requête SQL */ + char *addr_fields; /* Champs pour l'adresse */ + char *request; /* Requête à exécuter */ char *msg; /* Message d'erreur */ + int ret; /* Bilan de la création */ - sql = "CREATE TABLE Switchers (" \ - SQLITE_DB_ITEM_CREATE ", " \ - SQLITE_SIMPLE_VMPA_CREATE ", " \ - "op_index INTEGER, " \ - "type INTEGER" \ + sql = "CREATE TABLE Switchers (" \ + SQLITE_DB_ITEM_CREATE ", " \ + "%%s, " \ + "op_index INTEGER, " \ + "type INTEGER" \ ");"; + addr_fields = create_vmpa_db_table(NULL); + + asprintf(&request, sql, addr_fields); + ret = sqlite3_exec(db, sql, NULL, NULL, &msg); + + free(addr_fields); + free(request); + if (ret != SQLITE_OK) { fprintf(stderr, "sqlite3_exec(): %s\n", msg); @@ -917,7 +927,7 @@ static bool g_switcher_collection_setup_load(GSwitcherCollection *collec, bound_ values, count); if (!status) return false; - if (!setup_load_for_vmpa(NULL, NULL, values, count)) + if (!setup_load_for_vmpa(NULL, values, count)) return false; *count += 2; diff --git a/src/analysis/db/items/switcher.h b/src/analysis/db/items/switcher.h index 651b3d7..4947383 100644 --- a/src/analysis/db/items/switcher.h +++ b/src/analysis/db/items/switcher.h @@ -26,8 +26,6 @@ #include <glib-object.h> -#include <sqlite3.h> -#include <stdbool.h> #include "../../../arch/immediate.h" |