[ghex/gtk4-port: 81/91] Try to fix signed vs unsigned mess




commit 0b35b043f2061aaee0d3f123947c61db87fe189a
Author: Logan Rathbone <poprocks gmail com>
Date:   Wed Aug 4 10:54:42 2021 -0400

    Try to fix signed vs unsigned mess
    
    This pertains to hex-document.* and gtkhex.* so far.

 meson.build        |   9 +++++
 src/gtkhex.c       | 108 +++++++++++++++++++++++++----------------------------
 src/gtkhex.h       |   2 +-
 src/hex-document.c | 107 +++++++++++++++++++++++++++-------------------------
 src/hex-document.h |  70 ++++++++++++++++------------------
 5 files changed, 151 insertions(+), 145 deletions(-)
---
diff --git a/meson.build b/meson.build
index f8bca0b9..cb70271b 100644
--- a/meson.build
+++ b/meson.build
@@ -26,6 +26,15 @@ ghex_iconsdir = join_paths(ghex_datadir, 'icons')
 ghex_root_dir = include_directories('.')
 ghex_po_dir = join_paths(meson.source_root(), 'po')
 
+# warning cflags
+warning_cflags = [
+  '-Wno-unused-variable',
+  '-Wno-unused-parameter'
+]
+c_compiler = meson.get_compiler('c')
+supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
+add_global_arguments(supported_warning_cflags, language : 'c')
+
 gnome = import('gnome')
 i18n = import('i18n')
 
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 6112fe5b..642d6da7 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -142,7 +142,7 @@ struct _GtkHex
        guint char_width, char_height;
        guint button;
 
-       guint cursor_pos;
+       int cursor_pos;
        GtkHex_Highlight selection;
        gint lower_nibble;
 
