From 41d475589cf7857bbaf46e5eb69bbfabbacc5281 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 13 Apr 2006 12:50:41 +0000 Subject: [PATCH] * Renamed cucul_export into cucul_buffer. We'll use it for other things. --- cucul/cucul.c | 12 ++++++------ cucul/cucul.h | 16 ++++++++-------- cucul/cucul_internals.h | 12 ++++++------ cucul/export_ansi.c | 10 +++++----- cucul/export_html.c | 20 ++++++++++---------- cucul/export_irc.c | 10 +++++----- cucul/export_ps.c | 10 +++++----- cucul/export_svg.c | 10 +++++----- src/cacaserver.c | 10 +++++----- src/img2irc.c | 4 ++-- test/export.c | 4 ++-- 11 files changed, 59 insertions(+), 59 deletions(-) diff --git a/cucul/cucul.c b/cucul/cucul.c index c8482ef..721ddd4 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -224,11 +224,11 @@ void cucul_free(cucul_t *qq) free(qq); } -struct cucul_export * cucul_create_export(cucul_t *qq, char const *format) +struct cucul_buffer * cucul_create_export(cucul_t *qq, char const *format) { - struct cucul_export *ex; + struct cucul_buffer *ex; - ex = malloc(sizeof(struct cucul_export)); + ex = malloc(sizeof(struct cucul_buffer)); if(!strcasecmp("ansi", format)) _cucul_get_ansi(qq, ex); @@ -256,7 +256,7 @@ struct cucul_export * cucul_create_export(cucul_t *qq, char const *format) * * Return a list of available export formats. The list is a NULL-terminated * array of strings, interleaving a string containing the internal value for - * the export format, to be used with \e cucul_export(), and a string + * the export format, to be used with \e cucul_create_export(), and a string * containing the natural language description for that export format. * * \return An array of strings. @@ -277,9 +277,9 @@ char const * const * cucul_get_export_list(void) return list; } -void cucul_free_export(struct cucul_export *ex) +void cucul_free_export(struct cucul_buffer *ex) { - free(ex->buffer); + free(ex->data); free(ex); } diff --git a/cucul/cucul.h b/cucul/cucul.h index 9218508..d1acf26 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -30,6 +30,12 @@ extern "C" typedef struct cucul_context cucul_t; +struct cucul_buffer +{ + unsigned int size; + char *data; +}; + /** \defgroup colour Colour definitions * * Colours that can be used with cucul_set_color(). @@ -194,15 +200,9 @@ void cucul_free_font(struct cucul_font *); * is necessary to call cucul_free_export() to dispose of the data. * * @{ */ -struct cucul_export -{ - unsigned int size; - char *buffer; -}; - -struct cucul_export * cucul_create_export(cucul_t *, char const *); +struct cucul_buffer * cucul_create_export(cucul_t *, char const *); char const * const * cucul_get_export_list(void); -void cucul_free_export(struct cucul_export *); +void cucul_free_export(struct cucul_buffer *); /* @} */ #ifdef __cplusplus diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index 341bda8..f50fc5e 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -68,11 +68,11 @@ uint8_t _cucul_argb32_to_ansi4bg(uint32_t); void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]); /* Export functions */ -extern void _cucul_get_ansi(cucul_t *, struct cucul_export *); -extern void _cucul_get_html(cucul_t *, struct cucul_export *); -extern void _cucul_get_html3(cucul_t *, struct cucul_export *); -extern void _cucul_get_irc(cucul_t *, struct cucul_export *); -extern void _cucul_get_ps(cucul_t *, struct cucul_export *); -extern void _cucul_get_svg(cucul_t *, struct cucul_export *); +extern void _cucul_get_ansi(cucul_t *, struct cucul_buffer *); +extern void _cucul_get_html(cucul_t *, struct cucul_buffer *); +extern void _cucul_get_html3(cucul_t *, struct cucul_buffer *); +extern void _cucul_get_irc(cucul_t *, struct cucul_buffer *); +extern void _cucul_get_ps(cucul_t *, struct cucul_buffer *); +extern void _cucul_get_svg(cucul_t *, struct cucul_buffer *); #endif /* __CUCUL_INTERNALS_H__ */ diff --git a/cucul/export_ansi.c b/cucul/export_ansi.c index db77ecc..f04a2a8 100644 --- a/cucul/export_ansi.c +++ b/cucul/export_ansi.c @@ -37,7 +37,7 @@ * able to cut/paste the result to a function like printf * \return buffer containing generated ANSI codes as a big string */ -void _cucul_get_ansi(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_ansi(cucul_t *qq, struct cucul_buffer *ex) { static int const palette[] = { @@ -52,9 +52,9 @@ void _cucul_get_ansi(cucul_t *qq, struct cucul_export *ex) * 4 max bytes for a UTF-8 character). * Add height*9 to that (zeroes color at the end and jump to next line) */ ex->size = (qq->height * 9) + (qq->width * qq->height * 23); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; for(y = 0; y < qq->height; y++) { @@ -99,7 +99,7 @@ void _cucul_get_ansi(cucul_t *qq, struct cucul_export *ex) } /* Crop to really used size */ - ex->size = (uintptr_t)(cur - ex->buffer); - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = (uintptr_t)(cur - ex->data); + ex->data = realloc(ex->data, ex->size); } diff --git a/cucul/export_html.c b/cucul/export_html.c index 79a26a5..f6daacd 100644 --- a/cucul/export_html.c +++ b/cucul/export_html.c @@ -34,7 +34,7 @@ * This function generates and returns the HTML representation of * the current image. */ -void _cucul_get_html(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_html(cucul_t *qq, struct cucul_buffer *ex) { static int const palette[] = { @@ -50,9 +50,9 @@ void _cucul_get_html(cucul_t *qq, struct cucul_export *ex) * up to 9 chars for "&#xxxxxx;", far less for pure ASCII * 7 chars for "" */ ex->size = 13000 + qq->height * (7 + qq->width * (18 + 9 + 7)); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; /* HTML header */ cur += sprintf(cur, "\n\nGenerated by libcaca %s\n", VERSION); @@ -100,8 +100,8 @@ void _cucul_get_html(cucul_t *qq, struct cucul_export *ex) cur += sprintf(cur, "\n"); /* Crop to really used size */ - ex->size = strlen(ex->buffer) + 1; - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = strlen(ex->data) + 1; + ex->data = realloc(ex->data, ex->size); } @@ -113,7 +113,7 @@ void _cucul_get_html(cucul_t *qq, struct cucul_export *ex) * Won't work under gecko (mozilla rendering engine) unless you set * a correct header. */ -void _cucul_get_html3(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_html3(cucul_t *qq, struct cucul_buffer *ex) { static int const palette[] = { @@ -132,9 +132,9 @@ void _cucul_get_html3(cucul_t *qq, struct cucul_export *ex) * up to 9 chars for "&#xxxxxx;", far less for pure ASCII * 12 chars for "" */ ex->size = 13000 + qq->height * (10 + qq->width * (40 + 9 + 12)); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; /* Table */ cur += sprintf(cur, "\n", @@ -185,8 +185,8 @@ void _cucul_get_html3(cucul_t *qq, struct cucul_export *ex) cur += sprintf(cur, "
\n"); /* Crop to really used size */ - ex->size = (uintptr_t)(cur - ex->buffer); - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = (uintptr_t)(cur - ex->data); + ex->data = realloc(ex->data, ex->size); } diff --git a/cucul/export_irc.c b/cucul/export_irc.c index 83eff3b..9851e05 100644 --- a/cucul/export_irc.c +++ b/cucul/export_irc.c @@ -34,7 +34,7 @@ * This function generates and returns an IRC representation of * the current image. */ -void _cucul_get_irc(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_irc(cucul_t *qq, struct cucul_buffer *ex) { static int const palette[] = { @@ -54,9 +54,9 @@ void _cucul_get_irc(cucul_t *qq, struct cucul_export *ex) */ ex->size = 2 + (qq->width * qq->height * 11); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; for(y = 0; y < qq->height; y++) { @@ -104,6 +104,6 @@ void _cucul_get_irc(cucul_t *qq, struct cucul_export *ex) } /* Crop to really used size */ - ex->size = (uintptr_t)(cur - ex->buffer); - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = (uintptr_t)(cur - ex->data); + ex->data = realloc(ex->data, ex->size); } diff --git a/cucul/export_ps.c b/cucul/export_ps.c index 76632b3..2ebd1c5 100644 --- a/cucul/export_ps.c +++ b/cucul/export_ps.c @@ -59,7 +59,7 @@ static char const *ps_header = * This function generates and returns a Postscript representation of * the current image. */ -void _cucul_get_ps(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex) { static char const * const palette[] = { @@ -75,9 +75,9 @@ void _cucul_get_ps(cucul_t *qq, struct cucul_export *ex) /* 200 is arbitrary but should be ok */ ex->size = strlen(ps_header) + (qq->width * qq->height * 200); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; /* Header */ cur += sprintf(cur, "%s", ps_header); @@ -134,7 +134,7 @@ void _cucul_get_ps(cucul_t *qq, struct cucul_export *ex) cur += sprintf(cur, "showpage\n"); /* Crop to really used size */ - ex->size = (uintptr_t)(cur - ex->buffer); - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = (uintptr_t)(cur - ex->data); + ex->data = realloc(ex->data, ex->size); } diff --git a/cucul/export_svg.c b/cucul/export_svg.c index f0f0f4e..9ab6fca 100644 --- a/cucul/export_svg.c +++ b/cucul/export_svg.c @@ -44,7 +44,7 @@ static char const svg_header[] = * This function generates and returns a SVG representation of * the current image. */ -void _cucul_get_svg(cucul_t *qq, struct cucul_export *ex) +void _cucul_get_svg(cucul_t *qq, struct cucul_buffer *ex) { static int const palette[] = { @@ -59,9 +59,9 @@ void _cucul_get_svg(cucul_t *qq, struct cucul_export *ex) /* 200 is arbitrary but should be ok */ ex->size = strlen(svg_header) + (qq->width * qq->height * 200); - ex->buffer = malloc(ex->size); + ex->data = malloc(ex->size); - cur = ex->buffer; + cur = ex->data; /* Header */ cur += sprintf(cur, svg_header, qq->width * 6, qq->height * 10, @@ -146,7 +146,7 @@ void _cucul_get_svg(cucul_t *qq, struct cucul_export *ex) cur += sprintf(cur, "\n"); /* Crop to really used size */ - ex->size = (uintptr_t)(cur - ex->buffer); - ex->buffer = realloc(ex->buffer, ex->size); + ex->size = (uintptr_t)(cur - ex->data); + ex->data = realloc(ex->data, ex->size); } diff --git a/src/cacaserver.c b/src/cacaserver.c index 5c61538..6754b83 100644 --- a/src/cacaserver.c +++ b/src/cacaserver.c @@ -103,7 +103,7 @@ struct server char prefix[sizeof(INIT_PREFIX)]; cucul_t *qq; - struct cucul_export *ex; + struct cucul_buffer *ex; int client_count; struct client *clients; @@ -438,7 +438,7 @@ static int send_data(struct server *server, struct client *c) memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX)); c->stop += strlen(ANSI_PREFIX); - memcpy(c->outbuf + c->stop, server->ex->buffer, server->ex->size); + memcpy(c->outbuf + c->stop, server->ex->data, server->ex->size); c->stop += server->ex->size; return 0; @@ -470,14 +470,14 @@ static int send_data(struct server *server, struct client *c) memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret); c->stop = strlen(ANSI_PREFIX) - ret; - memcpy(c->outbuf + c->stop, server->ex->buffer, server->ex->size); + memcpy(c->outbuf + c->stop, server->ex->data, server->ex->size); c->stop += server->ex->size; return 0; } /* Send actual data */ - ret = nonblock_write(c->fd, server->ex->buffer, server->ex->size); + ret = nonblock_write(c->fd, server->ex->data, server->ex->size); if(ret == -1) { if(errno == EAGAIN) @@ -497,7 +497,7 @@ static int send_data(struct server *server, struct client *c) return 0; } - memcpy(c->outbuf, server->ex->buffer, server->ex->size - ret); + memcpy(c->outbuf, server->ex->data, server->ex->size - ret); c->stop = server->ex->size - ret; return 0; diff --git a/src/img2irc.c b/src/img2irc.c index 23ac1f1..4c9f3b6 100644 --- a/src/img2irc.c +++ b/src/img2irc.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) { /* libcucul context */ cucul_t *qq; - struct cucul_export *export; + struct cucul_buffer *export; struct image *i; int cols = 56, lines; @@ -59,7 +59,7 @@ int main(int argc, char **argv) unload_image(i); export = cucul_create_export(qq, "irc"); - fwrite(export->buffer, export->size, 1, stdout); + fwrite(export->data, export->size, 1, stdout); cucul_free_export(export); cucul_free(qq); diff --git a/test/export.c b/test/export.c index 299d3bb..10f213a 100644 --- a/test/export.c +++ b/test/export.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) { cucul_t *qq; struct cucul_dither *dither; - struct cucul_export *buffer; + struct cucul_buffer *buffer; int x, y; if(argc != 2) @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); buffer = cucul_create_export(qq, argv[1]); - fwrite(buffer->buffer, buffer->size, 1, stdout); + fwrite(buffer->data, buffer->size, 1, stdout); cucul_free_export(buffer); cucul_free(qq);