From 7d3a242132eedadbcb96bead6dbed64729d11aaf Mon Sep 17 00:00:00 2001 From: John Tytgat Date: Sat, 14 Aug 2004 12:57:02 +0000 Subject: [project @ 2004-08-14 12:57:00 by joty] Using more stddef.h types. svn path=/import/netsurf/; revision=1230 --- debug/fontd.c | 11 ++++----- desktop/browser.c | 15 +++++++------ gtk/font_pango.c | 10 ++++----- render/box.c | 65 ++++++++++++++++++++++++++++------------------------- render/box.h | 7 +++--- render/font.h | 15 +++++++------ render/html.c | 4 ++-- render/html.h | 2 +- render/layout.c | 6 +++-- riscos/font.c | 17 +++++++------- riscos/gui.h | 1 + riscos/htmlredraw.c | 13 +++++------ riscos/print.c | 4 ++-- riscos/save_draw.c | 2 +- 14 files changed, 91 insertions(+), 81 deletions(-) diff --git a/debug/fontd.c b/debug/fontd.c index 1b9ba871c..2fc3ec93b 100644 --- a/debug/fontd.c +++ b/debug/fontd.c @@ -28,7 +28,8 @@ static void font_close(struct font_data *data); * functions */ -unsigned long nsfont_width(struct font_data *font, const char * text, unsigned int length) +unsigned long nsfont_width(struct font_data *font, const char * text, + size_t length) { int width; @@ -41,7 +42,7 @@ unsigned long nsfont_width(struct font_data *font, const char * text, unsigned i } void nsfont_position_in_string(struct font_data* font, const char* text, - unsigned int length, unsigned long x, int* char_offset, int* pixel_offset) + size_t length, unsigned long x, int* char_offset, int* pixel_offset) { assert(font != 0 && text != 0); @@ -137,8 +138,8 @@ void font_close(struct font_data *data) } -char *nsfont_split(struct font_data *data, const char * text, unsigned int length, - unsigned int width, unsigned int *used_width) +char *nsfont_split(struct font_data *data, const char * text, + size_t length, unsigned int width, unsigned int *used_width) { int i = width / 10; @@ -155,7 +156,7 @@ char *nsfont_split(struct font_data *data, const char * text, unsigned int lengt void nsfont_paint(struct font_data *data, const char *text, - int xpos, int ypos, void *trfm, int length) + size_t length, int xpos, int ypos, void *trfm) { assert(data != NULL); assert(text != NULL); diff --git a/desktop/browser.c b/desktop/browser.c index e2f30dfba..65ba0b050 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -383,7 +383,7 @@ void browser_window_update(struct browser_window *bw, if (bw->current_content->title != NULL && (title_local_enc = cnv_str_local_enc(bw->current_content->title)) != NULL) { gui_window_set_title(bw->window, title_local_enc); - free(title_local_enc); + free((void *)title_local_enc); } else gui_window_set_title(bw->window, bw->current_content->url); @@ -936,6 +936,7 @@ void browser_window_textarea_callback(struct browser_window *bw, struct box *text_box = textarea->gadget->caret_text_box; struct box *new_br, *new_text, *t; struct box *prev; + /** \todo: consider changing the following 2 types in size_t */ int char_offset = textarea->gadget->caret_box_offset; int pixel_offset = textarea->gadget->caret_pixel_offset; int dy; @@ -1154,7 +1155,7 @@ void browser_window_textarea_callback(struct browser_window *bw, textarea->height = height; } - if (text_box->length < (unsigned int)char_offset) { + if (text_box->length < (size_t)char_offset) { /* the text box has been split and the caret is in the * second part */ char_offset -= (text_box->length + 1); /* +1 for the space */ @@ -1327,8 +1328,8 @@ void browser_window_input_callback(struct browser_window *bw, box_offset += utf8keySize; free((void *)utf8key); - text_box->width = nsfont_width(text_box->font, text_box->text, - (unsigned int)text_box->length); + text_box->width = nsfont_width(text_box->font, + text_box->text, text_box->length); changed = true; } else if (key == 8 || key == 127) { @@ -1362,8 +1363,8 @@ void browser_window_input_callback(struct browser_window *bw, text_box->length -= prev_offset - box_offset; text_box->text[text_box->length] = 0; - text_box->width = nsfont_width(text_box->font, text_box->text, - (unsigned int)text_box->length); + text_box->width = nsfont_width(text_box->font, + text_box->text, text_box->length); changed = true; @@ -1462,7 +1463,7 @@ void browser_window_input_callback(struct browser_window *bw, } pixel_offset = nsfont_width(text_box->font, text_box->text, - (unsigned int)box_offset); + box_offset); dx = text_box->x; text_box->x = 0; if (input->width < text_box->width && input->width / 2 < pixel_offset) { diff --git a/gtk/font_pango.c b/gtk/font_pango.c index 22fbc6024..16408530f 100644 --- a/gtk/font_pango.c +++ b/gtk/font_pango.c @@ -70,7 +70,7 @@ struct font_data *nsfont_open(struct font_set *set, struct css_style *style) data->id = fontdesc; data->size = size; - data->space_width = nsfont_width(data, " ", 1); + data->space_width = nsfont_width(data, " ", sizeof(" ")-1); return data; } @@ -82,7 +82,7 @@ void nsfont_free_set(struct font_set *set) unsigned long nsfont_width(struct font_data *font, const char *text, - unsigned int length) + size_t length) { int width; PangoContext *context; @@ -108,7 +108,7 @@ unsigned long nsfont_width(struct font_data *font, const char *text, void nsfont_position_in_string(struct font_data *font, const char *text, - unsigned int length, unsigned long x, int *char_offset, + size_t length, unsigned long x, int *char_offset, int *pixel_offset) { int index; @@ -134,8 +134,8 @@ void nsfont_position_in_string(struct font_data *font, const char *text, } -char *nsfont_split(struct font_data *font, const char *text, unsigned int length, - unsigned int width, unsigned int *used_width) +char *nsfont_split(struct font_data *font, const char *text, + size_t length, unsigned int width, unsigned int *used_width) { int index = length; int x_pos; diff --git a/render/box.c b/render/box.c index 95224ec2a..f248f3d62 100644 --- a/render/box.c +++ b/render/box.c @@ -195,46 +195,51 @@ void box_add_child(struct box * parent, struct box * child) */ struct box * box_create(struct css_style * style, - char *href, char *title, char *id, pool box_pool) + const char *href, const char *title, const char *id, + pool box_pool) { unsigned int i; - struct box *box = pool_alloc(box_pool, sizeof (struct box)); - assert(box); + struct box *box; + + if ((box = pool_alloc(box_pool, sizeof (struct box))) == NULL) + return NULL; box->type = BOX_INLINE; box->style = style; + box->x = box->y = 0; box->width = UNKNOWN_WIDTH; + box->height = 0; + box->descendant_x0 = box->descendant_y0 = 0; + box->descendant_x1 = box->descendant_y1 = 0; + for (i = 0; i != 4; i++) + box->margin[i] = box->padding[i] = box->border[i] = 0; + box->min_width = 0; box->max_width = UNKNOWN_MAX_WIDTH; - box->href = href ? xstrdup(href) : 0; - box->title = title ? xstrdup(title) : 0; - box->columns = 1; - box->rows = 1; - box->text = 0; + box->text = NULL; + box->length = 0; box->space = 0; box->clone = 0; box->style_clone = 0; - box->length = 0; + box->href = href ? xstrdup(href) : NULL; + box->title = title ? xstrdup(title) : NULL; + box->columns = 1; + box->rows = 1; box->start_column = 0; - box->next = 0; - box->prev = 0; - box->children = 0; - box->last = 0; - box->parent = 0; - box->float_children = 0; - box->next_float = 0; - box->col = 0; - box->font = 0; - box->gadget = 0; - box->usemap = 0; - box->id = id ? xstrdup(id) : 0; - box->background = 0; - box->object = 0; - box->object_params = 0; - box->x = box->y = 0; - box->height = 0; - for (i = 0; i != 4; i++) - box->margin[i] = box->padding[i] = box->border[i] = 0; - box->descendant_x0 = box->descendant_y0 = 0; - box->descendant_x1 = box->descendant_y1 = 0; + box->next = NULL; + box->prev = NULL; + box->children = NULL; + box->last = NULL; + box->parent = NULL; + box->float_children = NULL; + box->next_float = NULL; + box->col = NULL; + box->font = NULL; + box->gadget = NULL; + box->usemap = NULL; + box->id = id ? xstrdup(id) : NULL; + box->background = NULL; + box->object = NULL; + box->object_params = NULL; + return box; } diff --git a/render/box.h b/render/box.h index bb493a323..5b6427bc6 100644 --- a/render/box.h +++ b/render/box.h @@ -159,8 +159,8 @@ struct box { int min_width; int max_width; /**< Width that would be taken with no line breaks. */ - char *text; /**< Text, or 0 if none. Unterminated. */ - unsigned int length; /**< Length of text. */ + char *text; /**< Text, or 0 if none. Unterminated. */ + size_t length; /**< Length of text. */ /** Text is followed by a space. */ unsigned int space : 1; @@ -234,7 +234,8 @@ struct column { void xml_to_box(xmlNode *n, struct content *c); void box_dump(struct box * box, unsigned int depth); struct box * box_create(struct css_style * style, - char *href, char *title, char *id, pool box_pool); + const char *href, const char *title, + const char *id, pool box_pool); void box_add_child(struct box * parent, struct box * child); void box_insert_sibling(struct box *box, struct box *new_box); void box_free(struct box *box); diff --git a/render/font.h b/render/font.h index 667b177e0..fdc63f9a5 100644 --- a/render/font.h +++ b/render/font.h @@ -10,6 +10,7 @@ #ifndef _NETSURF_RENDER_FONT_H_ #define _NETSURF_RENDER_FONT_H_ +#include #include "netsurf/css/css.h" typedef enum { @@ -31,21 +32,21 @@ struct font_set *nsfont_new_set(void); struct font_data *nsfont_open(struct font_set *set, struct css_style *style); void nsfont_free_set(struct font_set *set); unsigned long nsfont_width(struct font_data *font, const char *text, - unsigned int length); + size_t length); void nsfont_position_in_string(struct font_data *font, const char *text, - unsigned int length, unsigned long x, int *char_offset, + size_t length, unsigned long x, int *char_offset, int *pixel_offset); char *nsfont_split(struct font_data *font, const char *text, - unsigned int length, + size_t length, unsigned int width, unsigned int *used_width); void nsfont_paint(struct font_data *font, const char *str, - int xpos, int ypos, void *trfm, int length); + size_t length, int xpos, int ypos, void *trfm); void nsfont_txtenum(struct font_data *font, const char *text, - unsigned int length, + size_t length, unsigned int *width, const char **rofontname, const char **rotext, - unsigned int *rolength, - unsigned int *consumed); + size_t *rolength, + size_t *consumed); #endif diff --git a/render/html.c b/render/html.c index 8bf03c4bf..f71182079 100644 --- a/render/html.c +++ b/render/html.c @@ -90,11 +90,11 @@ bool html_create(struct content *c, const char *params[]) html->getenc = false; } else { LOG(("xmlSwitchToEncoding failed for <%s>\n", encStr)); - free(encStr); + free((void *)encStr); } } else { LOG(("xmlFindCharEncodingHandler() failed for <%s>\n", encStr)); - free(encStr); + free((void *)encStr); } } html->base_url = xstrdup(c->url); diff --git a/render/html.h b/render/html.h index be84d9efd..ef22c0d1a 100644 --- a/render/html.h +++ b/render/html.h @@ -36,7 +36,7 @@ struct imagemap; struct content_html_data { htmlParserCtxt *parser; /**< HTML parser context. */ - xmlChar *encoding; /**< Encoding of source. */ + const char *encoding; /**< Encoding of source. */ bool getenc; /**< Need to get the encoding from the document, as it * wasn't specified in the Content-Type header. */ diff --git a/render/layout.c b/render/layout.c index a4e688f42..5b08a11d5 100644 --- a/render/layout.c +++ b/render/layout.c @@ -749,7 +749,8 @@ bool layout_line(struct box *first, int width, int *y, if (b->text) { if (b->width == UNKNOWN_WIDTH) - b->width = nsfont_width(b->font, b->text, + b->width = nsfont_width(b->font, + b->text, b->length); x += b->width + b->space ? b->font->space_width : 0; @@ -998,7 +999,8 @@ bool layout_line(struct box *first, int width, int *y, } else { /* fit as many words as possible */ assert(space != 0); - space = nsfont_split(split_box->font, split_box->text, + space = nsfont_split(split_box->font, + split_box->text, split_box->length, x1 - x0 - x - space_before, &w) - split_box->text; diff --git a/riscos/font.c b/riscos/font.c index 6e2064438..ef2ecb5a6 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -414,7 +414,7 @@ void nsfont_free_set(struct font_set *set) * \return width of text in pixels */ unsigned long nsfont_width(struct font_data *font, const char *text, - unsigned int length) + size_t length) { int width; os_error *error; @@ -487,7 +487,7 @@ unsigned long nsfont_width(struct font_data *font, const char *text, * \param pixel_offset updated to give the coordinate of the character in pixels */ void nsfont_position_in_string(struct font_data *font, const char *text, - unsigned int length, unsigned long x, + size_t length, unsigned long x, int *char_offset, int *pixel_offset) { os_error *error; @@ -568,8 +568,7 @@ void nsfont_position_in_string(struct font_data *font, const char *text, * \return pointer to character which does not fit */ char *nsfont_split(struct font_data *font, const char *text, - unsigned int length, - unsigned int width, unsigned int *used_width) + size_t length, unsigned int width, unsigned int *used_width) { os_error *error; font_scan_block block; @@ -645,7 +644,7 @@ char *nsfont_split(struct font_data *font, const char *text, void nsfont_paint(struct font_data *data, const char *text, - int xpos, int ypos, void *trfm, int length) + size_t length, int xpos, int ypos, void *trfm) { os_error *error; unsigned int flags; @@ -679,7 +678,7 @@ void nsfont_paint(struct font_data *data, const char *text, xos_read_vdu_variables((const os_vdu_var_list *)&var_input, (int *)&var_output); xpos += var_output[0]; ypos += var_output[1]; - + switch (data->ftype) { case FONTTYPE_UFONT: @@ -728,12 +727,12 @@ void nsfont_paint(struct font_data *data, const char *text, * \param consumed number of bytes of the given text which can be set with one RISC OS font. If 0, then error happened or initial text length was 0. */ void nsfont_txtenum(struct font_data *font, const char *text, - unsigned int length, + size_t length, unsigned int *width, const char **rofontname, const char **rotext, - unsigned int *rolength, - unsigned int *consumed) + size_t *rolength, + size_t *consumed) { assert(font != NULL && text != NULL && rofontname != NULL && rotext != NULL && rolength != NULL && consumed != NULL); diff --git a/riscos/gui.h b/riscos/gui.h index d667a9148..ef500cfd0 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -11,6 +11,7 @@ #define _NETSURF_RISCOS_GUI_H_ #include +#include #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "netsurf/utils/config.h" diff --git a/riscos/htmlredraw.c b/riscos/htmlredraw.c index e037ac86e..d9060563d 100644 --- a/riscos/htmlredraw.c +++ b/riscos/htmlredraw.c @@ -530,13 +530,13 @@ bool html_redraw_box(struct box *box, } if (scale == 1) - nsfont_paint(box->font, box->text, + nsfont_paint(box->font, box->text, box->length, x, y - (int) (box->height * 1.5), - NULL, (int) box->length); + NULL); else - nsfont_paint(box->font, box->text, + nsfont_paint(box->font, box->text, box->length, x, y - (int) (box->height * 1.5 * scale), - &trfm, (int) box->length); + &trfm); } else { @@ -832,7 +832,7 @@ bool html_redraw_file(int x, int y, int width, int height, int text_width; const char *text; const char *sprite; - int length; + size_t length; if (box->gadget->value) { text = box->gadget->value; @@ -849,8 +849,7 @@ bool html_redraw_file(int x, int y, int width, int height, else x = x + 4; - nsfont_paint(box->font, text, - x, y - height * 0.75, &trfm, length); + nsfont_paint(box->font, text, length, x, y - height * 0.75, &trfm); /* xwimpspriteop_put_sprite_user_coords(sprite, x + 4, */ /* y - height / 2 - 17, os_ACTION_OVERWRITE); */ diff --git a/riscos/print.c b/riscos/print.c index 97991c1c1..ddb92963d 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -700,8 +700,8 @@ bool print_find_fonts(struct box *box, struct print_font **print_fonts, int *num { struct box *a; const char *txt; - int txt_len; - unsigned int width, rolength, consumed; + size_t txt_len; + size_t width, rolength, consumed; const char *rofontname, *rotext; int i; diff --git a/riscos/save_draw.c b/riscos/save_draw.c index 9f71c05c5..469d5a3d5 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -1021,7 +1021,7 @@ static bool add_text(struct box *box, os_colour cbc, os_colour fc, size_t txt_len = box->length; while (txt_len != 0) { - unsigned int width, rolength, consumed; + size_t width, rolength, consumed; const char *rofontname, *rotext; byte fontIndex; drawfile_object *dro; -- cgit v1.2.3