[project @ 2004-08-14 15:07:19 by joty]

- Rename len() to css_len2px().
- Less compiler warnings concerning float/int implicit casts.
- More stddef.h type usuage.

svn path=/import/netsurf/; revision=1232
This commit is contained in:
John Tytgat 2004-08-14 15:07:21 +00:00
parent 402c4ca66c
commit 7264ae50e5
8 changed files with 55 additions and 59 deletions

View File

@ -863,11 +863,10 @@ bool fetch_can_fetch(const char *url)
{
unsigned int i;
const char *semi;
unsigned int len;
size_t len;
curl_version_info_data *data;
semi = strchr(url, ':');
if (!semi)
if ((semi = strchr(url, ':')) == NULL)
return false;
len = semi - url;

View File

@ -948,7 +948,7 @@ bool css_match_detail(const struct css_selector *detail,
bool match = false;
char *s = 0;
char *space, *word;
unsigned int length;
size_t length;
switch (detail->type) {
case CSS_SELECTOR_ID:
@ -2396,12 +2396,12 @@ unsigned int css_hash(const char *s, int length)
* Convert a struct css_length to pixels.
*/
float len(struct css_length * length, struct css_style * style)
float css_len2px(struct css_length * length, struct css_style * style)
{
assert(!((length->unit == CSS_UNIT_EM || length->unit == CSS_UNIT_EX) && style == 0));
switch (length->unit) {
case CSS_UNIT_EM: return length->value * len(&style->font_size.value.length, 0);
case CSS_UNIT_EX: return length->value * len(&style->font_size.value.length, 0) * 0.6;
case CSS_UNIT_EM: return length->value * css_len2px(&style->font_size.value.length, 0);
case CSS_UNIT_EX: return length->value * css_len2px(&style->font_size.value.length, 0) * 0.6;
case CSS_UNIT_PX: return length->value;
case CSS_UNIT_IN: return length->value * 90.0;
case CSS_UNIT_CM: return length->value * 35.0;

View File

@ -538,6 +538,6 @@ colour named_colour(const char *name);
void css_dump_style(const struct css_style * const style);
void css_dump_stylesheet(const struct css_stylesheet * stylesheet);
float len(struct css_length * length, struct css_style * style);
float css_len2px(struct css_length * length, struct css_style * style);
#endif

View File

@ -124,10 +124,10 @@ static void add_option(xmlNode* n, struct form_control* current_select,
const char *text);
static void box_normalise_block(struct box *block, pool box_pool);
static void box_normalise_table(struct box *table, pool box_pool);
void box_normalise_table_row_group(struct box *row_group,
static void box_normalise_table_row_group(struct box *row_group,
unsigned int **row_span, unsigned int *table_columns,
pool box_pool);
void box_normalise_table_row(struct box *row,
static void box_normalise_table_row(struct box *row,
unsigned int **row_span, unsigned int *table_columns,
pool box_pool);
static void box_normalise_inline_container(struct box *cont, pool box_pool);

View File

@ -307,7 +307,7 @@ void layout_block_find_dimensions(int available_width, struct box *box)
/* calculate box width */
switch (style->width.width) {
case CSS_WIDTH_LENGTH:
width = len(&style->width.value.length, style);
width = (int)css_len2px(&style->width.value.length, style);
break;
case CSS_WIDTH_PERCENT:
width = available_width * style->width.value.percent / 100;
@ -321,7 +321,7 @@ void layout_block_find_dimensions(int available_width, struct box *box)
/* height */
switch (style->height.height) {
case CSS_HEIGHT_LENGTH:
box->height = len(&style->height.length, style);
box->height = (int)css_len2px(&style->height.length, style);
break;
case CSS_HEIGHT_AUTO:
default:
@ -429,7 +429,7 @@ void layout_float_find_dimensions(int available_width,
/* calculate box width */
switch (style->width.width) {
case CSS_WIDTH_LENGTH:
box->width = len(&style->width.value.length, style);
box->width = (int)css_len2px(&style->width.value.length, style);
break;
case CSS_WIDTH_PERCENT:
box->width = available_width *
@ -444,7 +444,7 @@ void layout_float_find_dimensions(int available_width,
/* height */
switch (style->height.height) {
case CSS_HEIGHT_LENGTH:
box->height = len(&style->height.length, style);
box->height = (int)css_len2px(&style->height.length, style);
break;
case CSS_HEIGHT_AUTO:
default:
@ -495,7 +495,7 @@ void layout_find_dimensions(int available_width,
for (i = 0; i != 4; i++) {
switch (style->margin[i].margin) {
case CSS_MARGIN_LENGTH:
margin[i] = len(&style->margin[i].value.length, style);
margin[i] = (int)css_len2px(&style->margin[i].value.length, style);
break;
case CSS_MARGIN_PERCENT:
margin[i] = available_width *
@ -514,7 +514,7 @@ void layout_find_dimensions(int available_width,
break;
case CSS_PADDING_LENGTH:
default:
padding[i] = len(&style->padding[i].value.length, style);
padding[i] = (int)css_len2px(&style->padding[i].value.length, style);
break;
}
@ -523,7 +523,7 @@ void layout_find_dimensions(int available_width,
/* spec unclear: following Mozilla */
border[i] = 0;
else
border[i] = len(&style->border[i].width.value, style);
border[i] = (int)css_len2px(&style->border[i].width.value, style);
}
}
@ -648,13 +648,13 @@ int line_height(struct css_style *style)
style->line_height.size == CSS_LINE_HEIGHT_PERCENT);
/* take account of minimum font size option */
if ((font_len = len(&style->font_size.value.length, 0)) <
if ((font_len = css_len2px(&style->font_size.value.length, 0)) <
((float)(option_font_min_size * 9.0 / 72.0)))
font_len = (float)(option_font_min_size * 9.0 / 72.0);
switch (style->line_height.size) {
case CSS_LINE_HEIGHT_LENGTH:
return len(&style->line_height.value.length, style);
return (int)css_len2px(&style->line_height.value.length, style);
case CSS_LINE_HEIGHT_ABSOLUTE:
return style->line_height.value.absolute * font_len;
@ -766,7 +766,7 @@ bool layout_line(struct box *first, int width, int *y,
/* calculate box width */
switch (b->style->width.width) {
case CSS_WIDTH_LENGTH:
b->width = len(&b->style->width.value.length,
b->width = (int)css_len2px(&b->style->width.value.length,
b->style);
break;
case CSS_WIDTH_PERCENT:
@ -783,7 +783,7 @@ bool layout_line(struct box *first, int width, int *y,
/* height */
switch (b->style->height.height) {
case CSS_HEIGHT_LENGTH:
b->height = len(&b->style->height.length,
b->height = (int)css_len2px(&b->style->height.length,
b->style);
break;
case CSS_HEIGHT_AUTO:
@ -1076,7 +1076,7 @@ int layout_text_indent(struct css_style *style, int width)
{
switch (style->text_indent.size) {
case CSS_TEXT_INDENT_LENGTH:
return len(&style->text_indent.value.length, style);
return (int)css_len2px(&style->text_indent.value.length, style);
case CSS_TEXT_INDENT_PERCENT:
return width * style->text_indent.value.percent / 100;
default:
@ -1205,7 +1205,7 @@ bool layout_table(struct box *table, int available_width,
switch (style->width.width) {
case CSS_WIDTH_LENGTH:
table_width = len(&style->width.value.length, style);
table_width = (int)css_len2px(&style->width.value.length, style);
auto_width = table_width;
break;
case CSS_WIDTH_PERCENT:
@ -1376,7 +1376,7 @@ bool layout_table(struct box *table, int available_width,
/* some sites use height="1" or similar to attempt
* to make cells as small as possible, so treat
* it as a minimum */
int h = len(&c->style->height.length, c->style);
int h = (int)css_len2px(&c->style->height.length, c->style);
if (c->height < h)
c->height = h;
}
@ -1493,17 +1493,17 @@ bool calculate_widths(struct box *box)
if (style) {
for (side = 1; side != 5; side += 2) { /* RIGHT, LEFT */
if (style->padding[side].padding == CSS_PADDING_LENGTH)
extra_fixed += len(&style->padding[side].value.length,
extra_fixed += (int)css_len2px(&style->padding[side].value.length,
style);
else if (style->padding[side].padding == CSS_PADDING_PERCENT)
extra_frac += style->padding[side].value.percent * 0.01;
if (style->border[side].style != CSS_BORDER_STYLE_NONE)
extra_fixed += len(&style->border[side].width.value,
extra_fixed += (int)css_len2px(&style->border[side].width.value,
style);
if (style->margin[side].margin == CSS_MARGIN_LENGTH)
extra_fixed += len(&style->margin[side].value.length,
extra_fixed += (int)css_len2px(&style->margin[side].value.length,
style);
else if (style->margin[side].margin == CSS_MARGIN_PERCENT)
extra_frac += style->margin[side].value.percent * 0.01;
@ -1545,7 +1545,7 @@ bool calculate_block_widths(struct box *box, int *min, int *max,
}
if (box->style->width.width == CSS_WIDTH_LENGTH) {
width = len(&box->style->width.value.length, box->style);
width = (int)css_len2px(&box->style->width.value.length, box->style);
if (*min < width) *min = width;
if (*max < width) *max = width;
if (max_sum) *max_sum += width;
@ -1555,7 +1555,7 @@ bool calculate_block_widths(struct box *box, int *min, int *max,
width = box->object->width;
else
width = box->object->width *
(float) len(&box->style->height.length,
css_len2px(&box->style->height.length,
box->style) / box->object->height;
if (*min < width) *min = width;
if (*max < width) *max = width;
@ -1640,7 +1640,7 @@ void calculate_inline_replaced_widths(struct box *box, int *min,
int width;
if (box->style->width.width == CSS_WIDTH_LENGTH) {
box->width = len(&box->style->width.value.length, box->style);
box->width = (int)css_len2px(&box->style->width.value.length, box->style);
*line_max += box->width;
if (*min < box->width)
*min = box->width;
@ -1649,7 +1649,7 @@ void calculate_inline_replaced_widths(struct box *box, int *min,
width = box->object->width;
else
width = box->object->width *
(float) len(&box->style->height.length,
css_len2px(&box->style->height.length,
box->style) / box->object->height;
if (*min < width) *min = width;
if (*max < width) *max = width;
@ -1756,7 +1756,7 @@ bool calculate_table_widths(struct box *table)
cell->style->width.width ==
CSS_WIDTH_LENGTH) {
col[i].type = COLUMN_WIDTH_FIXED;
col[i].width = len(&cell->style->
col[i].width = (int)css_len2px(&cell->style->
width.value.length,
cell->style);
continue;
@ -1812,7 +1812,7 @@ bool calculate_table_widths(struct box *table)
}
if (cell->style->width.width == CSS_WIDTH_LENGTH) {
width = len(&cell->style->width.value.length,
width = (int)css_len2px(&cell->style->width.value.length,
cell->style);
if (cell_min < width)
cell_min = width;

View File

@ -208,8 +208,8 @@ struct font_data *nsfont_open(struct font_set *set, struct css_style *style)
assert(style != NULL);
if (style->font_size.size == CSS_FONT_SIZE_LENGTH)
size = len(&style->font_size.value.length, style) *
72.0 / 90.0 * 16;
size = (int)(css_len2px(&style->font_size.value.length,
style) * 72.0 / 90.0 * 16.);
if (size < option_font_min_size * 1.6)
size = option_font_min_size * 1.6;
if (1600 < size)

View File

@ -954,7 +954,7 @@ bool html_redraw_background(int xi, int yi, int width, int height,
x += ((state.visible.x1 - state.visible.x0) - (image_size.x * 2)) * multiplier;
break;
case CSS_BACKGROUND_POSITION_LENGTH:
x += 2 * len(&box->style->background_position.horz.value.length, box->style) * scale;
x += (int)(2. * css_len2px(&box->style->background_position.horz.value.length, box->style) * scale);
break;
default:
break;
@ -966,7 +966,7 @@ bool html_redraw_background(int xi, int yi, int width, int height,
y -= ((state.visible.y1 - state.visible.y0 - toolbar_height) - (image_size.y * 2)) * multiplier;
break;
case CSS_BACKGROUND_POSITION_LENGTH:
y -= 2 * len(&box->style->background_position.vert.value.length, box->style) * scale;
y -= (int)(2. * css_len2px(&box->style->background_position.vert.value.length, box->style) * scale);
break;
default:
break;
@ -984,7 +984,7 @@ bool html_redraw_background(int xi, int yi, int width, int height,
x += 2 * (box->width + box->padding[LEFT] + box->padding[RIGHT] - image_size.x) * multiplier;
break;
case CSS_BACKGROUND_POSITION_LENGTH:
x += 2 * len(&box->style->background_position.horz.value.length, box->style) * scale;
x += (int)(2. * css_len2px(&box->style->background_position.horz.value.length, box->style) * scale);
break;
default:
break;
@ -996,7 +996,7 @@ bool html_redraw_background(int xi, int yi, int width, int height,
y -= 2 * (box->height + box->padding[TOP] + box->padding[BOTTOM] - image_size.y) * multiplier;
break;
case CSS_BACKGROUND_POSITION_LENGTH:
y -= 2 * len(&box->style->background_position.vert.value.length, box->style) * scale;
y -= (int)(2. * css_len2px(&box->style->background_position.vert.value.length, box->style) * scale);
break;
default:
break;

View File

@ -62,14 +62,13 @@ url_func_result url_normalize(const char *url, char **result)
char c;
int m;
int i;
int len;
size_t len;
bool http = false;
regmatch_t match[10];
(*result) = 0;
*result = NULL;
m = regexec(&url_re, url, 10, match, 0);
if (m) {
if ((m = regexec(&url_re, url, 10, match, 0)) != NULL) {
LOG(("url '%s' failed to match regex", url));
return URL_FUNC_FAILED;
}
@ -79,27 +78,24 @@ url_func_result url_normalize(const char *url, char **result)
if (match[1].rm_so == -1) {
/* scheme missing: add http:// and reparse */
LOG(("scheme missing: using http"));
(*result) = malloc(strlen(url) + 13);
if (!(*result)) {
if ((*result = malloc(len + 13)) == NULL) {
LOG(("malloc failed"));
return URL_FUNC_NOMEM;
}
strcpy((*result), "http://");
strcpy((*result) + 7, url);
m = regexec(&url_re, (*result), 10, match, 0);
if (m) {
strcpy(*result, "http://");
strcpy(*result + sizeof("http://")-1, url);
if ((m = regexec(&url_re, *result, 10, match, 0)) != NULL) {
LOG(("url '%s' failed to match regex", (*result)));
free((*result));
free(*result);
return URL_FUNC_FAILED;
}
len += 7;
len += sizeof("http://")-1;
} else {
(*result) = malloc(len + 6);
if (!(*result)) {
if ((*result = malloc(len + 6)) == NULL) {
LOG(("strdup failed"));
return URL_FUNC_FAILED;
}
strcpy((*result), url);
strcpy(*result, url);
}
/*for (unsigned int i = 0; i != 10; i++) {
@ -115,9 +111,11 @@ url_func_result url_normalize(const char *url, char **result)
if (match[2].rm_so != -1) {
for (i = match[2].rm_so; i != match[2].rm_eo; i++)
(*result)[i] = tolower((*result)[i]);
if (match[2].rm_eo == 4 && (*result)[0] == 'h' &&
(*result)[1] == 't' && (*result)[2] == 't' &&
(*result)[3] == 'p')
if (match[2].rm_eo == 4
&& (*result)[0] == 'h'
&& (*result)[1] == 't'
&& (*result)[2] == 't'
&& (*result)[3] == 'p')
http = true;
}
@ -174,8 +172,7 @@ url_func_result url_normalize(const char *url, char **result)
else
continue;
if (m <= 0x20 || strchr(";/?:@&=+$," "<>#%\""
"{}|\\^[]`", m)) {
if (m <= 0x20 || strchr(";/?:@&=+$," "<>#%\"{}|\\^[]`", m)) {
i += 2;
continue;
}