r4462 dynis - in /branches/dynis/libnsbmp: Makefile bin/ bin/decode_bmp bmp_display examples/ examples/decode_bmp.c examples/linux.bmp examples/ro.bmp
by netsurf@semichrome.net
Author: dynis
Date: Thu Jun 26 23:06:59 2008
New Revision: 4462
URL: http://source.netsurf-browser.org?rev=4462&view=rev
Log:
Added bmp decoding example
Added:
branches/dynis/libnsbmp/bin/
branches/dynis/libnsbmp/bin/decode_bmp (with props)
branches/dynis/libnsbmp/bmp_display (with props)
branches/dynis/libnsbmp/examples/
branches/dynis/libnsbmp/examples/decode_bmp.c
branches/dynis/libnsbmp/examples/linux.bmp (with props)
branches/dynis/libnsbmp/examples/ro.bmp (with props)
Modified:
branches/dynis/libnsbmp/Makefile
Modified: branches/dynis/libnsbmp/Makefile
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/Makefile?rev=44...
==============================================================================
--- branches/dynis/libnsbmp/Makefile (original)
+++ branches/dynis/libnsbmp/Makefile Thu Jun 26 23:06:59 2008
@@ -23,7 +23,7 @@
.PHONY: all clean docs install uninstall
-all: libnsbmp.a
+all: libnsbmp.a bin/decode_bmp
libnsbmp.a: libnsbmp.o libnsbmp.pc
${AR} ${ARFLAGS} libnsbmp.a libnsbmp.o
@@ -33,6 +33,9 @@
%.o: %.c
${CC} -c ${CFLAGS} -o $@ $<
+
+bin/decode_bmp: examples/decode_bmp.c libnsbmp.a
+ ${CC} ${CFLAGS} -o $@ $< libnsbmp.a
docs:
${DOXYGEN}
Added: branches/dynis/libnsbmp/bin/decode_bmp
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/bin/decode_bmp?...
==============================================================================
Binary file - no diff available.
Propchange: branches/dynis/libnsbmp/bin/decode_bmp
------------------------------------------------------------------------------
svn:executable = *
Propchange: branches/dynis/libnsbmp/bin/decode_bmp
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: branches/dynis/libnsbmp/bmp_display
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/bmp_display?rev...
==============================================================================
--- branches/dynis/libnsbmp/bmp_display (added)
+++ branches/dynis/libnsbmp/bmp_display Thu Jun 26 23:06:59 2008
@@ -1,0 +1,3 @@
+set -e
+make
+bin/decode_bmp $1 | display
Propchange: branches/dynis/libnsbmp/bmp_display
------------------------------------------------------------------------------
svn:executable = *
Added: branches/dynis/libnsbmp/examples/decode_bmp.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/examples/decode...
==============================================================================
--- branches/dynis/libnsbmp/examples/decode_bmp.c (added)
+++ branches/dynis/libnsbmp/examples/decode_bmp.c Thu Jun 26 23:06:59 2008
@@ -1,0 +1,220 @@
+/*
+ * Copyright 2008 Sean Fox <dyntryx(a)gmail.com>
+ * Copyright 2008 James Bursa <james(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <libnsbmp.h>
+
+#define BITMAP_BYTES_PER_PIXEL 4
+
+unsigned char *load_file(const char *path, size_t *data_size);
+void warning(const char *context, bmp_result code);
+void *bitmap_create(int width, int height, unsigned int state);
+void bitmap_set_suspendable(void *bitmap, void *private_word,
+ void (*invalidate)(void *bitmap, void *private_word));
+void invalidate(void *bitmap, void *private_word);
+unsigned char *bitmap_get_buffer(void *bitmap);
+size_t bitmap_get_bpp(void *bitmap);
+void bitmap_destroy(void *bitmap);
+
+/* The Bitmap callbacks function table;
+ necessary for interaction with nsgiflib.
+*/
+bmp_bitmap_callback_vt bitmap_callbacks = {
+ bitmap_create,
+ bitmap_destroy,
+ bitmap_set_suspendable,
+ bitmap_get_buffer,
+ bitmap_get_bpp
+};
+
+
+int main(int argc, char *argv[])
+{
+ bmp_result code;
+ bmp_image bmp;
+ size_t size;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s image.bmp\n", argv[0]);
+ return 1;
+ }
+
+ /* create our bmp image */
+ bmp_create(&bmp);
+
+ /* load file into memory */
+ unsigned char *data = load_file(argv[1], &size);
+
+ /* set our source data */
+ bmp.bmp_data = data;
+ bmp.buffer_size = size;
+
+ /* analyse the BMP */
+ code = bmp_analyse(&bmp, &bitmap_callbacks);
+ if (code != BMP_OK) {
+ warning("bmp_analyse", code);
+ exit(1);
+ }
+
+ printf("P3\n");
+ printf("# %s\n", argv[1]);
+ printf("# width %u \n", bmp.width);
+ printf("# height %u \n", bmp.height);
+ printf("%u %u 256\n", bmp.width, bmp.height);
+
+ /* decode the image */
+ code = bmp_decode(&bmp, &bitmap_callbacks);
+ if (code != BMP_OK) {
+ warning("bmp_decode", code);
+ exit(1);
+ }
+ {
+ unsigned int row, col;
+ unsigned char *image;
+ image = (unsigned char *) bmp.bitmap;
+ for (row = 0; row != bmp.height; row++) {
+ for (col = 0; col != bmp.width; col++) {
+ size_t z = (row * bmp.width + col) * BITMAP_BYTES_PER_PIXEL;
+ printf("%u %u %u ",
+ (unsigned char) image[z],
+ (unsigned char) image[z + 1],
+ (unsigned char) image[z + 2]);
+ }
+ printf("\n");
+ }
+ }
+
+ /* clean up */
+ bmp_finalise(&bmp, &bitmap_callbacks);
+ free(data);
+
+ return 0;
+}
+
+
+unsigned char *load_file(const char *path, size_t *data_size)
+{
+ FILE *fd;
+ struct stat sb;
+ unsigned char *buffer;
+ size_t size;
+ size_t n;
+
+ fd = fopen(path, "rb");
+ if (!fd) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ if (stat(path, &sb)) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+ size = sb.st_size;
+
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %lld bytes\n",
+ (long long) size);
+ exit(EXIT_FAILURE);
+ }
+
+ n = fread(buffer, 1, size, fd);
+ if (n != size) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ fclose(fd);
+
+ *data_size = size;
+ return buffer;
+}
+
+
+void warning(const char *context, bmp_result code)
+{
+ fprintf(stderr, "%s failed: ", context);
+ switch (code) {
+ case BMP_INSUFFICIENT_MEMORY:
+ fprintf(stderr, "BMP_INSUFFICIENT_MEMORY");
+ break;
+ case BMP_INSUFFICIENT_DATA:
+ fprintf(stderr, "BMP_INSUFFICIENT_DATA");
+ break;
+ case BMP_DATA_ERROR:
+ fprintf(stderr, "BMP_DATA_ERROR");
+ break;
+ default:
+ fprintf(stderr, "unknown code %i", code);
+ break;
+ }
+ fprintf(stderr, "\n");
+}
+
+
+void *bitmap_create(int width, int height, unsigned int state)
+{
+ (void) state; /* unused */
+ return calloc(width * height, BITMAP_BYTES_PER_PIXEL);
+}
+
+
+void bitmap_set_suspendable(void *bitmap, void *private_word,
+ void (*invalidate)(void *bitmap, void *private_word))
+{
+ (void) bitmap; /* unused */
+ (void) private_word; /* unused */
+ (void) invalidate; /* unused */
+}
+
+
+void invalidate(void *bitmap, void *private_word)
+{
+ (void) bitmap; /* unused */
+ (void) private_word; /* unused */
+}
+
+
+unsigned char *bitmap_get_buffer(void *bitmap)
+{
+ assert(bitmap);
+ return bitmap;
+}
+
+
+size_t bitmap_get_bpp(void *bitmap)
+{
+ (void) bitmap; /* unused */
+ return BITMAP_BYTES_PER_PIXEL;
+}
+
+
+void bitmap_destroy(void *bitmap)
+{
+ assert(bitmap);
+ free(bitmap);
+}
+
Added: branches/dynis/libnsbmp/examples/linux.bmp
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/examples/linux....
==============================================================================
Binary file - no diff available.
Propchange: branches/dynis/libnsbmp/examples/linux.bmp
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: branches/dynis/libnsbmp/examples/ro.bmp
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/examples/ro.bmp...
==============================================================================
Binary file - no diff available.
Propchange: branches/dynis/libnsbmp/examples/ro.bmp
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
14 years, 11 months
r4461 dynis - in /branches/dynis/libnsbmp: libnsbmp.c libnsbmp.h
by netsurf@semichrome.net
Author: dynis
Date: Thu Jun 26 22:42:33 2008
New Revision: 4461
URL: http://source.netsurf-browser.org?rev=4461&view=rev
Log:
Correct coloring issue under linux caused by signedness; added bmp_create() function
Modified:
branches/dynis/libnsbmp/libnsbmp.c
branches/dynis/libnsbmp/libnsbmp.h
Modified: branches/dynis/libnsbmp/libnsbmp.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/libnsbmp.c?rev=...
==============================================================================
--- branches/dynis/libnsbmp/libnsbmp.c (original)
+++ branches/dynis/libnsbmp/libnsbmp.c Thu Jun 26 22:42:33 2008
@@ -26,19 +26,32 @@
#include "libnsbmp.h"
#include "utils/log.h"
-#define READ_SHORT(a, o) (a[o]|(a[o+1]<<8))
-#define READ_INT(a, o) (a[o]|(a[o+1]<<8)|(a[o+2]<<16)|(a[o+3]<<24))
-
/* squashes unused variable compiler warnings */
#define UNUSED(x) ((x)=(x))
-bmp_result bmp_analyse_header(struct bmp_image *bmp, char *data, bmp_bitmap_callback_vt *bitmap_callbacks);
-bmp_result bmp_decode_rgb24(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
-bmp_result bmp_decode_rgb16(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
-bmp_result bmp_decode_rgb(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
-bmp_result bmp_decode_mask(struct bmp_image *bmp, char *data, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
-bmp_result bmp_decode_rle(struct bmp_image *bmp, char *data, int bytes, int size, bmp_bitmap_callback_vt *bitmap_callbacks);
+static inline int read_short(unsigned char *data, unsigned int o) {
+ return (data[o] | ((unsigned char)data[o+1] << 8));
+}
+
+static inline int read_int(unsigned char *data, unsigned int o) {
+ return ((unsigned char)data[o] | ((unsigned char)data[o+1] << 8) | ((unsigned char)data[o+2] << 16) | ((unsigned char)data[o+3] << 24));
+}
+
+bmp_result bmp_analyse_header(struct bmp_image *bmp, unsigned char *data, bmp_bitmap_callback_vt *bitmap_callbacks);
+bmp_result bmp_decode_rgb24(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
+bmp_result bmp_decode_rgb16(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
+bmp_result bmp_decode_rgb(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
+bmp_result bmp_decode_mask(struct bmp_image *bmp, unsigned char *data, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks);
+bmp_result bmp_decode_rle(struct bmp_image *bmp, unsigned char *data, int bytes, int size, bmp_bitmap_callback_vt *bitmap_callbacks);
void bmp_invalidate(void *bitmap, void *private_word);
+
+
+
+/** Initialises necessary bmp_image members.
+*/
+void bmp_create(bmp_image *bmp) {
+ memset(bmp, 0, sizeof(bmp_image));
+}
/**
@@ -54,7 +67,7 @@
* \return BMP_OK on success
*/
bmp_result bmp_analyse(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *data = (char *) bmp->bmp_data;
+ unsigned char *data = bmp->bmp_data;
/* ensure we aren't already initialised */
if (bmp->bitmap)
@@ -72,7 +85,7 @@
return BMP_INSUFFICIENT_DATA;
if ((data[0] != 'B') || (data[1] != 'M'))
return BMP_DATA_ERROR;
- bmp->bitmap_offset = READ_INT(data, 10);
+ bmp->bitmap_offset = read_int(data, 10);
/* decode the BMP header */
return bmp_analyse_header(bmp, data + 14, bitmap_callbacks);
@@ -91,7 +104,7 @@
* \return BMP_OK on success
*/
bmp_result ico_analyse(struct ico_collection *ico, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *data = (char *) ico->ico_data;
+ unsigned char *data = ico->ico_data;
unsigned int count, i;
bmp_result result;
struct ico_image *image;
@@ -108,9 +121,9 @@
*/
if (ico->buffer_size < 6)
return BMP_INSUFFICIENT_DATA;
- if (READ_INT(data, 0) != 0x00010000)
+ if (read_int(data, 0) != 0x00010000)
return BMP_DATA_ERROR;
- count = READ_SHORT(data, 4);
+ count = read_short(data, 4);
if (count == 0)
return BMP_DATA_ERROR;
data += 6;
@@ -126,12 +139,12 @@
ico->first = image;
image->bmp.width = data[0];
image->bmp.height = data[1];
- image->bmp.buffer_size = READ_INT(data, 8) + 40;
- image->bmp.bmp_data = ico->ico_data + READ_INT(data, 12);
+ image->bmp.buffer_size = read_int(data, 8) + 40;
+ image->bmp.bmp_data = ico->ico_data + read_int(data, 12);
image->bmp.ico = true;
data += 16;
result = bmp_analyse_header(&image->bmp,
- (char *) image->bmp.bmp_data, bitmap_callbacks);
+ image->bmp.bmp_data, bitmap_callbacks);
if (result != BMP_OK)
return result;
area = image->bmp.width * image->bmp.height;
@@ -145,7 +158,7 @@
}
-bmp_result bmp_analyse_header(struct bmp_image *bmp, char *data, bmp_bitmap_callback_vt *bitmap_callbacks) {
+bmp_result bmp_analyse_header(struct bmp_image *bmp, unsigned char *data, bmp_bitmap_callback_vt *bitmap_callbacks) {
unsigned int header_size;
unsigned int i;
int width, height, j;
@@ -156,7 +169,7 @@
* on the BMP variant. A full description of the various headers
* can be found at http://www.fileformat.info/format/bmp/
*/
- header_size = READ_INT(data, 0);
+ header_size = read_int(data, 0);
if (bmp->buffer_size < (14 + header_size))
return BMP_INSUFFICIENT_DATA;
if (header_size == 12) {
@@ -168,8 +181,8 @@
* +8 SHORT number of color planes (always 1)
* +10 SHORT number of bits per pixel
*/
- width = READ_SHORT(data, 4);
- height = READ_SHORT(data, 6);
+ width = read_short(data, 4);
+ height = read_short(data, 6);
if (width < 0)
return BMP_DATA_ERROR;
if (height < 0) {
@@ -178,9 +191,9 @@
}
bmp->width = width;
bmp->height = height;
- if (READ_SHORT(data, 8) != 1)
+ if (read_short(data, 8) != 1)
return BMP_DATA_ERROR;
- bmp->bpp = READ_SHORT(data, 10);
+ bmp->bpp = read_short(data, 10);
bmp->colours = (1 << bmp->bpp);
palette_size = 3;
} else if (header_size < 40) {
@@ -219,8 +232,8 @@
* +104 INT gamma blue coordinate scale value
*/
if (!bmp->ico) {
- width = READ_INT(data, 4);
- height = READ_INT(data, 8);
+ width = read_int(data, 4);
+ height = read_int(data, 8);
if (width < 0)
return BMP_DATA_ERROR;
if (height < 0) {
@@ -230,12 +243,12 @@
bmp->width = width;
bmp->height = height;
}
- if (READ_SHORT(data, 12) != 1)
+ if (read_short(data, 12) != 1)
return BMP_DATA_ERROR;
- bmp->bpp = READ_SHORT(data, 14);
+ bmp->bpp = read_short(data, 14);
if (bmp->bpp == 0)
bmp->bpp = 8;
- bmp->encoding = READ_INT(data, 16);
+ bmp->encoding = read_int(data, 16);
if (bmp->encoding > BMP_ENCODING_BITFIELDS)
return BMP_DATA_ERROR;
if (bmp->encoding == BMP_ENCODING_BITFIELDS) {
@@ -246,10 +259,10 @@
if (bmp->buffer_size < (14 + header_size))
return BMP_INSUFFICIENT_DATA;
for (i = 0; i < 3; i++)
- bmp->mask[i] = READ_INT(data, 40 + (i << 2));
+ bmp->mask[i] = read_int(data, 40 + (i << 2));
} else {
for (i = 0; i < 4; i++)
- bmp->mask[i] = READ_INT(data, 40 + (i << 2));
+ bmp->mask[i] = read_int(data, 40 + (i << 2));
}
for (i = 0; i < 4; i++) {
if (bmp->mask[i] == 0)
@@ -265,7 +278,7 @@
}
}
}
- bmp->colours = READ_INT(data, 32);
+ bmp->colours = read_int(data, 32);
if (bmp->colours == 0)
bmp->colours = (1 << bmp->bpp);
palette_size = 4;
@@ -285,13 +298,11 @@
*/
if (bmp->buffer_size < (14 + header_size + (4 * bmp->colours)))
return BMP_INSUFFICIENT_DATA;
- bmp->colour_table = (unsigned int *)
- malloc(bmp->colours * sizeof(int));
+ bmp->colour_table = (unsigned int *)malloc(bmp->colours * sizeof(int));
if (!bmp->colour_table)
return BMP_INSUFFICIENT_MEMORY;
for (i = 0; i < bmp->colours; i++) {
- bmp->colour_table[i] = data[2] | (data[1] << 8) |
- (data[0] << 16);
+ bmp->colour_table[i] = data[2] | (data[1] << 8) | (data[0] << 16);
data += palette_size;
}
}
@@ -313,7 +324,7 @@
}
-/*
+/**
* Finds the closest BMP within an ICO collection
*
* This function finds the BMP with dimensions as close to a specified set
@@ -370,13 +381,13 @@
* \return BMP_OK on success
*/
bmp_result bmp_decode(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *data;
+ unsigned char *data;
int bytes;
bmp_result result = BMP_OK;
assert(bmp->bitmap);
- data = (char *) bmp->bmp_data + bmp->bitmap_offset;
+ data = bmp->bmp_data + bmp->bitmap_offset;
bytes = bmp->buffer_size - bmp->bitmap_offset;
switch (bmp->encoding) {
@@ -419,15 +430,15 @@
* \param bytes the number of bytes of data available
* \return BMP_OK on success
*/
-bmp_result bmp_decode_rgb24(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *top, *bottom, *end, *data;
+bmp_result bmp_decode_rgb24(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
+ unsigned char *top, *bottom, *end, *data;
unsigned int *scanline;
unsigned int x, y, swidth, skip;
intptr_t addr;
unsigned int i, word;
data = *start;
- swidth = bitmap_callbacks->bitmap_get_rowstride(bmp->bitmap);
+ swidth = bitmap_callbacks->bitmap_get_bpp(bmp->bitmap) * bmp->width;
top = bitmap_callbacks->bitmap_get_buffer(bmp->bitmap);
if (!top)
return BMP_INSUFFICIENT_MEMORY;
@@ -462,8 +473,7 @@
}
} else {
for (x = 0; x < bmp->width; x++) {
- scanline[x] = data[2] | (data[1] << 8) | (data[0] << 16) |
- (data[3] << 24);
+ scanline[x] = data[2] | (data[1] << 8) | (data[0] << 16) | (0xff << 24);
data += skip;
}
}
@@ -481,15 +491,15 @@
* \param bytes the number of bytes of data available
* \return BMP_OK on success
*/
-bmp_result bmp_decode_rgb16(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *top, *bottom, *end, *data;
+bmp_result bmp_decode_rgb16(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
+ unsigned char *top, *bottom, *end, *data;
unsigned int *scanline;
unsigned int x, y, swidth;
intptr_t addr;
unsigned int word, i;
data = *start;
- swidth = bitmap_callbacks->bitmap_get_rowstride(bmp->bitmap);
+ swidth = bitmap_callbacks->bitmap_get_bpp(bmp->bitmap) * bmp->width;
top = bitmap_callbacks->bitmap_get_buffer(bmp->bitmap);
if (!top)
return BMP_INSUFFICIENT_MEMORY;
@@ -543,8 +553,8 @@
* \param bytes the number of bytes of data available
* \return BMP_OK on success
*/
-bmp_result bmp_decode_rgb(struct bmp_image *bmp, char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *top, *bottom, *end, *data;
+bmp_result bmp_decode_rgb(struct bmp_image *bmp, unsigned char **start, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
+ unsigned char *top, *bottom, *end, *data;
unsigned int *scanline;
intptr_t addr;
unsigned int x, y, swidth;
@@ -558,7 +568,7 @@
bit_shifts[i] = 8 - ((i + 1) * bmp->bpp);
data = *start;
- swidth = bitmap_callbacks->bitmap_get_rowstride(bmp->bitmap);
+ swidth = bitmap_callbacks->bitmap_get_bpp(bmp->bitmap) * bmp->width;
top = bitmap_callbacks->bitmap_get_buffer(bmp->bitmap);
if (!top)
return BMP_INSUFFICIENT_MEMORY;
@@ -599,14 +609,14 @@
* \param bytes the number of bytes of data available
* \return BMP_OK on success
*/
-bmp_result bmp_decode_mask(struct bmp_image *bmp, char *data, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *top, *bottom, *end;
+bmp_result bmp_decode_mask(struct bmp_image *bmp, unsigned char *data, int bytes, bmp_bitmap_callback_vt *bitmap_callbacks) {
+ unsigned char *top, *bottom, *end;
unsigned int *scanline;
intptr_t addr;
unsigned int x, y, swidth;
int cur_byte = 0;
- swidth = bitmap_callbacks->bitmap_get_rowstride(bmp->bitmap);
+ swidth = bitmap_callbacks->bitmap_get_bpp(bmp->bitmap) * bmp->width;
top = bitmap_callbacks->bitmap_get_buffer(bmp->bitmap);
if (!top)
return BMP_INSUFFICIENT_MEMORY;
@@ -641,8 +651,8 @@
* \param size the size of the RLE tokens (4 or 8)
* \return BMP_OK on success
*/
-bmp_result bmp_decode_rle(struct bmp_image *bmp, char *data, int bytes, int size, bmp_bitmap_callback_vt *bitmap_callbacks) {
- char *top, *bottom, *end;
+bmp_result bmp_decode_rle(struct bmp_image *bmp, unsigned char *data, int bytes, int size, bmp_bitmap_callback_vt *bitmap_callbacks) {
+ unsigned char *top, *bottom, *end;
unsigned int *scanline;
unsigned int swidth;
int i, length, pixels_left;
@@ -652,7 +662,7 @@
if (bmp->ico)
return BMP_DATA_ERROR;
- swidth = bitmap_callbacks->bitmap_get_rowstride(bmp->bitmap);
+ swidth = bitmap_callbacks->bitmap_get_bpp(bmp->bitmap) * bmp->width;
top = bitmap_callbacks->bitmap_get_buffer(bmp->bitmap);
if (!top)
return BMP_INSUFFICIENT_MEMORY;
Modified: branches/dynis/libnsbmp/libnsbmp.h
URL: http://source.netsurf-browser.org/branches/dynis/libnsbmp/libnsbmp.h?rev=...
==============================================================================
--- branches/dynis/libnsbmp/libnsbmp.h (original)
+++ branches/dynis/libnsbmp/libnsbmp.h Thu Jun 26 22:42:33 2008
@@ -53,8 +53,8 @@
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef void (*bmp_bitmap_cb_set_suspendable)(void *bitmap, void *private_word,
void (*invalidate)(void *bitmap, void *private_word));
-typedef char* (*bmp_bitmap_cb_get_buffer)(void *bitmap);
-typedef size_t (*bmp_bitmap_cb_get_rowstride)(void *bitmap);
+typedef unsigned char* (*bmp_bitmap_cb_get_buffer)(void *bitmap);
+typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
/* The Bitmap callbacks function table
*/
@@ -63,10 +63,10 @@
bmp_bitmap_cb_destroy bitmap_destroy; /**< Free a bitmap. */
bmp_bitmap_cb_set_suspendable bitmap_set_suspendable; /**< The bitmap image can be suspended. */
bmp_bitmap_cb_get_buffer bitmap_get_buffer; /**< Return a pointer to the pixel data in a bitmap. */
- bmp_bitmap_cb_get_rowstride bitmap_get_rowstride; /**< Find the width of a pixel row in bytes. */
+ bmp_bitmap_cb_get_bpp bitmap_get_bpp; /**< Find the width of a pixel row in bytes. */
} bmp_bitmap_callback_vt;
-struct bmp_image {
+typedef struct bmp_image {
unsigned char *bmp_data; /** pointer to BMP data */
unsigned int buffer_size; /** total number of bytes of BMP data available */
unsigned int width; /** width of BMP (valid after _analyse) */
@@ -81,8 +81,8 @@
bool ico; /** image is part of an ICO, mask follows */
unsigned int mask[4]; /** four bitwise mask */
int shift[4]; /** four bitwise shifts */
- void *bitmap; /** decoded image */
-};
+ void *bitmap; /** decoded image */
+} bmp_image;
struct ico_image {
struct bmp_image bmp;
@@ -97,6 +97,7 @@
struct ico_image *first;
};
+void bmp_create(bmp_image *gif);
bmp_result bmp_analyse(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
bmp_result bmp_decode(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
void bmp_finalise(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
14 years, 11 months
r4460 dynis - in /branches/dynis/libnsgif: examples/decode_gif.c libnsgif.c
by netsurf@semichrome.net
Author: dynis
Date: Thu Jun 26 22:23:02 2008
New Revision: 4460
URL: http://source.netsurf-browser.org?rev=4460&view=rev
Log:
Type correction; clear gif_animation's memory in gif_create()
Modified:
branches/dynis/libnsgif/examples/decode_gif.c
branches/dynis/libnsgif/libnsgif.c
Modified: branches/dynis/libnsgif/examples/decode_gif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/examples/decode...
==============================================================================
--- branches/dynis/libnsgif/examples/decode_gif.c (original)
+++ branches/dynis/libnsgif/examples/decode_gif.c Thu Jun 26 22:23:02 2008
@@ -83,14 +83,14 @@
/* decode the frames */
for (i = 0; i != gif.frame_count; i++) {
unsigned int row, col;
- char *image;
+ unsigned char *image;
code = gif_decode_frame(&gif, i);
if (code != GIF_OK)
warning("gif_decode_frame", code);
printf("# frame %u:\n", i);
- image = (char *) gif.frame_image;
+ image = (unsigned char *) gif.frame_image;
for (row = 0; row != gif.height; row++) {
for (col = 0; col != gif.width; col++) {
size_t z = (row * gif.width + col) * 4;
Modified: branches/dynis/libnsgif/libnsgif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/libnsgif.c?rev=...
==============================================================================
--- branches/dynis/libnsgif/libnsgif.c (original)
+++ branches/dynis/libnsgif/libnsgif.c Thu Jun 26 22:23:02 2008
@@ -149,20 +149,16 @@
*/
static bool clear_image = false;
+
+
/** Initialises necessary gif_animation members.
*/
void gif_create(gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks) {
+ memset(gif, 0, sizeof(gif_animation));
gif->bitmap_callbacks = *bitmap_callbacks;
- gif->gif_data = NULL;
- gif->frame_image = NULL;
- gif->frames = NULL;
- gif->local_colour_table = NULL;
- gif->global_colour_table = NULL;
- gif->buffer_position = 0;
- gif->frame_count = 0;
- gif->frame_count_partial = 0;
gif->decoded_frame = GIF_INVALID_FRAME;
}
+
/** Initialises any workspace held by the animation and attempts to decode
any information that hasn't already been decoded.
@@ -361,7 +357,6 @@
*/
return return_value;
}
-
/** Updates the sprite memory size
14 years, 11 months
r4459 dynis - in /branches/dynis/libnsgif: examples/decode_gif.c libnsgif.c
by netsurf@semichrome.net
Author: dynis
Date: Thu Jun 26 18:47:31 2008
New Revision: 4459
URL: http://source.netsurf-browser.org?rev=4459&view=rev
Log:
Minor corrections; lib caller must now free gif_data
Modified:
branches/dynis/libnsgif/examples/decode_gif.c
branches/dynis/libnsgif/libnsgif.c
Modified: branches/dynis/libnsgif/examples/decode_gif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/examples/decode...
==============================================================================
--- branches/dynis/libnsgif/examples/decode_gif.c (original)
+++ branches/dynis/libnsgif/examples/decode_gif.c Thu Jun 26 18:47:31 2008
@@ -48,7 +48,7 @@
};
gif_animation gif;
size_t size;
- int code;
+ gif_result code;
unsigned int i;
if (argc != 2) {
@@ -151,7 +151,7 @@
}
-void warning(const char *context, int code)
+void warning(const char *context, gif_result code)
{
fprintf(stderr, "%s failed: ", context);
switch (code)
Modified: branches/dynis/libnsgif/libnsgif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/libnsgif.c?rev=...
==============================================================================
--- branches/dynis/libnsgif/libnsgif.c (original)
+++ branches/dynis/libnsgif/libnsgif.c Thu Jun 26 18:47:31 2008
@@ -59,7 +59,8 @@
or perform the check itself.
It should be noted that gif_finalise() should always be called, even if
- no frames were initialised.
+ no frames were initialised. Additionally, it is the responsibility of
+ the caller to free 'gif_data'.
[rjw] - Fri 2nd April 2004
*/
@@ -1100,8 +1101,6 @@
gif->local_colour_table = NULL;
free(gif->global_colour_table);
gif->global_colour_table = NULL;
- free(gif->gif_data);
- gif->gif_data = NULL;
}
/**
14 years, 11 months
r4458 dynis - in /branches/dynis/libnsgif: examples/decode_gif.c libnsgif.c libnsgif.h
by netsurf@semichrome.net
Author: dynis
Date: Thu Jun 26 14:49:08 2008
New Revision: 4458
URL: http://source.netsurf-browser.org?rev=4458&view=rev
Log:
Bitmap callbacks are now set during the call to gif_create
Modified:
branches/dynis/libnsgif/examples/decode_gif.c
branches/dynis/libnsgif/libnsgif.c
branches/dynis/libnsgif/libnsgif.h
Modified: branches/dynis/libnsgif/examples/decode_gif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/examples/decode...
==============================================================================
--- branches/dynis/libnsgif/examples/decode_gif.c (original)
+++ branches/dynis/libnsgif/examples/decode_gif.c Thu Jun 26 14:49:08 2008
@@ -38,16 +38,15 @@
int main(int argc, char *argv[])
{
- gif_animation gif = {
- .bitmap_callbacks = {
- bitmap_create,
- bitmap_destroy,
- bitmap_get_buffer,
- bitmap_set_opaque,
- bitmap_test_opaque,
- bitmap_modified
- }
+ gif_bitmap_callback_vt bitmap_callbacks = {
+ bitmap_create,
+ bitmap_destroy,
+ bitmap_get_buffer,
+ bitmap_set_opaque,
+ bitmap_test_opaque,
+ bitmap_modified
};
+ gif_animation gif;
size_t size;
int code;
unsigned int i;
@@ -58,7 +57,7 @@
}
/* create our gif animation */
- gif_create(&gif);
+ gif_create(&gif, &bitmap_callbacks);
/* load file into memory */
unsigned char *data = load_file(argv[1], &size);
@@ -106,6 +105,7 @@
/* clean up */
gif_finalise(&gif);
+ free(data);
return 0;
}
Modified: branches/dynis/libnsgif/libnsgif.c
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/libnsgif.c?rev=...
==============================================================================
--- branches/dynis/libnsgif/libnsgif.c (original)
+++ branches/dynis/libnsgif/libnsgif.c Thu Jun 26 14:49:08 2008
@@ -150,7 +150,8 @@
/** Initialises necessary gif_animation members.
*/
-void gif_create(gif_animation *gif) {
+void gif_create(gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks) {
+ gif->bitmap_callbacks = *bitmap_callbacks;
gif->gif_data = NULL;
gif->frame_image = NULL;
gif->frames = NULL;
@@ -714,6 +715,7 @@
GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame
GIF_DATA_ERROR for GIF error (invalid frame header)
GIF_INSUFFICIENT_DATA for insufficient data to do anything
+ GIF_INSUFFICIENT_MEMORY for insufficient memory to process
GIF_OK for successful decoding
If a frame does not contain any image data, GIF_OK is returned and
gif->current_error is set to GIF_FRAME_NO_DISPLAY
Modified: branches/dynis/libnsgif/libnsgif.h
URL: http://source.netsurf-browser.org/branches/dynis/libnsgif/libnsgif.h?rev=...
==============================================================================
--- branches/dynis/libnsgif/libnsgif.h (original)
+++ branches/dynis/libnsgif/libnsgif.h Thu Jun 26 14:49:08 2008
@@ -108,7 +108,7 @@
unsigned int *local_colour_table; /**< local colour table */
} gif_animation;
-void gif_create(gif_animation *gif);
+void gif_create(gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks);
gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data);
gif_result gif_decode_frame(gif_animation *gif, unsigned int frame);
void gif_finalise(gif_animation *gif);
14 years, 11 months
r4457 takkaria - in /trunk/hubbub/src/treebuilder: after_head.c in_body.c in_caption.c in_cell.c in_column_group.c in_head.c in_head_noscript.c in_row.c in_select.c in_table_body.c internal.h treebuilder.c
by netsurf@semichrome.net
Author: takkaria
Date: Thu Jun 26 13:19:49 2008
New Revision: 4457
URL: http://source.netsurf-browser.org?rev=4457&view=rev
Log:
Add namespace awareness right through the code, in preparation for handling foreign content properly.
Modified:
trunk/hubbub/src/treebuilder/after_head.c
trunk/hubbub/src/treebuilder/in_body.c
trunk/hubbub/src/treebuilder/in_caption.c
trunk/hubbub/src/treebuilder/in_cell.c
trunk/hubbub/src/treebuilder/in_column_group.c
trunk/hubbub/src/treebuilder/in_head.c
trunk/hubbub/src/treebuilder/in_head_noscript.c
trunk/hubbub/src/treebuilder/in_row.c
trunk/hubbub/src/treebuilder/in_select.c
trunk/hubbub/src/treebuilder/in_table_body.c
trunk/hubbub/src/treebuilder/internal.h
trunk/hubbub/src/treebuilder/treebuilder.c
Modified: trunk/hubbub/src/treebuilder/after_head.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/after_head...
==============================================================================
--- trunk/hubbub/src/treebuilder/after_head.c (original)
+++ trunk/hubbub/src/treebuilder/after_head.c Thu Jun 26 13:19:49 2008
@@ -55,27 +55,28 @@
} else if (type == BASE || type == LINK || type == META ||
type == NOFRAMES || type == SCRIPT ||
type == STYLE || type == TITLE) {
+ hubbub_ns ns;
element_type otype;
void *node;
/** \todo parse error */
- if (!element_stack_push(treebuilder,
- HEAD,
+ if (!element_stack_push(treebuilder,
+ HUBBUB_NS_HTML,
+ HEAD,
treebuilder->context.head_element)) {
/** \todo errors */
}
-
-
/* Process as "in head" */
reprocess = process_in_head(treebuilder, token);
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype,
+ &node)) {
/** \todo errors */
}
- /* No need to unref node as we never increased
+ /* No need to unref node as we never increased
* its reference count when pushing it on the stack */
} else if (type == HEAD) {
/** \todo parse error */
Modified: trunk/hubbub/src/treebuilder/in_body.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_body.c?...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_body.c (original)
+++ trunk/hubbub/src/treebuilder/in_body.c Thu Jun 26 13:19:49 2008
@@ -571,10 +571,12 @@
}
do {
+ hubbub_ns ns;
element_type otype;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns,
+ &otype, &node)) {
/** \todo errors */
}
@@ -846,6 +848,7 @@
void process_input_in_body(hubbub_treebuilder *treebuilder,
const hubbub_token *token)
{
+ hubbub_ns ns;
element_type otype;
void *node;
@@ -861,7 +864,7 @@
treebuilder->context.current_node].node);
}
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
@@ -1111,9 +1114,11 @@
close_implied_end_tags(treebuilder, UNKNOWN);
do {
+ hubbub_ns ns;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype,
+ &node)) {
/** \todo errors */
}
@@ -1144,11 +1149,12 @@
/** \todo parse error */
}
- while(element_in_scope(treebuilder, P, false)) {
+ while (element_in_scope(treebuilder, P, false)) {
+ hubbub_ns ns;
element_type type;
void *node;
- if (!element_stack_pop(treebuilder, &type, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &type, &node)) {
/** \todo errors */
}
@@ -1195,9 +1201,10 @@
close_implied_end_tags(treebuilder, type);
do {
+ hubbub_ns ns;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
@@ -1239,9 +1246,11 @@
close_implied_end_tags(treebuilder, UNKNOWN);
do {
+ hubbub_ns ns;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype,
+ &node)) {
/** \todo errors */
}
@@ -1482,14 +1491,15 @@
}
if (fb > treebuilder->context.current_node) {
+ hubbub_ns ns;
element_type type;
void *node;
uint32_t index;
- /* Pop all elements off the stack up to,
+ /* Pop all elements off the stack up to,
* and including, the formatting element */
do {
- if (!element_stack_pop(treebuilder, &type, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &type, &node)) {
/** \todo errors */
}
@@ -1811,9 +1821,11 @@
close_implied_end_tags(treebuilder, UNKNOWN);
do {
+ hubbub_ns ns;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype,
+ &node)) {
/** \todo errors */
}
@@ -1878,10 +1890,11 @@
close_implied_end_tags(treebuilder, UNKNOWN);
do {
+ hubbub_ns ns;
void *node;
if (!element_stack_pop(treebuilder,
- &otype, &node)) {
+ &ns, &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_caption.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_caption...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_caption.c (original)
+++ trunk/hubbub/src/treebuilder/in_caption.c Thu Jun 26 13:19:49 2008
@@ -74,6 +74,7 @@
}
if (handled || reprocess) {
+ hubbub_ns ns;
element_type otype = UNKNOWN;
void *node;
@@ -85,7 +86,8 @@
while (otype != CAPTION) {
/** \todo parse error */
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype,
+ &node)) {
/** \todo errors */
}
}
Modified: trunk/hubbub/src/treebuilder/in_cell.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_cell.c?...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_cell.c (original)
+++ trunk/hubbub/src/treebuilder/in_cell.c Thu Jun 26 13:19:49 2008
@@ -21,9 +21,11 @@
*/
static inline void close_cell(hubbub_treebuilder *treebuilder)
{
+ hubbub_ns ns;
+ element_type otype = UNKNOWN;
void *node;
+
element_type type;
- element_type otype = UNKNOWN;
if (element_in_scope(treebuilder, TD, true)) {
type = TD;
@@ -37,7 +39,7 @@
/** \todo parse error */
while (otype != type) {
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
}
@@ -87,6 +89,7 @@
if (type == TH || TD) {
if (element_in_scope(treebuilder, type, true)) {
+ hubbub_ns ns;
element_type otype = UNKNOWN;
void *node;
@@ -95,7 +98,7 @@
while (otype != type) {
if (!element_stack_pop(treebuilder,
- &otype, &node)) {
+ &ns, &otype, &node)) {
/** \todo errors */
}
}
Modified: trunk/hubbub/src/treebuilder/in_column_group.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_column_...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_column_group.c (original)
+++ trunk/hubbub/src/treebuilder/in_column_group.c Thu Jun 26 13:19:49 2008
@@ -81,11 +81,12 @@
}
if (handled || reprocess) {
+ hubbub_ns ns;
element_type otype;
void *node;
/* Pop the current node (which will be a colgroup) */
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_head.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_head.c?...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_head.c (original)
+++ trunk/hubbub/src/treebuilder/in_head.c Thu Jun 26 13:19:49 2008
@@ -164,10 +164,11 @@
}
if (handled || reprocess) {
+ hubbub_ns ns;
element_type otype;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_head_noscript.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_head_no...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_head_noscript.c (original)
+++ trunk/hubbub/src/treebuilder/in_head_noscript.c Thu Jun 26 13:19:49 2008
@@ -81,10 +81,11 @@
}
if (handled || reprocess) {
+ hubbub_ns ns;
element_type otype;
void *node;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_row.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_row.c?r...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_row.c (original)
+++ trunk/hubbub/src/treebuilder/in_row.c Thu Jun 26 13:19:49 2008
@@ -25,10 +25,11 @@
treebuilder->context.current_node].type;
while (cur_node != TR && cur_node != HTML) {
+ hubbub_ns ns;
element_type type;
void *node;
- if (!element_stack_pop(treebuilder, &type, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &type, &node)) {
/** \todo errors */
}
@@ -48,13 +49,14 @@
*/
static inline bool act_as_if_end_tag_tr(hubbub_treebuilder *treebuilder)
{
+ hubbub_ns ns;
element_type otype;
void *node;
/** \todo fragment case */
table_clear_stack(treebuilder);
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_select.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_select....
==============================================================================
--- trunk/hubbub/src/treebuilder/in_select.c (original)
+++ trunk/hubbub/src/treebuilder/in_select.c Thu Jun 26 13:19:49 2008
@@ -26,6 +26,7 @@
{
bool reprocess = false;
+ hubbub_ns ns;
element_type otype;
void *node;
@@ -51,7 +52,7 @@
process_tag_in_body(treebuilder, token);
} else if (type == OPTION) {
if (current_node(treebuilder) == OPTION) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
@@ -60,14 +61,14 @@
insert_element(treebuilder, &token->data.tag);
} else if (type == OPTGROUP) {
if (current_node(treebuilder) == OPTION) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
}
if (current_node(treebuilder) == OPTGROUP) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
@@ -99,14 +100,14 @@
if (type == OPTGROUP) {
if (current_node(treebuilder) == OPTION &&
prev_node(treebuilder) == OPTGROUP) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
}
if (current_node(treebuilder) == OPTGROUP) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
@@ -115,7 +116,7 @@
}
} else if (type == OPTION) {
if (current_node(treebuilder) == OPTION) {
- if (!element_stack_pop(treebuilder, &otype,
+ if (!element_stack_pop(treebuilder, &ns, &otype,
&node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/in_table_body.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/in_table_b...
==============================================================================
--- trunk/hubbub/src/treebuilder/in_table_body.c (original)
+++ trunk/hubbub/src/treebuilder/in_table_body.c Thu Jun 26 13:19:49 2008
@@ -26,10 +26,11 @@
while (cur_node != TBODY && cur_node != TFOOT &&
cur_node != THEAD && cur_node != HTML) {
+ hubbub_ns ns;
element_type type;
void *node;
- if (!element_stack_pop(treebuilder, &type, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &type, &node)) {
/** \todo errors */
}
@@ -51,6 +52,7 @@
if (element_in_scope(treebuilder, TBODY, true) ||
element_in_scope(treebuilder, THEAD, true) ||
element_in_scope(treebuilder, TFOOT, true)) {
+ hubbub_ns ns;
element_type otype;
void *node;
@@ -59,7 +61,7 @@
/* "Act as if an end tag with the same name as the current
* node had been seen" -- this behaviour should be identical
* to handling for (tbody/tfoot/thead) end tags in this mode */
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
@@ -134,12 +136,13 @@
/** \todo parse error */
/* Ignore the token */
} else {
+ hubbub_ns ns;
element_type otype;
void *node;
table_clear_stack(treebuilder);
- if (!element_stack_pop(treebuilder, &otype,
- &node)) {
+ if (!element_stack_pop(treebuilder, &ns,
+ &otype, &node)) {
/** \todo errors */
}
Modified: trunk/hubbub/src/treebuilder/internal.h
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/internal.h...
==============================================================================
--- trunk/hubbub/src/treebuilder/internal.h (original)
+++ trunk/hubbub/src/treebuilder/internal.h Thu Jun 26 13:19:49 2008
@@ -33,6 +33,7 @@
typedef struct element_context
{
+ hubbub_ns ns;
element_type type;
void *node;
} element_context;
@@ -50,6 +51,7 @@
typedef struct hubbub_treebuilder_context
{
insertion_mode mode; /**< The current insertion mode */
+ insertion_mode second_mode; /**< The secondary insertion mode */
#define ELEMENT_STACK_CHUNK 128
element_context *element_stack; /**< Stack of open elements */
@@ -134,9 +136,9 @@
bool is_phrasing_element(element_type type);
bool element_stack_push(hubbub_treebuilder *treebuilder,
- element_type type, void *node);
+ hubbub_ns ns, element_type type, void *node);
bool element_stack_pop(hubbub_treebuilder *treebuilder,
- element_type *type, void **node);
+ hubbub_ns *ns, element_type *type, void **node);
bool element_stack_pop_until(hubbub_treebuilder *treebuilder,
element_type type);
element_type current_node(hubbub_treebuilder *treebuilder);
Modified: trunk/hubbub/src/treebuilder/treebuilder.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/treebuilde...
==============================================================================
--- trunk/hubbub/src/treebuilder/treebuilder.c (original)
+++ trunk/hubbub/src/treebuilder/treebuilder.c Thu Jun 26 13:19:49 2008
@@ -601,8 +601,9 @@
return;
}
- if (!element_stack_push(treebuilder,
- entry->details.type, appended)) {
+ if (!element_stack_push(treebuilder,
+ entry->details.ns, entry->details.type,
+ appended)) {
/** \todo handle memory exhaustion */
treebuilder->tree_handler->unref_node(
treebuilder->tree_handler->ctx,
@@ -612,10 +613,10 @@
clone);
}
- if (!formatting_list_replace(treebuilder, entry,
- entry->details.type, clone,
+ if (!formatting_list_replace(treebuilder, entry,
+ entry->details.type, clone,
treebuilder->context.current_node,
- &prev_type, &prev_node,
+ &prev_type, &prev_node,
&prev_stack_index)) {
/** \todo handle errors */
treebuilder->tree_handler->unref_node(
@@ -692,8 +693,9 @@
treebuilder->tree_handler->unref_node(treebuilder->tree_handler->ctx,
appended);
- if (!element_stack_push(treebuilder,
- element_type_from_name(treebuilder, &tag->name),
+ if (!element_stack_push(treebuilder,
+ tag->ns,
+ element_type_from_name(treebuilder, &tag->name),
node)) {
/** \todo errors */
}
@@ -750,13 +752,14 @@
while (type == DD || type == DT || type == LI || type == OPTION ||
type == OPTGROUP || type == P || type == RP ||
type == RT) {
+ hubbub_ns ns;
element_type otype;
void *node;
if (except != UNKNOWN && type == except)
break;
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo errors */
}
@@ -953,12 +956,13 @@
* Push an element onto the stack of open elements
*
* \param treebuilder The treebuilder instance containing the stack
+ * \param ns The namespace of element being pushed
* \param type The type of element being pushed
* \param node The node to push
* \return True on success, false on memory exhaustion
*/
bool element_stack_push(hubbub_treebuilder *treebuilder,
- element_type type, void *node)
+ hubbub_ns ns, element_type type, void *node)
{
uint32_t slot = treebuilder->context.current_node + 1;
@@ -977,6 +981,7 @@
treebuilder->context.stack_alloc += ELEMENT_STACK_CHUNK;
}
+ treebuilder->context.element_stack[slot].ns = ns;
treebuilder->context.element_stack[slot].type = type;
treebuilder->context.element_stack[slot].node = node;
@@ -998,7 +1003,7 @@
* \return True on success, false on memory exhaustion.
*/
bool element_stack_pop(hubbub_treebuilder *treebuilder,
- element_type *type, void **node)
+ hubbub_ns *ns, element_type *type, void **node)
{
element_context *stack = treebuilder->context.element_stack;
uint32_t slot = treebuilder->context.current_node;
@@ -1031,6 +1036,7 @@
}
}
+ *ns = stack[slot].ns;
*type = stack[slot].type;
*node = stack[slot].node;
@@ -1051,9 +1057,10 @@
{
element_type otype = UNKNOWN;
void *node;
+ hubbub_ns ns;
while (otype != type) {
- if (!element_stack_pop(treebuilder, &otype, &node)) {
+ if (!element_stack_pop(treebuilder, &ns, &otype, &node)) {
/** \todo error -- never happens */
return false;
}
14 years, 11 months
r4455 jmb - in /trunk/libcss: src/lex/lex.c src/lex/lex.h test/data/lex/tests2.dat test/lex-auto.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Jun 26 07:05:14 2008
New Revision: 4455
URL: http://source.netsurf-browser.org?rev=4455&view=rev
Log:
Correctly process unterminated strings.
Modified:
trunk/libcss/src/lex/lex.c
trunk/libcss/src/lex/lex.h
trunk/libcss/test/data/lex/tests2.dat
trunk/libcss/test/lex-auto.c
Modified: trunk/libcss/src/lex/lex.c
URL: http://source.netsurf-browser.org/trunk/libcss/src/lex/lex.c?rev=4455&r1=...
==============================================================================
--- trunk/libcss/src/lex/lex.c (original)
+++ trunk/libcss/src/lex/lex.c Thu Jun 26 07:05:14 2008
@@ -34,6 +34,7 @@
#include "lex/lex.h"
#include "utils/parserutilserror.h"
+#include "utils/utils.h"
/** \todo Optimisation -- we're currently revisiting a bunch of input
* characters (Currently, we're calling parserutils_inputstream_peek
@@ -379,7 +380,15 @@
t->data.ptr += 1;
t->data.len -= 1;
- /* Strip the trailing quote */
+ /* Strip the trailing quote, iff it exists (may have hit EOF) */
+ if (t->data.ptr[t->data.len - 1] == '"' ||
+ t->data.ptr[t->data.len - 1] == '\'') {
+ t->data.len -= 1;
+ }
+ break;
+ case CSS_TOKEN_INVALID_STRING:
+ /* Strip the leading quote */
+ t->data.ptr += 1;
t->data.len -= 1;
break;
case CSS_TOKEN_HASH:
@@ -396,8 +405,8 @@
break;
case CSS_TOKEN_URI:
/* Strip the "url(" from the start */
- t->data.ptr += sizeof("url(") - 1;
- t->data.len -= sizeof("url(") - 1;
+ t->data.ptr += SLEN("url(");
+ t->data.len -= SLEN("url(");
/* Strip any leading whitespace */
while (isSpace(t->data.ptr[0])) {
@@ -427,16 +436,16 @@
break;
case CSS_TOKEN_UNICODE_RANGE:
/* Remove "U+" from the start */
- t->data.ptr += sizeof("U+") - 1;
- t->data.len -= sizeof("U+") - 1;
+ t->data.ptr += SLEN("U+");
+ t->data.len -= SLEN("U+");
break;
case CSS_TOKEN_COMMENT:
/* Strip the leading '/' and '*' */
- t->data.ptr += sizeof("/*") - 1;
- t->data.len -= sizeof("/*") - 1;
+ t->data.ptr += SLEN("/*");
+ t->data.len -= SLEN("/*");
/* Strip the trailing '*' and '/' */
- t->data.len -= sizeof("*/") - 1;
+ t->data.len -= SLEN("*/");
break;
case CSS_TOKEN_FUNCTION:
/* Strip the trailing '(' */
@@ -1239,11 +1248,13 @@
*/
error = consumeString(lexer);
- if (error != CSS_OK && error != CSS_EOF)
+ if (error != CSS_OK && error != CSS_EOF && error != CSS_INVALID)
return error;
+ /* EOF will be reprocessed in Start() */
return emitToken(lexer,
- error == CSS_EOF ? CSS_TOKEN_EOF : CSS_TOKEN_STRING,
+ error == CSS_INVALID ? CSS_TOKEN_INVALID_STRING
+ : CSS_TOKEN_STRING,
token);
}
@@ -1450,8 +1461,14 @@
lexer->substate = String;
error = consumeString(lexer);
- if (error != CSS_OK && error != CSS_EOF)
+ if (error == CSS_INVALID) {
+ /* Rewind to "url(" */
+ lexer->bytesReadForToken = lexer->context.bytesForURL;
+ lexer->token.data.len = lexer->context.dataLenForURL;
+ return emitToken(lexer, CSS_TOKEN_FUNCTION, token);
+ } else if (error != CSS_OK && error != CSS_EOF) {
return error;
+ }
/* EOF gets handled in RParen */
@@ -1794,12 +1811,6 @@
* The open quote has been consumed.
*/
- /** \todo Handle unexpected end of string correctly - CSS 2.1 $4.2
- * Need to flag the string as being in error (within token, so the
- * parser can discard the construct in which the string was found).
- * This does not apply in the EOF case. In that case, we must act
- * as described in "Unexpected end of style sheet" and simply close
- * the string */
do {
cptr = parserutils_inputstream_peek(lexer->input,
lexer->bytesReadForToken, &clen);
@@ -1818,8 +1829,8 @@
if (error != CSS_OK)
return error;
} else if (c != quote) {
- /* Invalid character in string -- skip */
- lexer->bytesReadForToken += clen;
+ /* Invalid character in string */
+ return CSS_INVALID;
}
} while(c != quote);
Modified: trunk/libcss/src/lex/lex.h
URL: http://source.netsurf-browser.org/trunk/libcss/src/lex/lex.h?rev=4455&r1=...
==============================================================================
--- trunk/libcss/src/lex/lex.h (original)
+++ trunk/libcss/src/lex/lex.h Thu Jun 26 07:05:14 2008
@@ -33,13 +33,13 @@
* Token type
*/
typedef enum css_token_type {
- CSS_TOKEN_IDENT, CSS_TOKEN_ATKEYWORD, CSS_TOKEN_STRING,
- CSS_TOKEN_HASH, CSS_TOKEN_NUMBER, CSS_TOKEN_PERCENTAGE,
- CSS_TOKEN_DIMENSION, CSS_TOKEN_URI, CSS_TOKEN_UNICODE_RANGE,
- CSS_TOKEN_CDO, CSS_TOKEN_CDC, CSS_TOKEN_S, CSS_TOKEN_COMMENT,
- CSS_TOKEN_FUNCTION, CSS_TOKEN_INCLUDES, CSS_TOKEN_DASHMATCH,
- CSS_TOKEN_PREFIXMATCH, CSS_TOKEN_SUFFIXMATCH, CSS_TOKEN_SUBSTRINGMATCH,
- CSS_TOKEN_CHAR, CSS_TOKEN_EOF
+ CSS_TOKEN_IDENT, CSS_TOKEN_ATKEYWORD, CSS_TOKEN_STRING,
+ CSS_TOKEN_INVALID_STRING, CSS_TOKEN_HASH, CSS_TOKEN_NUMBER,
+ CSS_TOKEN_PERCENTAGE, CSS_TOKEN_DIMENSION, CSS_TOKEN_URI,
+ CSS_TOKEN_UNICODE_RANGE, CSS_TOKEN_CDO, CSS_TOKEN_CDC, CSS_TOKEN_S,
+ CSS_TOKEN_COMMENT, CSS_TOKEN_FUNCTION, CSS_TOKEN_INCLUDES,
+ CSS_TOKEN_DASHMATCH, CSS_TOKEN_PREFIXMATCH, CSS_TOKEN_SUFFIXMATCH,
+ CSS_TOKEN_SUBSTRINGMATCH, CSS_TOKEN_CHAR, CSS_TOKEN_EOF
} css_token_type;
/**
Modified: trunk/libcss/test/data/lex/tests2.dat
URL: http://source.netsurf-browser.org/trunk/libcss/test/data/lex/tests2.dat?r...
==============================================================================
--- trunk/libcss/test/data/lex/tests2.dat (original)
+++ trunk/libcss/test/data/lex/tests2.dat Thu Jun 26 07:05:14 2008
@@ -27,3 +27,89 @@
S
EOF
#reset
+
+#data
+@import url("abcde
+);
+#expected
+ATKEYWORD:import
+S
+FUNCTION:url
+INVALID:abcde
+S
+CHAR:)
+CHAR:;
+S
+EOF
+#reset
+
+#data
+body {
+ font-family: "Bitstream Vera Sans;
+}
+.one { width: 10em; }
+#expected
+IDENT:body
+S
+CHAR:{
+S
+IDENT:font-family
+CHAR::
+S
+INVALID:Bitstream Vera Sans;
+S
+CHAR:}
+S
+CHAR:.
+IDENT:one
+S
+CHAR:{
+S
+IDENT:width
+CHAR::
+S
+DIMENSION:10em
+CHAR:;
+S
+CHAR:}
+S
+EOF
+#reset
+
+#data
+body { font-family: "Bitstream Vera Sans; }
+.two { width: 10em; }
+#expected
+IDENT:body
+S
+CHAR:{
+S
+IDENT:font-family
+CHAR::
+S
+INVALID:Bitstream Vera Sans; }
+S
+CHAR:.
+IDENT:two
+S
+CHAR:{
+S
+IDENT:width
+CHAR::
+S
+DIMENSION:10em
+CHAR:;
+S
+CHAR:}
+S
+EOF
+#reset
+
+#data
+"abcde
+#expected
+INVALID:abcde
+S
+EOF
+#reset
+
Modified: trunk/libcss/test/lex-auto.c
URL: http://source.netsurf-browser.org/trunk/libcss/test/lex-auto.c?rev=4455&r...
==============================================================================
--- trunk/libcss/test/lex-auto.c (original)
+++ trunk/libcss/test/lex-auto.c Thu Jun 26 07:05:14 2008
@@ -204,7 +204,7 @@
{
const char *names[] =
{
- "IDENT", "ATKEYWORD", "STRING", "HASH", "NUMBER",
+ "IDENT", "ATKEYWORD", "STRING", "INVALID", "HASH", "NUMBER",
"PERCENTAGE", "DIMENSION", "URI", "UNICODE-RANGE", "CDO",
"CDC", "S", "COMMENT", "FUNCTION", "INCLUDES",
"DASHMATCH", "PREFIXMATCH", "SUFFIXMATCH", "SUBSTRINGMATCH",
@@ -222,6 +222,8 @@
return CSS_TOKEN_ATKEYWORD;
else if (len == 6 && strncasecmp(data, "STRING", len) == 0)
return CSS_TOKEN_STRING;
+ else if (len == 7 && strncasecmp(data, "INVALID", len) == 0)
+ return CSS_TOKEN_INVALID_STRING;
else if (len == 4 && strncasecmp(data, "HASH", len) == 0)
return CSS_TOKEN_HASH;
else if (len == 6 && strncasecmp(data, "NUMBER", len) == 0)
14 years, 11 months
r4454 takkaria - in /trunk/hubbub/src: treebuilder/internal.h treebuilder/treebuilder.c utils/Makefile utils/string.c utils/string.h
by netsurf@semichrome.net
Author: takkaria
Date: Thu Jun 26 04:19:59 2008
New Revision: 4454
URL: http://source.netsurf-browser.org?rev=4454&view=rev
Log:
Add code to adjust foreign attributes, as per spec.
Added:
trunk/hubbub/src/utils/string.c (with props)
trunk/hubbub/src/utils/string.h (with props)
Modified:
trunk/hubbub/src/treebuilder/internal.h
trunk/hubbub/src/treebuilder/treebuilder.c
trunk/hubbub/src/utils/Makefile
Modified: trunk/hubbub/src/treebuilder/internal.h
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/internal.h...
==============================================================================
--- trunk/hubbub/src/treebuilder/internal.h (original)
+++ trunk/hubbub/src/treebuilder/internal.h Thu Jun 26 04:19:59 2008
@@ -155,6 +155,9 @@
element_type type, void *node, uint32_t stack_index,
element_type *otype, void **onode, uint32_t *ostack_index);
+void adjust_foreign_attributes(hubbub_treebuilder *treebuilder,
+ hubbub_tag *tag);
+
#ifndef NDEBUG
#include <stdio.h>
Modified: trunk/hubbub/src/treebuilder/treebuilder.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/treebuilder/treebuilde...
==============================================================================
--- trunk/hubbub/src/treebuilder/treebuilder.c (original)
+++ trunk/hubbub/src/treebuilder/treebuilder.c Thu Jun 26 04:19:59 2008
@@ -12,7 +12,7 @@
#include "treebuilder/internal.h"
#include "treebuilder/treebuilder.h"
#include "utils/utils.h"
-
+#include "utils/string.h"
static const struct {
const char *name;
@@ -1242,6 +1242,75 @@
return true;
}
+/**
+ * Adjust foreign attributes.
+ *
+ * \param treebuilder Treebuilder instance
+ * \param tag Tag to adjust the attributes of
+ */
+void adjust_foreign_attributes(hubbub_treebuilder *treebuilder,
+ hubbub_tag *tag)
+{
+ for (size_t i = 0; i < tag->n_attributes; i++) {
+ hubbub_attribute *attr = &tag->attributes[i];
+ const uint8_t *name = treebuilder->input_buffer +
+ attr->name.data.off;
+
+#define S(s) (uint8_t *) s, SLEN(s)
+
+ /* 10 == strlen("xlink:href") */
+ if (attr->name.len >= 10 &&
+ strncmp((char *) name, "xlink:",
+ SLEN("xlink:")) == 0) {
+ size_t len = attr->name.len - 6;
+ name += 6;
+
+ if (hubbub_string_match(name, len, S("actutate")) ||
+ hubbub_string_match(name, len,
+ S("arcrole")) ||
+ hubbub_string_match(name, len,
+ S("href")) ||
+ hubbub_string_match(name, len,
+ S("role")) ||
+ hubbub_string_match(name, len,
+ S("show")) ||
+ hubbub_string_match(name, len,
+ S("title")) ||
+ hubbub_string_match(name, len,
+ S("type"))) {
+ attr->ns = HUBBUB_NS_XLINK;
+ attr->name.data.off += 6;
+ attr->name.len -= 6;
+ }
+ /* 8 == strlen("xml:base") */
+ } else if (attr->name.len >= 8 &&
+ strncmp((char *) name, "xml:", SLEN("xml:")) == 0) {
+ size_t len = attr->name.len - 4;
+ name += 4;
+
+ if (hubbub_string_match(name, len, S("base")) ||
+ hubbub_string_match(name, len,
+ S("lang")) ||
+ hubbub_string_match(name, len,
+ S("space"))) {
+ attr->ns = HUBBUB_NS_XML;
+ attr->name.data.off += 4;
+ attr->name.len -= 4;
+ }
+ } else if (hubbub_string_match(name, attr->name.len,
+ S("xmlns")) ||
+ hubbub_string_match(name, attr->name.len,
+ S("xmlns:xlink"))) {
+ attr->ns = HUBBUB_NS_XMLNS;
+ attr->name.data.off += 6;
+ attr->name.len -= 6;
+ }
+
+#undef S
+ }
+}
+
+
#ifndef NDEBUG
static const char *element_type_to_name(element_type type);
Modified: trunk/hubbub/src/utils/Makefile
URL: http://source.netsurf-browser.org/trunk/hubbub/src/utils/Makefile?rev=445...
==============================================================================
--- trunk/hubbub/src/utils/Makefile (original)
+++ trunk/hubbub/src/utils/Makefile Thu Jun 26 04:19:59 2008
@@ -32,7 +32,7 @@
d := $(DIR)
# Sources
-SRCS_$(d) := dict.c errors.c utf8.c utf16.c
+SRCS_$(d) := dict.c errors.c utf8.c utf16.c string.c
# Append to sources for component
SOURCES += $(addprefix $(d), $(SRCS_$(d)))
Added: trunk/hubbub/src/utils/string.c
URL: http://source.netsurf-browser.org/trunk/hubbub/src/utils/string.c?rev=445...
==============================================================================
--- trunk/hubbub/src/utils/string.c (added)
+++ trunk/hubbub/src/utils/string.c Thu Jun 26 04:19:59 2008
@@ -1,0 +1,62 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 Andrew Sidwell
+ */
+
+#include <stddef.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include "utils/string.h"
+
+
+/**
+ * Check if one string starts with another.
+ *
+ * \param a String to compare
+ * \param a_len Length of first string
+ * \param b String to compare
+ * \param b_len Length of second string
+ */
+bool hubbub_string_starts(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len)
+{
+ uint8_t z1, z2;
+
+ if (a_len < b_len)
+ return false;
+
+ for (const uint8_t *s1 = a, *s2 = b; b_len > 0; s1++, s2++, b_len--)
+ {
+ z1 = *s1;
+ z2 = *s2;
+ if (z1 != z2) return false;
+ if (!z1) return true;
+ }
+
+ return true;
+}
+
+/**
+ * Check that one string is exactly equal to another
+ *
+ * \param a String to compare
+ * \param a_len Length of first string
+ * \param b String to compare
+ * \param b_len Length of second string
+ */
+bool hubbub_string_match(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len)
+{
+ if (a_len != b_len)
+ return false;
+
+ for (const uint8_t *s1 = a, *s2 = b; b_len > 0; s1++, s2++, b_len--)
+ {
+ if (*s1 != *s2) return false;
+ }
+
+ return true;
+}
+
Propchange: trunk/hubbub/src/utils/string.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/hubbub/src/utils/string.h
URL: http://source.netsurf-browser.org/trunk/hubbub/src/utils/string.h?rev=445...
==============================================================================
--- trunk/hubbub/src/utils/string.h (added)
+++ trunk/hubbub/src/utils/string.h Thu Jun 26 04:19:59 2008
@@ -1,0 +1,16 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 Andrew Sidwell
+ */
+
+#ifndef hubbub_string_h_
+#define hubbub_string_h_
+
+bool hubbub_string_starts(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len);
+bool hubbub_string_match(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len);
+
+#endif
Propchange: trunk/hubbub/src/utils/string.h
------------------------------------------------------------------------------
svn:eol-style = native
14 years, 11 months
r4453 takkaria - /trunk/hubbub/include/hubbub/types.h
by netsurf@semichrome.net
Author: takkaria
Date: Thu Jun 26 04:18:52 2008
New Revision: 4453
URL: http://source.netsurf-browser.org?rev=4453&view=rev
Log:
Add namespaces to attributes, too.
Modified:
trunk/hubbub/include/hubbub/types.h
Modified: trunk/hubbub/include/hubbub/types.h
URL: http://source.netsurf-browser.org/trunk/hubbub/include/hubbub/types.h?rev...
==============================================================================
--- trunk/hubbub/include/hubbub/types.h (original)
+++ trunk/hubbub/include/hubbub/types.h Thu Jun 26 04:18:52 2008
@@ -54,6 +54,18 @@
} hubbub_token_type;
/**
+ * Possible namespaces
+ */
+typedef enum hubbub_ns {
+ HUBBUB_NS_HTML,
+ HUBBUB_NS_MATHML,
+ HUBBUB_NS_SVG,
+ HUBBUB_NS_XLINK,
+ HUBBUB_NS_XML,
+ HUBBUB_NS_XMLNS
+} hubbub_ns;
+
+/**
* Tokeniser string type
*/
typedef struct hubbub_string {
@@ -74,6 +86,7 @@
* Tag attribute data
*/
typedef struct hubbub_attribute {
+ hubbub_ns ns; /**< Attribute namespace */
hubbub_string name; /**< Attribute name */
hubbub_string value; /**< Attribute value */
} hubbub_attribute;
@@ -92,18 +105,6 @@
bool force_quirks; /**< Doctype force-quirks flag */
} hubbub_doctype;
-
-/**
- * Possible namespaces
- */
-typedef enum hubbub_ns {
- HUBBUB_NS_HTML,
- HUBBUB_NS_MATHML,
- HUBBUB_NS_SVG,
- HUBBUB_NS_XLINK,
- HUBBUB_NS_XML,
- HUBBUB_NS_XMLNS
-} hubbub_ns;
/**
* Data for a tag
14 years, 11 months