@@ -341,9 +341,9 @@ undo_action (GtkWidget *widget,
  * to cursor coordinates.
  */
 static void
-hex_to_pointer (GtkHex *gh, guint mx, guint my)
+hex_to_pointer (GtkHex *gh, int mx, int my)
 {
-       guint cx, cy, x;
+       int cx, cy, x;
        
        cy = gh->top_line + my/gh->char_height;
        
@@ -437,7 +437,7 @@ format_xbyte (GtkHex *gh, gint pos, gchar buf[2]) {
  * into displayable text in hex or ascii, respectively
  */
 gint
-format_xblock(GtkHex *gh, gchar *out, guint start, guint end)
+format_xblock(GtkHex *gh, gchar *out, int start, int end)
 {
        int i, j, low, high;
        guchar c;
@@ -456,8 +456,8 @@ format_xblock(GtkHex *gh, gchar *out, guint start, guint end)
        return j;
 }
 
-static gint
-format_ablock (GtkHex *gh, gchar *out, guint start, guint end)
+static int
+format_ablock (GtkHex *gh, char *out, int start, int end)
 {
        int i, j;
        guchar c;
@@ -476,10 +476,10 @@ format_ablock (GtkHex *gh, gchar *out, guint start, guint end)
  * get_[x|a]coords() translates offset from the beginning of
  * the block into x,y coordinates of the xdisp/adisp, respectively
  */
-static gint
-get_xcoords(GtkHex *gh, gint pos, gint *x, gint *y)
+static int
+get_xcoords(GtkHex *gh, int pos, int *x, int *y)
 {
-       gint cx, cy, spaces;
+       int cx, cy, spaces;
        
        if(gh->cpl == 0)
                return FALSE;
@@ -563,8 +563,8 @@ render_ac (GtkHex *gh,
        GdkRGBA fg_color;
        GtkStateFlags state;
        GtkStyleContext *context;
-       gint cx, cy;
-       static guchar c[2] = "\0\0";
+       int cx, cy;
+       static char c[2] = "\0\0";
        
        g_return_if_fail (gtk_widget_get_realized (gh->adisp));
 
@@ -624,8 +624,8 @@ render_xc (GtkHex *gh,
        GdkRGBA fg_color;
        GtkStateFlags state;
        GtkStyleContext *context;
-       gint cx, cy, i;
-       static guchar c[2];
+       int cx, cy, i;
+       static char c[2];
 
        g_return_if_fail (gtk_widget_get_realized (gh->xdisp));
 
@@ -952,7 +952,6 @@ render_hex_lines (GtkHex *gh,
 {
        GtkWidget *widget = gh->xdisp;
        GtkAllocation allocation;
-       GtkStateFlags state;
        GtkStyleContext *context;
        int cursor_line;
        int frm_len;
@@ -963,7 +962,6 @@ render_hex_lines (GtkHex *gh,
 
        hex_cpl = gtk_hex_layout_get_hex_cpl (GTK_HEX_LAYOUT(gh->layout_manager));
        context = gtk_widget_get_style_context (widget);
-       state = gtk_widget_get_state_flags (widget);
        cursor_line = gh->cursor_pos / gh->cpl - gh->top_line;
        gtk_widget_get_allocation (widget, &allocation);
 
@@ -979,10 +977,10 @@ render_hex_lines (GtkHex *gh,
 
        /* FIXME -  Maybe break this down/comment it to make it clearer?
         */
-       frm_len = format_xblock (gh, gh->disp_buffer,
+       frm_len = format_xblock (gh, (char *)gh->disp_buffer,
                        (gh->top_line + min_lines) * gh->cpl,
                        MIN( (gh->top_line + max_lines + 1) * gh->cpl,
-                               gh->document->file_size ));
+                               (int)gh->document->file_size ));
        
        for (int i = min_lines; i <= max_lines; i++)
        {
@@ -996,7 +994,7 @@ render_hex_lines (GtkHex *gh,
                /* Set pango layout to the line of hex to render. */
 
                pango_layout_set_text (gh->xlayout,
-                               gh->disp_buffer + (i - min_lines) * hex_cpl,
+                               (char *)gh->disp_buffer + (i - min_lines) * hex_cpl,
                                MIN(hex_cpl, tmp));
 
                gtk_render_layout (context, cr,
@@ -1020,16 +1018,14 @@ render_ascii_lines (GtkHex *gh,
 {
        GtkWidget *widget = gh->adisp;
        GtkAllocation allocation;
-       GtkStateFlags state;
        GtkStyleContext *context;
        int frm_len;
-       guint cursor_line;
+       int cursor_line;
 
        g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET(gh)));
        g_return_if_fail (gh->cpl);
 
        context = gtk_widget_get_style_context (widget);
-       state = gtk_widget_get_state_flags (widget);
        cursor_line = gh->cursor_pos / gh->cpl - gh->top_line;
        gtk_widget_get_allocation(widget, &allocation);
 
@@ -1043,10 +1039,10 @@ render_ascii_lines (GtkHex *gh,
        max_lines = MIN(max_lines, gh->vis_lines);
        max_lines = MIN(max_lines, gh->lines);
        
-       frm_len = format_ablock (gh, gh->disp_buffer,
+       frm_len = format_ablock (gh, (char *)gh->disp_buffer,
                        (gh->top_line + min_lines) * gh->cpl,
                        MIN( (gh->top_line + max_lines + 1) * gh->cpl,
-                               gh->document->file_size ));
+                               (int)gh->document->file_size ));
        
        for (int i = min_lines; i <= max_lines; i++)
        {
@@ -1057,7 +1053,7 @@ render_ascii_lines (GtkHex *gh,
                render_ascii_highlights (gh, cr, i);
 
                pango_layout_set_text (gh->alayout,
-                               gh->disp_buffer + (i - min_lines) * gh->cpl,
+                               (char *)gh->disp_buffer + (i - min_lines) * gh->cpl,
                                MIN(gh->cpl, tmp));
 
                gtk_render_layout (context, cr,
@@ -1083,7 +1079,6 @@ render_offsets (GtkHex *gh,
        GtkWidget *widget = gh->offsets;
        GdkRGBA fg_color;
        GtkAllocation allocation;
-       GtkStateFlags state;
        GtkStyleContext *context;
        /* offset chars (8) + 1 (null terminator) */
        char offstr[9];
@@ -1091,7 +1086,6 @@ render_offsets (GtkHex *gh,
        g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (gh)));
 
        context = gtk_widget_get_style_context (widget);
-       state = gtk_widget_get_state_flags (widget);
 
        gtk_widget_get_allocation (widget, &allocation);
 
@@ -1279,7 +1273,7 @@ scroll_timeout_handler(GtkHex *gh)
                gtk_hex_set_cursor (gh, MAX(0, (int)(gh->cursor_pos - gh->cpl)));
        }
        else if (gh->scroll_dir > 0) {
-               gtk_hex_set_cursor(gh, MIN(gh->document->file_size - 1,
+               gtk_hex_set_cursor(gh, MIN((int)gh->document->file_size - 1,
                                                gh->cursor_pos + gh->cpl));
        }
        return TRUE;
@@ -1660,7 +1654,7 @@ key_press_cb (GtkEventControllerKey *controller,
                }
                break;
        case GDK_KEY_Delete:
-               if(gh->cursor_pos < gh->document->file_size) {
+               if(gh->cursor_pos < (int)gh->document->file_size) {
                        hex_document_set_data(gh->document, gh->cursor_pos,
                                                                  0, 1, NULL, TRUE);
                        gtk_hex_set_cursor(gh, gh->cursor_pos);
@@ -1696,7 +1690,7 @@ key_press_cb (GtkEventControllerKey *controller,
                                }
                                break;
                        case GDK_KEY_Right:
-                               if(gh->cursor_pos >= gh->document->file_size)
+                               if(gh->cursor_pos >= (int)gh->document->file_size)
                                        break;
                                if(!(state & GDK_SHIFT_MASK)) {
                                        gh->lower_nibble = !gh->lower_nibble;
@@ -1832,8 +1826,8 @@ hide_offsets_widget(GtkHex *gh)
 static void gtk_hex_real_data_changed (GtkHex *gh, gpointer data)
 {
        HexChangeData *change_data = (HexChangeData *)data;
-       gint start_line, end_line;
-       guint lines;
+       int start_line, end_line;
+       int lines;
 
        if(gh->cpl == 0)
                return;
@@ -2004,10 +1998,10 @@ gtk_hex_compare_data (GtkHex *gh, guchar *cmp, guint pos, gint len)
 
 static gboolean
 gtk_hex_find_limited (GtkHex *gh, gchar *find, int findlen,
-               guint lower, guint upper,
-               guint *found)
+               int lower, int upper,
+               int *found)
 {
-       guint pos = lower;
+       int pos = lower;
 
        while (pos < upper)
        {
@@ -2028,11 +2022,11 @@ static void
 gtk_hex_update_auto_highlight(GtkHex *gh, GtkHex_AutoHighlight *ahl,
                gboolean delete, gboolean add)
 {
-       gint del_min, del_max;
-       gint add_min, add_max;
-       guint foundpos = -1;
-       gint prev_min = ahl->view_min;
-       gint prev_max = ahl->view_max;
+       int del_min, del_max;
+       int add_min, add_max;
+       int foundpos = -1;
+       int prev_min = ahl->view_min;
+       int prev_max = ahl->view_max;
        GtkHex_Highlight *cur;
 
        ahl->view_min = gh->top_line * gh->cpl;
@@ -2880,8 +2874,8 @@ gtk_hex_clear_selection(GtkHex *gh)
 void
 gtk_hex_delete_selection(GtkHex *gh)
 {
-       guint start;
-       guint end;
+       int start;
+       int end;
 
        start = MIN(gh->selection.start, gh->selection.end);
        end = MAX(gh->selection.start, gh->selection.end);
@@ -2928,16 +2922,16 @@ gtk_hex_set_nibble (GtkHex *gh, gint lower_nibble)
  * moves cursor to byte index
  */
 void
-gtk_hex_set_cursor(GtkHex *gh, gint index) {
-       guint y;
-       guint old_pos = gh->cursor_pos;
+gtk_hex_set_cursor(GtkHex *gh, int index) {
+       int y;
+       int old_pos = gh->cursor_pos;
 
        g_return_if_fail(gh != NULL);
        g_return_if_fail(GTK_IS_HEX(gh));
 
-       if ((index >= 0) && (index <= gh->document->file_size))
+       if ((index >= 0) && (index <= (int)gh->document->file_size))
        {
-               if(!gh->insert && index == gh->document->file_size)
+               if(!gh->insert && index == (int)gh->document->file_size)
                        index--;
 
                index = MAX(index, 0);
@@ -2960,7 +2954,7 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
                        gtk_adjustment_set_value(gh->adj, y);
                }      
 
-               if(index == gh->document->file_size)
+               if(index == (int)gh->document->file_size)
                        gh->lower_nibble = FALSE;
 
                if(gh->selecting) {
@@ -2988,10 +2982,10 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
  * currently visible part)
  */
 void
-gtk_hex_set_cursor_xy (GtkHex *gh, gint x, gint y)
+gtk_hex_set_cursor_xy (GtkHex *gh, int x, int y)
 {
-       gint cp;
-       guint old_pos = gh->cursor_pos;
+       int cp;
+       int old_pos = gh->cursor_pos;
 
        g_return_if_fail(gh != NULL);
        g_return_if_fail(GTK_IS_HEX(gh));
@@ -2999,9 +2993,9 @@ gtk_hex_set_cursor_xy (GtkHex *gh, gint x, gint y)
        cp = y*gh->cpl + x;
 
        if ((y >= 0) && (y < gh->lines) && (x >= 0) &&
-          (x < gh->cpl) && (cp <= gh->document->file_size))
+          (x < gh->cpl) && (cp <= (int)gh->document->file_size))
        {
-               if (!gh->insert && cp == gh->document->file_size)
+               if (!gh->insert && cp == (int)gh->document->file_size)
                        cp--;
 
                cp = MAX(cp, 0);
@@ -3055,12 +3049,12 @@ gtk_hex_get_cursor(GtkHex *gh)
  * returns value of the byte at position offset
  */
 guchar
-gtk_hex_get_byte (GtkHex *gh, guint offset)
+gtk_hex_get_byte (GtkHex *gh, int offset)
 {
        g_return_val_if_fail(gh != NULL, 0);
        g_return_val_if_fail(GTK_IS_HEX(gh), 0);
 
-       if((offset >= 0) && (offset < gh->document->file_size))
+       if((offset >= 0) && (offset < (int)gh->document->file_size))
                return hex_document_get_byte(gh->document, offset);
 
        return 0;
@@ -3122,8 +3116,8 @@ gtk_hex_set_insert_mode (GtkHex *gh, gboolean insert)
        gh->insert = insert;
 
        if(!gh->insert && gh->cursor_pos > 0) {
-               if(gh->cursor_pos >= gh->document->file_size)
-                       gh->cursor_pos = gh->document->file_size - 1;
+               if(gh->cursor_pos >= (int)gh->document->file_size)
+                       gh->cursor_pos = (int)gh->document->file_size - 1;
        }
 }
 
@@ -3134,7 +3128,7 @@ gtk_hex_insert_autohighlight(GtkHex *gh,
 {
        GtkHex_AutoHighlight *new = g_malloc0(sizeof(GtkHex_AutoHighlight));
 
-       new->search_string = g_memdup(search, len);
+       new->search_string = g_memdup2 (search, len);
        new->search_len = len;
 
        new->highlights = NULL;
diff --git a/src/gtkhex.h b/src/gtkhex.h
index 48bb1ed1..962af2a9 100644
--- a/src/gtkhex.h
+++ b/src/gtkhex.h
@@ -64,7 +64,7 @@ void gtk_hex_set_cursor_xy(GtkHex *, gint, gint);
 void gtk_hex_set_nibble(GtkHex *, gint);
 
 guint gtk_hex_get_cursor(GtkHex *);
-guchar gtk_hex_get_byte(GtkHex *, guint);
+guchar gtk_hex_get_byte(GtkHex *, int);
 
 void gtk_hex_set_group_type(GtkHex *, guint);
 guint gtk_hex_get_group_type (GtkHex *gh);
diff --git a/src/hex-document.c b/src/hex-document.c
index 22506517..609bb7e6 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -50,8 +50,8 @@ static void hex_document_real_changed   (HexDocument *doc,
 static void hex_document_real_redo      (HexDocument *doc);
 static void hex_document_real_undo      (HexDocument *doc);
 static void move_gap_to                 (HexDocument *doc,
-                                                                                guint offset,
-                                                                            gint min_size);
+                                                                                int offset,
+                                                                            int min_size);
 static void free_stack                  (GList *stack);
 static gint undo_stack_push             (HexDocument *doc,
                                                                             HexChangeData *change_data);
@@ -220,12 +220,12 @@ get_document_attributes(HexDocument *doc)
 
 
 static void
-move_gap_to(HexDocument *doc, guint offset, gint min_size)
+move_gap_to(HexDocument *doc, int offset, int min_size)
 {
-       guchar *tmp, *buf_ptr, *tmp_ptr;
+       char *tmp, *buf_ptr, *tmp_ptr;
 
        if(doc->gap_size < min_size) {
-               tmp = g_malloc(sizeof(guchar)*doc->file_size);
+               tmp = g_malloc(doc->file_size);
                buf_ptr = doc->buffer;
                tmp_ptr = tmp;
                while(buf_ptr < doc->gap_pos)
@@ -236,7 +236,7 @@ move_gap_to(HexDocument *doc, guint offset, gint min_size)
 
                doc->gap_size = MAX(min_size, 32);
                doc->buffer_size = doc->file_size + doc->gap_size;
-               doc->buffer = g_realloc(doc->buffer, sizeof(guchar)*doc->buffer_size);
+               doc->buffer = g_realloc(doc->buffer, doc->buffer_size);
                doc->gap_pos = doc->buffer + offset;
 
                buf_ptr = doc->buffer;
@@ -456,7 +456,7 @@ hex_document_new()
        doc->gap_size = 100;
        doc->file_size = 0;
        doc->buffer_size = doc->file_size + doc->gap_size;
-       doc->gap_pos = doc->buffer = (guchar *)g_malloc(doc->buffer_size);
+       doc->gap_pos = doc->buffer = g_malloc(doc->buffer_size);
 
        doc->path_end = g_strdup(_("New document"));
 
@@ -473,11 +473,11 @@ hex_document_new_from_file(const gchar *name)
        doc = HEX_DOCUMENT (g_object_new (hex_document_get_type(), NULL));
        g_return_val_if_fail (doc != NULL, NULL);
 
-       doc->file_name = (gchar *)g_strdup(name);
+       doc->file_name = g_strdup(name);
        if(get_document_attributes(doc)) {
                doc->gap_size = 100;
                doc->buffer_size = doc->file_size + doc->gap_size;
-               doc->buffer = (guchar *)g_malloc(doc->buffer_size);
+               doc->buffer = g_malloc(doc->buffer_size);
 
                /* find the start of the filename without path */
                path_end = g_path_get_basename (doc->file_name);
@@ -494,8 +494,8 @@ hex_document_new_from_file(const gchar *name)
        return NULL;
 }
 
-guchar
-hex_document_get_byte(HexDocument *doc, guint offset)
+char
+hex_document_get_byte(HexDocument *doc, int offset)
 {
        if(offset < doc->file_size) {
                if(doc->gap_pos <= doc->buffer + offset)
@@ -506,18 +506,18 @@ hex_document_get_byte(HexDocument *doc, guint offset)
                return 0;
 }
 
-guchar *
-hex_document_get_data(HexDocument *doc, guint offset, guint len)
+char *
+hex_document_get_data(HexDocument *doc, int offset, int len)
 {
-       guchar *ptr, *data, *dptr;
-       guint i;
+       char *ptr, *data, *dptr;
+       int i;
 
        ptr = doc->buffer + offset;
 
        if (ptr >= doc->gap_pos)
                ptr += doc->gap_size;
 
-       dptr = data = g_malloc(len * sizeof(guchar));
+       dptr = data = g_malloc(len);
 
        for (i = 0; i < len; ++i) {
                if (ptr >= doc->gap_pos && ptr < doc->gap_pos + doc->gap_size)
@@ -530,7 +530,7 @@ hex_document_get_data(HexDocument *doc, guint offset, guint len)
 }
 
 void
-hex_document_set_nibble(HexDocument *doc, guchar val, guint offset,
+hex_document_set_nibble(HexDocument *doc, char val, int offset,
                                                gboolean lower_nibble, gboolean insert,
                                                gboolean undoable)
 {
@@ -570,7 +570,7 @@ hex_document_set_nibble(HexDocument *doc, guchar val, guint offset,
 }
 
 void
-hex_document_set_byte(HexDocument *doc, guchar val, guint offset,
+hex_document_set_byte(HexDocument *doc, char val, int offset,
                                          gboolean insert, gboolean undoable)
 {
        static HexChangeData change_data;
@@ -604,11 +604,11 @@ hex_document_set_byte(HexDocument *doc, guchar val, guint offset,
 }
 
 void
-hex_document_set_data(HexDocument *doc, guint offset, guint len,
-                                         guint rep_len, guchar *data, gboolean undoable)
+hex_document_set_data (HexDocument *doc, int offset, int len,
+                                         int rep_len, char *data, gboolean undoable)
 {
-       guint i;
-       guchar *ptr;
+       int i;
+       char *ptr;
        static HexChangeData change_data;
 
        if(offset <= doc->file_size) {
@@ -673,6 +673,7 @@ hex_document_read(HexDocument *doc)
 {
        FILE *file;
        static HexChangeData change_data;
+       int fread_as_int;
 
        if(doc->file_name == NULL)
                return FALSE;
@@ -684,10 +685,13 @@ hex_document_read(HexDocument *doc)
                return FALSE;
 
        doc->gap_size = doc->buffer_size - doc->file_size;
-       if(fread(doc->buffer + doc->gap_size, 1, doc->file_size, file) != doc->file_size)
+
+       fread_as_int = fread(doc->buffer + doc->gap_size, 1, doc->file_size, file);
+       if (fread_as_int != doc->file_size)
        {
                g_return_val_if_reached(FALSE);
        }
+
        doc->gap_pos = doc->buffer;
        fclose(file);
        undo_stack_free(doc);
@@ -703,13 +707,13 @@ hex_document_read(HexDocument *doc)
 gint
 hex_document_write_to_file(HexDocument *doc, FILE *file)
 {
-       gint ret = TRUE;
-       size_t exp_len;
+       int ret = TRUE;
+       int exp_len;
 
        if(doc->gap_pos > doc->buffer) {
                exp_len = MIN(doc->file_size, doc->gap_pos - doc->buffer);
                ret = fwrite(doc->buffer, 1, exp_len, file);
-               ret = (ret == exp_len)?TRUE:FALSE;
+               ret = (ret == exp_len) ? TRUE : FALSE;
        }
        if(doc->gap_pos < doc->buffer + doc->file_size) {
                exp_len = doc->file_size - (size_t)(doc->gap_pos - doc->buffer);
@@ -754,7 +758,7 @@ hex_document_has_changed(HexDocument *doc)
 }
 
 void
-hex_document_set_max_undo(HexDocument *doc, guint max_undo)
+hex_document_set_max_undo(HexDocument *doc, int max_undo)
 {
        if(doc->undo_max != max_undo) {
                if(doc->undo_max > max_undo)
@@ -772,10 +776,10 @@ ignore_dialog_cb(GtkDialog *dialog, gpointer user_data)
        return TRUE;
 }
 
-gint
-hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
-                                                guint start, guint end, guint cpl, guint lpp,
-                                                guint cpw)
+int
+hex_document_export_html (HexDocument *doc, char *html_path, char *base_name,
+                                                int start, int end, int cpl, int lpp,
+                                                int cpw)
 {
        GtkWidget *progress_dialog, *progress_bar;
        FILE *file;
@@ -959,14 +963,15 @@ hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
        return TRUE;
 }
 
-gint
-hex_document_compare_data(HexDocument *doc, guchar *s2, gint pos, gint len)
+int
+hex_document_compare_data(HexDocument *doc, char *s2, int pos, int len)
 {
-       guchar c1;
-       guint i;
+       char c1;
 
-       for(i = 0; i < len; i++, s2++) {
+       for (int i = 0; i < len; i++, s2++)
+       {
                c1 = hex_document_get_byte(doc, pos + i);
+
                if(c1 != (*s2))
                        return (c1 - (*s2));
        }
@@ -974,15 +979,17 @@ hex_document_compare_data(HexDocument *doc, guchar *s2, gint pos, gint len)
        return 0;
 }
 
-gint
-hex_document_find_forward(HexDocument *doc, guint start, guchar *what,
-                                                 gint len, guint *found)
+int
+hex_document_find_forward (HexDocument *doc, int start, char *what,
+                                                 int len, int *found)
 {
-       guint pos;
+       int pos;
        
        pos = start;
-       while(pos < doc->file_size) {
-               if(hex_document_compare_data(doc, what, pos, len) == 0) {
+       while (pos < doc->file_size)
+       {
+               if (hex_document_compare_data(doc, what, pos, len) == 0)
+               {
                        *found = pos;
                        return TRUE;
                }
@@ -993,7 +1000,7 @@ hex_document_find_forward(HexDocument *doc, guint start, guchar *what,
 }
 
 gint
-hex_document_find_backward(HexDocument *doc, guint start, guchar *what,
+hex_document_find_backward(HexDocument *doc, guint start, char *what,
                                                   gint len, guint *found)
 {
        guint pos;
@@ -1029,11 +1036,11 @@ static void
 hex_document_real_undo(HexDocument *doc)
 {
        HexChangeData *cd;
-       gint len;
-       guchar *rep_data;
-       gchar c_val;
+       int len;
+       char *rep_data;
+       char c_val;
 
-       cd = (HexChangeData *)doc->undo_top->data;
+       cd = doc->undo_top->data;
 
        switch(cd->type) {
        case HEX_CHANGE_BYTE:
@@ -1086,9 +1093,9 @@ static void
 hex_document_real_redo(HexDocument *doc)
 {
        HexChangeData *cd;
-       gint len;
-       guchar *rep_data;
-       gchar c_val;
+       int len;
+       char *rep_data;
+       char c_val;
 
        undo_stack_ascend(doc);
 
diff --git a/src/hex-document.h b/src/hex-document.h
index b4158113..7e7107ba 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -56,14 +56,14 @@ typedef enum {
 
 struct _HexChangeData
 {
-       guint start, end;
+       int start, end;
        /* length to replace (overwrite); (0 to insert without overwriting) */
-       guint rep_len;
+       int rep_len;
        gboolean lower_nibble;
        gboolean insert;
        HexChangeType type;
-       gchar *v_string;
-       gchar v_byte;
+       char *v_string;
+       char v_byte;
 };
 
 struct _HexDocument
@@ -72,21 +72,21 @@ struct _HexDocument
 
        GList *views;      /* a list of GtkHex widgets showing this document */
        
-       gchar *file_name;
-       gchar *path_end;
+       char *file_name;
+       char *path_end;
 
-       guchar *buffer;    /* data buffer */
-       guchar *gap_pos;   /* pointer to the start of insertion gap */
-       gint gap_size;     /* insertion gap size */
-       guint buffer_size; /* buffer size = file size + gap size */
-       guint file_size;   /* real file size */
+       char *buffer;    /* data buffer */
+       char *gap_pos;   /* pointer to the start of insertion gap */
+       int gap_size;     /* insertion gap size */
+       int buffer_size; /* buffer size = file size + gap size */
+       int file_size;   /* real file size */
 
        gboolean changed;
 
        GList *undo_stack; /* stack base */
        GList *undo_top;   /* top of the stack (for redo) */
-       guint undo_depth;  /* number of els on stack */
-       guint undo_max;    /* max undo depth */
+       int undo_depth;  /* number of els on stack */
+       int undo_max;    /* max undo depth */
 };
 
 struct _HexDocumentClass
@@ -103,38 +103,34 @@ struct _HexDocumentClass
 
 GType       hex_document_get_type(void);
 HexDocument *hex_document_new(void);
-HexDocument *hex_document_new_from_file(const gchar *name);
-void        hex_document_set_data(HexDocument *doc, guint offset,
-               guint len, guint rep_len, guchar *data,
-               gboolean undoable);
-void        hex_document_set_byte(HexDocument *doc, guchar val, guint offset,
+HexDocument *hex_document_new_from_file(const char *name);
+void        hex_document_set_data(HexDocument *doc, int offset,
+               int len, int rep_len, char *data, gboolean undoable);
+void        hex_document_set_byte(HexDocument *doc, char val, int offset,
                gboolean insert, gboolean undoable);
-void        hex_document_set_nibble(HexDocument *doc, guchar val,
-               guint offset, gboolean lower_nibble,
-               gboolean insert, gboolean undoable);
-guchar      hex_document_get_byte(HexDocument *doc, guint offset);
-guchar      *hex_document_get_data(HexDocument *doc, guint offset, guint len);
+void        hex_document_set_nibble(HexDocument *doc, char val,
+               int offset, gboolean lower_nibble, gboolean insert, gboolean undoable);
+char        hex_document_get_byte(HexDocument *doc, int offset);
+char        *hex_document_get_data(HexDocument *doc, int offset, int len);
 void        hex_document_delete_data(HexDocument *doc, guint offset,
                guint len, gboolean undoable);
-gint        hex_document_read(HexDocument *doc);
-gint        hex_document_write(HexDocument *doc);
-gint        hex_document_write_to_file(HexDocument *doc, FILE *file);
-gint        hex_document_export_html(HexDocument *doc,
-               gchar *html_path, gchar *base_name,
-               guint start, guint end,
-               guint cpl, guint lpp, guint cpw);
+int        hex_document_read(HexDocument *doc);
+int        hex_document_write(HexDocument *doc);
+int        hex_document_write_to_file(HexDocument *doc, FILE *file);
+int        hex_document_export_html(HexDocument *doc, char *html_path,
+               char *base_name, int start, int end, int cpl, int lpp, int cpw);
 gboolean    hex_document_has_changed(HexDocument *doc);
 void        hex_document_changed(HexDocument *doc, gpointer change_data,
                gboolean push_undo);
-void        hex_document_set_max_undo(HexDocument *doc, guint max_undo);
+void        hex_document_set_max_undo(HexDocument *doc, int max_undo);
 gboolean    hex_document_undo(HexDocument *doc);
 gboolean    hex_document_redo(HexDocument *doc);
-gint        hex_document_compare_data(HexDocument *doc, guchar *s2,
-               gint pos, gint len);
-gint        hex_document_find_forward(HexDocument *doc, guint start,
-               guchar *what, gint len, guint *found);
-gint        hex_document_find_backward(HexDocument *doc, guint start,
-               guchar *what, gint len, guint *found);
+int        hex_document_compare_data(HexDocument *doc, char *s2,
+               int pos, int len);
+int        hex_document_find_forward(HexDocument *doc, int start,
+               char *what, int len, int *found);
+int        hex_document_find_backward(HexDocument *doc, guint start,
+               char *what, int len, guint *found);
 void        hex_document_remove_view(HexDocument *doc, GtkWidget *view);
 GtkWidget   *hex_document_add_view(HexDocument *doc);
 const GList *hex_document_get_list(void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]