summaryrefslogtreecommitdiff
path: root/src/glibext/generators/hex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/generators/hex.c')
-rw-r--r--src/glibext/generators/hex.c469
1 files changed, 413 insertions, 56 deletions
diff --git a/src/glibext/generators/hex.c b/src/glibext/generators/hex.c
index 668ebae..6058825 100644
--- a/src/glibext/generators/hex.c
+++ b/src/glibext/generators/hex.c
@@ -28,14 +28,26 @@
#include <ctype.h>
+#include "../generator-int.h"
+#include "../options/hex.h"
+
+
+
+
+#if 0
+
+//#include <ctype.h>
+
+
#include "../bufferline.h"
#include "../gbinarycursor.h"
-#include "../linegen-int.h"
#include "../linesegment.h"
#include "../../core/columns.h"
#include "../../core/params.h"
#include "../../gtkext/hexdisplay.h"
+#endif
+
/* --------------------------- RENDU AMIQUE D'HEXADECIMAL --------------------------- */
@@ -48,9 +60,13 @@ struct _GHexGenerator
GBinContent *content; /* Contenu à représenter */
+#if 0
+
gint left_start; /* Abscisse des impressions */
gint padding; /* Bourrage supplémentaire */
+#endif
+
phys_t bytes_per_line; /* Nombre d'octets par ligne */
};
@@ -60,11 +76,15 @@ struct _GHexGeneratorClass
{
GObjectClass parent; /* A laisser en premier */
+#if 0
+
gint addr_width; /* Largeur des positions */
gint byte_width; /* Largeur d'un octet brut */
gint sep_width; /* Largeur de séparation */
gint char_width; /* Largeur d'un caractère */
+#endif
+
};
@@ -75,7 +95,7 @@ static void g_hex_generator_class_init(GHexGeneratorClass *);
static void g_hex_generator_init(GHexGenerator *);
/* Procède à l'initialisation de l'interface de génération. */
-static void g_hex_generator_interface_init(GLineGeneratorInterface *);
+static void g_hex_generator_token_generator_iface_init(GTokenGeneratorInterface *);
/* Supprime toutes les références externes. */
static void g_hex_generator_dispose(GHexGenerator *);
@@ -91,6 +111,13 @@ static void g_hex_generator_finalize(GHexGenerator *);
/* Indique le nombre de ligne prêtes à être générées. */
static size_t g_hex_generator_count_lines(const GHexGenerator *);
+/* Etablit dans une ligne de rendu le contenu représenté. */
+static void g_hex_generator_populate_line(const GHexGenerator *, size_t, size_t, GBufferLine *, void *);
+
+
+
+
+#if 0
#ifdef INCLUDE_GTK_SUPPORT
/* Retrouve l'emplacement correspondant à une position donnée. */
@@ -106,6 +133,7 @@ static BufferLineFlags g_hex_generator_get_flags(const GHexGenerator *, size_t,
/* Imprime dans une ligne de rendu le contenu représenté. */
static void g_hex_generator_print(GHexGenerator *, GBufferLine *, size_t, size_t);
+#endif
@@ -116,7 +144,7 @@ static void g_hex_generator_print(GHexGenerator *, GBufferLine *, size_t, size_t
/* Détermine le type du générateur de lignes hexadécimales à la volée. */
G_DEFINE_TYPE_WITH_CODE(GHexGenerator, g_hex_generator, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE(G_TYPE_LINE_GENERATOR, g_hex_generator_interface_init));
+ G_IMPLEMENT_INTERFACE(G_TYPE_TOKEN_GENERATOR, g_hex_generator_token_generator_iface_init));
/******************************************************************************
@@ -134,13 +162,15 @@ G_DEFINE_TYPE_WITH_CODE(GHexGenerator, g_hex_generator, G_TYPE_OBJECT,
static void g_hex_generator_class_init(GHexGeneratorClass *class)
{
GObjectClass *object; /* Autre version de la classe */
- line_segment *segment; /* Segment de test pour mesure */
+ //line_segment *segment; /* Segment de test pour mesure */
object = G_OBJECT_CLASS(class);
object->dispose = (GObjectFinalizeFunc/* ! */)g_hex_generator_dispose;
object->finalize = (GObjectFinalizeFunc)g_hex_generator_finalize;
+#if 0
+
/* Mesure de quelques dimensions */
segment = get_new_line_segment(RTT_PHYS_ADDR, "0x00000000", 10);
@@ -167,6 +197,8 @@ static void g_hex_generator_class_init(GHexGeneratorClass *class)
release_line_segment(segment);
+#endif
+
}
@@ -184,7 +216,7 @@ static void g_hex_generator_class_init(GHexGeneratorClass *class)
static void g_hex_generator_init(GHexGenerator *generator)
{
- generator->bytes_per_line = 4;
+ generator->bytes_per_line = 0;
}
@@ -201,15 +233,20 @@ static void g_hex_generator_init(GHexGenerator *generator)
* *
******************************************************************************/
-static void g_hex_generator_interface_init(GLineGeneratorInterface *iface)
+static void g_hex_generator_token_generator_iface_init(GTokenGeneratorInterface *iface)
{
- iface->count = (linegen_count_lines_fc)g_hex_generator_count_lines;
+ iface->count = (count_tokgen_lines_fc)g_hex_generator_count_lines;
+
+ iface->populate = (populate_tokgen_line_fc)g_hex_generator_populate_line;
+
+#if 0
#ifdef INCLUDE_GTK_SUPPORT
iface->compute = (linegen_compute_fc)g_hex_generator_compute_cursor;
iface->contain = (linegen_contain_fc)g_hex_generator_contain_cursor;
#endif
iface->get_flags = (linegen_get_flags_fc)g_hex_generator_get_flags;
iface->print = (linegen_print_fc)g_hex_generator_print;
+#endif
}
@@ -228,8 +265,7 @@ static void g_hex_generator_interface_init(GLineGeneratorInterface *iface)
static void g_hex_generator_dispose(GHexGenerator *generator)
{
- if (generator->content != NULL)
- g_object_unref(G_OBJECT(generator->content));
+ g_clear_object(&generator->content);
G_OBJECT_CLASS(g_hex_generator_parent_class)->dispose(G_OBJECT(generator));
@@ -274,8 +310,239 @@ GHexGenerator *g_hex_generator_new(GBinContent *content)
result = g_object_new(G_TYPE_HEX_GENERATOR, NULL);
result->content = content;
+ ref_object(content);
+
+ return result;
+
+}
+
+
+// TODO create...
+
+
+/******************************************************************************
+* *
+* Paramètres : generator = générateur à consulter. *
+* *
+* Description : Fournit le contenu associé au générateur de lignes hexa. *
+* *
+* Retour : Contenu dans lequel puise le générateur pour les lignes. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinContent *g_hex_generator_get_content(const GHexGenerator *generator)
+{
+ GBinContent *result; /* Référence à retourner */
+
+ result = generator->content;
+
+ ref_object(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : generator = générateur à ajuster. *
+* options = options d'affichage des colonnes. *
+* style = style de rendus des bribes de texte. *
+* width = largeur disponible pour les différentes colonnes.*
+* *
+* Description : Détermine la hauteur idéale d'un contenu lié à une largeur. *
+* *
+* Retour : Hauteur nécessaire pour les lignes induites. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int g_hex_generator_mesure_height_for_width(GHexGenerator *generator, const GDisplayOptions *options, const GTokenStyle *style, int width)
+{
+ int result; /* Taille à retourner */
+ vmpa2t end; /* Position terminale */
+ bool status; /* Bilan d'une opération */
+ int off_size; /* Taille des emplacements */
+ int byte_width; /* Largeur d'un octet brut */
+ int sep_width; /* Largeur de séparation */
+ int char_width; /* Largeur d'un caractère */
+ phys_t i; /* Boucle de parcours */
+ phys_t block_count; /* Nombre de blocs d'octets */
+ int requested; /* Espace requis pour X octets */
+ phys_t size; /* Taille du contenu binaire */
+ phys_t line_count; /* Nombre de lignes requises */
+
+ result = -1;
+
+ /* Largeur des positions */
+
+ if (g_display_options_get(options, HCO_OFFSET))
+ {
+ status = g_binary_content_compute_end_pos(generator->content, &end);
+ assert(status);
+ if (!status) goto done;
+
+ off_size = g_token_style_compute_location_width(style, end.physical, false);
+
+ width -= off_size;
+
+ }
+
+ /* Détermination des tailles basiques */
+
+ byte_width = g_token_style_measure_width(style, TRT_RAW_CODE, 2 /* 00 */);
+
+ sep_width = g_token_style_measure_width(style, TRT_RAW_CODE, TAB_SIZE /* \t */);
+
+ char_width = g_token_style_measure_width(style, TRT_RAW_CODE, 1 /* 0 */);
+
+ for (i = 4; ; i += 4)
+ {
+ block_count = (i / 4);
+
+ requested = i * byte_width + 3 * block_count * char_width;
+ requested += (block_count > 1 ? block_count - 1 : 0) * sep_width;
+
+ requested += i * char_width;
+
+ /* Limite atteinte ? */
+ if (requested > width)
+ {
+ i -= 4;
+ break;
+ }
+
+ }
+
+ if (i == 0)
+ i = 4;
+
+ /* Détermination de la taille pour un nombre de lignes donné */
+
+ size = g_binary_content_compute_size(generator->content);
+
+ line_count = size / i;
+
+ if (size % i > 0)
+ line_count++;
+
+ result = line_count * g_token_style_get_line_height(style);
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : generator = générateur à ajuster. *
+* options = options d'affichage des colonnes. *
+* style = style de rendus des bribes de texte. *
+* width = largeur disponible pour les différentes colonnes.*
+* columns = largeurs adaptées pour les colonnes. [OUT] *
+* *
+* Description : Détermine les différentes largeurs de colonnes requises. *
+* *
+* Retour : true si un changement de contenu a été déterminé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_hex_generator_allocate(GHexGenerator *generator, const GDisplayOptions *options, const GTokenStyle *style, int width, int *columns)
+{
+ bool result; /* Variation d'état à remonter */
+ vmpa2t end; /* Position terminale */
+ bool status; /* Bilan d'une opération */
+ int byte_width; /* Largeur d'un octet brut */
+ int sep_width; /* Largeur de séparation */
+ int char_width; /* Largeur d'un caractère */
+ phys_t i; /* Boucle de parcours */
+ phys_t block_count; /* Nombre de blocs d'octets */
+ int requested; /* Espace requis pour X octets */
+
+ result = false;
+
+ /* Largeur des positions */
+
+ status = g_binary_content_compute_end_pos(generator->content, &end);
+ assert(status);
+ if (!status) goto done;
+
+ columns[HCO_OFFSET] = g_token_style_compute_location_width(style, end.physical, false);
+
+ if (g_display_options_get(options, HCO_OFFSET))
+ width -= columns[HCO_OFFSET];
+
+ /* Détermination des tailles basiques */
+
+ byte_width = g_token_style_measure_width(style, TRT_RAW_CODE, 2 /* 00 */);
+
+ sep_width = g_token_style_measure_width(style, TRT_RAW_CODE, TAB_SIZE /* \t */);
+
+ char_width = g_token_style_measure_width(style, TRT_RAW_CODE, 1 /* 0 */);
+
+ for (i = 4; ; i += 4)
+ {
+ block_count = (i / 4);
+
+ requested = i * byte_width + 3 * block_count * char_width;
+ requested += (block_count > 1 ? block_count - 1 : 0) * sep_width;
+
+ requested += i * char_width;
+
+ /* Limite atteinte ? */
+ if (requested > width)
+ {
+ i -= 4;
+ break;
+ }
+
+ }
+
+ if (i == 0)
+ i = 4;
+
+ /* Détermination des largeurs de colonnes principales */
+
+ columns[HCO_COUNT + 0] = i * byte_width + 3 * block_count * char_width;
+ columns[HCO_COUNT + 0] += (block_count > 1 ? block_count - 1 : 0) * sep_width;
+
+ columns[HCO_COUNT + 1] = i * char_width;
+
+ result = (generator->bytes_per_line != i);
+
+ generator->bytes_per_line = i;
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : generator = générateur à consulter. *
+* *
+* Description : Indique le nombre d'octets programmés constituer une ligne. *
+* *
+* Retour : Nombre d'octets représentés sur chaque ligne. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- g_object_ref(G_OBJECT(result->content));
+phys_t g_hex_generator_get_bytes_per_line(const GHexGenerator *generator)
+{
+ phys_t result; /* Quantité d'octets à renvoyer*/
+
+ result = generator->bytes_per_line;
return result;
@@ -317,6 +584,136 @@ static size_t g_hex_generator_count_lines(const GHexGenerator *generator)
}
+/******************************************************************************
+* *
+* Paramètres : generator = générateur à utiliser pour l'impression. *
+* index = indice de cette même ligne dans le tampon global.*
+* repeat = indice d'utilisations successives du générateur. *
+* line = ligne de rendu à compléter. *
+* data = éventuelle donnée complémentaire fournie. *
+* *
+* Description : Etablit dans une ligne de rendu le contenu représenté. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hex_generator_populate_line(const GHexGenerator *generator, size_t index, size_t repeat, GBufferLine *line, void *data)
+{
+
+
+ //GGenConfig *config; /* Configuration à consulter */
+ bool upper_case; /* Casse des données en hexa */
+#ifndef NDEBUG
+ bool status; /* Bilan de la consultation */
+#endif
+ const char *hexa; /* Chaîne à considérer #0 */
+ const char *ff; /* Chaîne à considérer #1 */
+ vmpa2t pos; /* Position définie à la volée */
+ phys_t got; /* Quantité affichable */
+ const bin_t *raw; /* Accès direct et brut */
+ phys_t i; /* Boucle de parcours */
+ bin_t byte; /* Copie pour confort */
+ char tmp[2]; /* Représentation d'un octet */
+
+ static const char hexa_lower[] = "0123456789abcdef";
+ static const char hexa_upper[] = "0123456789ABCDEF";
+ static const char ff_lower[] = "ff";
+ static const char ff_upper[] = "FF";
+
+ /*
+ config = get_main_configuration();
+
+#ifndef NDEBUG
+ status = g_generic_config_get_value(config, MPK_HEX_UPPER_CASE, &upper_case);
+ assert(status);
+#else
+ g_generic_config_get_value(config, MPK_HEX_UPPER_CASE, &upper_case);
+#endif
+ */
+
+ upper_case = true;
+
+ if (upper_case)
+ {
+ hexa = hexa_upper;
+ ff = ff_upper;
+ }
+ else
+ {
+ hexa = hexa_lower;
+ ff = ff_lower;
+ }
+
+ /* Position physique */
+
+ init_vmpa(&pos, generator->bytes_per_line * index, VMPA_NO_VIRTUAL);
+
+ //g_buffer_line_fill_phys(line, HLC_PHYSICAL, MDS_32_BITS_UNSIGNED, &pos);
+
+ /* Contenu brut */
+
+ got = g_binary_content_compute_size(generator->content) - get_phy_addr(&pos);
+
+ if (got > generator->bytes_per_line)
+ got = generator->bytes_per_line;
+
+ raw = g_binary_content_get_raw_access(generator->content, &pos, got);
+
+ for (i = 0; i < got; i++)
+ {
+ /* Séparation ? */
+
+ if (i > 0)
+ {
+ if (i % 4 == 0)
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_NONE, "\t", 1, NULL, NULL);
+ else
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_NONE, " ", 1, NULL, NULL);
+ }
+
+ /* Binaire brut */
+
+ byte = raw[i];
+
+ if (byte == 0x00)
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_RAW_NULL, "00", 2, NULL, NULL);
+
+ else if (byte == 0xff)
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_RAW_FULL, ff, 2, NULL, NULL);
+
+ else
+ {
+ tmp[1] = hexa[byte & 0xf];
+ tmp[0] = hexa[(byte >> 4) & 0xf];
+
+ if (isgraph(byte) || byte == ' ')
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_RAW_PRINTABLE, tmp, 2, NULL, NULL);
+ else
+ g_buffer_line_append_text(line, HCO_COUNT + 0, TRT_RAW_NOT_PRINTABLE, tmp, 2, NULL, NULL);
+
+ }
+
+ /* Représentation humaine ? */
+
+ if (isgraph(byte) || byte == ' ')
+ g_buffer_line_append_text(line, HCO_COUNT + 1, TRT_CHR_PRINTABLE, (char *)raw + i, 1, NULL, NULL);
+ else
+ g_buffer_line_append_text(line, HCO_COUNT + 1, TRT_CHR_NOT_PRINTABLE, ".", 1, NULL, NULL);
+
+ }
+
+}
+
+
+
+
+
+
+
+#if 0
#ifdef INCLUDE_GTK_SUPPORT
@@ -538,9 +935,9 @@ static void g_hex_generator_print(GHexGenerator *generator, GBufferLine *line, s
if (i > 0)
{
if (i % 4 == 0)
- g_buffer_line_append_text(line, HLC_BINARY, "\t", 1, RTT_RAW, NULL);
+ g_buffer_line_append_text(line, HCO_COUNT + 0, "\t", 1, RTT_RAW, NULL);
else
- g_buffer_line_append_text(line, HLC_BINARY, " ", 1, RTT_RAW, NULL);
+ g_buffer_line_append_text(line, HCO_COUNT + 0, " ", 1, RTT_RAW, NULL);
}
/* Binaire brut */
@@ -548,17 +945,17 @@ static void g_hex_generator_print(GHexGenerator *generator, GBufferLine *line, s
byte = raw[i];
if (byte == 0x00)
- g_buffer_line_append_text(line, HLC_BINARY, "00", 2, RTT_RAW_NULL, NULL);
+ g_buffer_line_append_text(line, HCO_COUNT + 0, "00", 2, RTT_RAW_NULL, NULL);
else if (byte == 0xff)
- g_buffer_line_append_text(line, HLC_BINARY, ff, 2, RTT_RAW_FULL, NULL);
+ g_buffer_line_append_text(line, HCO_COUNT + 0, ff, 2, RTT_RAW_FULL, NULL);
else
{
tmp[1] = hexa[byte & 0xf];
tmp[0] = hexa[(byte >> 4) & 0xf];
- g_buffer_line_append_text(line, HLC_BINARY, tmp, 2, RTT_RAW, NULL);
+ g_buffer_line_append_text(line, HCO_COUNT + 0, tmp, 2, RTT_RAW, NULL);
}
@@ -574,30 +971,6 @@ static void g_hex_generator_print(GHexGenerator *generator, GBufferLine *line, s
}
-/******************************************************************************
-* *
-* Paramètres : generator = générateur à consulter. *
-* *
-* Description : Fournit le contenu associé au générateur de lignes hexa. *
-* *
-* Retour : Contenu dans lequel puise le générateur pour les lignes. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GBinContent *g_hex_generator_get_content(const GHexGenerator *generator)
-{
- GBinContent *result; /* Référence à retourner */
-
- result = generator->content;
-
- g_object_ref(G_OBJECT(result));
-
- return result;
-
-}
-
/******************************************************************************
* *
@@ -665,20 +1038,4 @@ bool g_hex_generator_auto_fit(GHexGenerator *generator, gint left, bool show_pos
}
-/******************************************************************************
-* *
-* Paramètres : generator = générateur à consulter. *
-* *
-* Description : Indique le nombre d'octets programmés constituer une ligne. *
-* *
-* Retour : Nombre d'octets représentés sur chaque ligne. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-phys_t g_hex_generator_get_bytes_per_line(const GHexGenerator *generator)
-{
- return generator->bytes_per_line;
-
-}
+#endif