From acac24dbaae205b389c81132939280295b6a5d34 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 17 Jul 2018 00:18:03 +0200 Subject: Cleaned code. --- plugins/pychrysalide/glibext/loadedpanel.c | 89 ++++++++++++++++++++++++++++-- plugins/pychrysalide/gtkext/displaypanel.c | 83 ---------------------------- src/analysis/loaded.c | 12 +++- src/format/format.c | 8 ++- src/gtkext/gtkdisplaypanel-int.h | 3 +- src/gtkext/gtkdisplaypanel.h | 5 +- 6 files changed, 105 insertions(+), 95 deletions(-) diff --git a/plugins/pychrysalide/glibext/loadedpanel.c b/plugins/pychrysalide/glibext/loadedpanel.c index f831607..ba4ced0 100644 --- a/plugins/pychrysalide/glibext/loadedpanel.c +++ b/plugins/pychrysalide/glibext/loadedpanel.c @@ -31,6 +31,8 @@ #include +#include "../helpers.h" + /* Retrouve l'emplacement correspondant à une position donnée. */ @@ -38,6 +40,14 @@ +/* S'assure qu'un emplacement donné est visible à l'écran. */ +static PyObject *py_loaded_panel_scroll_to_cursor(PyObject *, PyObject *); + +/* Définit les constantes pour l'affichage des contenus chargés. */ +static bool py_loaded_panel_define_constants(PyTypeObject *); + + + #if 0 @@ -84,9 +94,79 @@ static PyObject *py_loaded_panel_compute_addr(PyObject *self, PyObject *args) +/****************************************************************************** +* * +* Paramètres : self = classe représentant un tampon de code. * +* args = arguments fournis à l'appel. * +* * +* Description : S'assure qu'un emplacement donné est visible à l'écran. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_panel_scroll_to_cursor(PyObject *self, PyObject *args) +{ +#if 0 + + GLoadedPanel *panel; /* Panneau à manipuler */ + PyObject *py_vmpa; /* Localisation version Python */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ + + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + panel = G_LOADED_PANEL(pygobject_get(self)); + + // FIXME + //gtk_loaded_panel_scroll_to_address(panel, addr, SPT_RAW, true); +#endif + + Py_RETURN_NONE; + +} + + + + + + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour l'affichage des contenus chargés.* +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_loaded_panel_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + result &= PyDict_AddIntMacro(obj_type, SPT_RAW); + result &= PyDict_AddIntMacro(obj_type, SPT_TOP); + result &= PyDict_AddIntMacro(obj_type, SPT_CENTER); + result &= PyDict_AddIntMacro(obj_type, SPT_BOTTOM); + return result; +} /****************************************************************************** @@ -104,13 +184,11 @@ static PyObject *py_loaded_panel_compute_addr(PyObject *self, PyObject *args) PyTypeObject *get_python_loaded_panel_type(void) { static PyMethodDef py_loaded_panel_methods[] = { - /* { - "compute_addr", py_loaded_panel_compute_addr, + "scroll_to_cursor", (PyCFunction)py_loaded_panel_scroll_to_cursor, METH_VARARGS, - "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location." + "scroll_to_cursor($self, cursor, tweak, move, /)\n--\n\nEnsure a given address is displayed in the view panel." }, - */ { NULL } }; @@ -161,6 +239,9 @@ bool register_python_loaded_panel(PyObject *module) dict = PyModule_GetDict(module); pyg_register_interface(dict, "LoadedPanel", G_TYPE_LOADED_PANEL, py_loaded_panel_type); + if (!py_loaded_panel_define_constants(py_loaded_panel_type)) + return false; + return true; } diff --git a/plugins/pychrysalide/gtkext/displaypanel.c b/plugins/pychrysalide/gtkext/displaypanel.c index b75d173..16bd1d9 100644 --- a/plugins/pychrysalide/gtkext/displaypanel.c +++ b/plugins/pychrysalide/gtkext/displaypanel.c @@ -42,12 +42,6 @@ static PyObject *py_display_panel_new(PyTypeObject *, PyObject *, PyObject *); #endif -/* S'assure qu'une adresse donnée est visible à l'écran. */ -static PyObject *py_display_panel_scroll_to_address(PyObject *, PyObject *); - -/* Définit les constantes pour les panneaux de vue. */ -static bool py_display_panel_define_constants(PyTypeObject *); - /****************************************************************************** @@ -98,73 +92,6 @@ static PyObject *py_display_panel_new(PyTypeObject *type, PyObject *args, PyObje /****************************************************************************** * * -* Paramètres : self = classe représentant un tampon de code. * -* args = arguments fournis à l'appel. * -* * -* Description : S'assure qu'une adresse donnée est visible à l'écran. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_display_panel_scroll_to_address(PyObject *self, PyObject *args) -{ - GtkDisplayPanel *panel; /* Panneau à manipuler */ - PyObject *py_vmpa; /* Localisation version Python */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Adresse visée par l'opérat° */ - - ret = PyArg_ParseTuple(args, "O", &py_vmpa); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (addr == NULL) return NULL; - - panel = GTK_DISPLAY_PANEL(pygobject_get(self)); - - // FIXME - //gtk_display_panel_scroll_to_address(panel, addr, SPT_RAW); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les panneaux de vue. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_display_panel_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, SPT_RAW); - result &= PyDict_AddIntMacro(obj_type, SPT_TOP); - result &= PyDict_AddIntMacro(obj_type, SPT_CENTER); - result &= PyDict_AddIntMacro(obj_type, SPT_BOTTOM); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -178,11 +105,6 @@ static bool py_display_panel_define_constants(PyTypeObject *obj_type) PyTypeObject *get_python_display_panel_type(void) { static PyMethodDef py_display_panel_methods[] = { - { - "scroll_to_address", (PyCFunction)py_display_panel_scroll_to_address, - METH_VARARGS, - "scroll_to_address($self, addr, tweak, /)\n--\n\nEnsure a given address is displayed in the view panel." - }, { NULL } }; @@ -257,11 +179,6 @@ bool register_python_display_panel(PyObject *module) py_display_panel_type, (PyTypeObject *)fixed); Py_DECREF(fixed); - if (!result) - goto rpdp_exit; - - result = py_display_panel_define_constants(py_display_panel_type); - rpdp_exit: return result; diff --git a/src/analysis/loaded.c b/src/analysis/loaded.c index e65cb38..5359103 100644 --- a/src/analysis/loaded.c +++ b/src/analysis/loaded.c @@ -168,7 +168,11 @@ bool g_loaded_content_restore(GLoadedContent *content, xmlDocPtr xdoc, xmlXPathC iface = G_LOADED_CONTENT_GET_IFACE(content); - result = iface->restore(content, xdoc, context, path); + if (iface->restore != NULL) + result = iface->restore(content, xdoc, context, path); + + else + result = true; return result; @@ -197,7 +201,11 @@ bool g_loaded_content_save(const GLoadedContent *content, xmlDocPtr xdoc, xmlXPa iface = G_LOADED_CONTENT_GET_IFACE(content); - result = iface->save(content, xdoc, context, path); + if (iface->save != NULL) + result = iface->save(content, xdoc, context, path); + + else + result = true; return result; diff --git a/src/format/format.c b/src/format/format.c index 5ff08e6..2101767 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -251,9 +251,13 @@ void g_binary_format_set_content(GBinFormat *format, GBinContent *content) GBinContent *g_binary_format_get_content(const GBinFormat *format) { - g_object_ref(G_OBJECT(format->content)); + GBinContent *result; /* Instance à retourner */ - return format->content; + result = format->content; + + g_object_ref(G_OBJECT(result)); + + return result; } diff --git a/src/gtkext/gtkdisplaypanel-int.h b/src/gtkext/gtkdisplaypanel-int.h index cf0335a..ffed3b1 100644 --- a/src/gtkext/gtkdisplaypanel-int.h +++ b/src/gtkext/gtkdisplaypanel-int.h @@ -32,7 +32,8 @@ #include -#include "../glibext/glinecursor.h" +#include "../analysis/binary.h" +#include "../glibext/gloadedpanel.h" diff --git a/src/gtkext/gtkdisplaypanel.h b/src/gtkext/gtkdisplaypanel.h index b336799..51648df 100644 --- a/src/gtkext/gtkdisplaypanel.h +++ b/src/gtkext/gtkdisplaypanel.h @@ -26,11 +26,10 @@ #include +#include -#include "../analysis/binary.h" -#include "../glibext/glinecursor.h" -#include "../glibext/gloadedpanel.h" +#include "../arch/vmpa.h" -- cgit v0.11.2-87-g4458