@@ -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); | |||
} | |||
@@ -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 | |||
@@ -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__ */ |
@@ -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); | |||
} | |||
@@ -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 "</span>" */ | |||
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, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION); | |||
@@ -100,8 +100,8 @@ void _cucul_get_html(cucul_t *qq, struct cucul_export *ex) | |||
cur += sprintf(cur, "</div></body></html>\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 "</font></td>" */ | |||
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, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", | |||
@@ -185,8 +185,8 @@ void _cucul_get_html3(cucul_t *qq, struct cucul_export *ex) | |||
cur += sprintf(cur, "</table>\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); | |||
} | |||
@@ -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); | |||
} |
@@ -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); | |||
} | |||
@@ -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, "</svg>\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); | |||
} | |||
@@ -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; | |||
@@ -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); | |||
@@ -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); | |||