Browse Source

* Renamed cucul_export into cucul_buffer. We'll use it for other things.

tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
41d475589c
11 changed files with 59 additions and 59 deletions
  1. +6
    -6
      cucul/cucul.c
  2. +8
    -8
      cucul/cucul.h
  3. +6
    -6
      cucul/cucul_internals.h
  4. +5
    -5
      cucul/export_ansi.c
  5. +10
    -10
      cucul/export_html.c
  6. +5
    -5
      cucul/export_irc.c
  7. +5
    -5
      cucul/export_ps.c
  8. +5
    -5
      cucul/export_svg.c
  9. +5
    -5
      src/cacaserver.c
  10. +2
    -2
      src/img2irc.c
  11. +2
    -2
      test/export.c

+ 6
- 6
cucul/cucul.c View File

@@ -224,11 +224,11 @@ void cucul_free(cucul_t *qq)
free(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)) if(!strcasecmp("ansi", format))
_cucul_get_ansi(qq, ex); _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 * Return a list of available export formats. The list is a NULL-terminated
* array of strings, interleaving a string containing the internal value for * 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. * containing the natural language description for that export format.
* *
* \return An array of strings. * \return An array of strings.
@@ -277,9 +277,9 @@ char const * const * cucul_get_export_list(void)
return list; 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); free(ex);
} }




+ 8
- 8
cucul/cucul.h View File

@@ -30,6 +30,12 @@ extern "C"


typedef struct cucul_context cucul_t; typedef struct cucul_context cucul_t;


struct cucul_buffer
{
unsigned int size;
char *data;
};

/** \defgroup colour Colour definitions /** \defgroup colour Colour definitions
* *
* Colours that can be used with cucul_set_color(). * 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. * 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); char const * const * cucul_get_export_list(void);
void cucul_free_export(struct cucul_export *);
void cucul_free_export(struct cucul_buffer *);
/* @} */ /* @} */


#ifdef __cplusplus #ifdef __cplusplus


+ 6
- 6
cucul/cucul_internals.h View File

@@ -68,11 +68,11 @@ uint8_t _cucul_argb32_to_ansi4bg(uint32_t);
void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]); void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]);


/* Export functions */ /* 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__ */ #endif /* __CUCUL_INTERNALS_H__ */

+ 5
- 5
cucul/export_ansi.c View File

@@ -37,7 +37,7 @@
* able to cut/paste the result to a function like printf * able to cut/paste the result to a function like printf
* \return buffer containing generated ANSI codes as a big string * \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[] = 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). * 4 max bytes for a UTF-8 character).
* Add height*9 to that (zeroes color at the end and jump to next line) */ * 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->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++) 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 */ /* 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);
} }



+ 10
- 10
cucul/export_html.c View File

@@ -34,7 +34,7 @@
* This function generates and returns the HTML representation of * This function generates and returns the HTML representation of
* the current image. * 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[] = 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 * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
* 7 chars for "</span>" */ * 7 chars for "</span>" */
ex->size = 13000 + qq->height * (7 + qq->width * (18 + 9 + 7)); 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 */ /* HTML header */
cur += sprintf(cur, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION); 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"); cur += sprintf(cur, "</div></body></html>\n");


/* Crop to really used size */ /* 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 * Won't work under gecko (mozilla rendering engine) unless you set
* a correct header. * 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[] = 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 * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
* 12 chars for "</font></td>" */ * 12 chars for "</font></td>" */
ex->size = 13000 + qq->height * (10 + qq->width * (40 + 9 + 12)); 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 */ /* Table */
cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", 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"); cur += sprintf(cur, "</table>\n");


/* Crop to really used size */ /* 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);
} }





+ 5
- 5
cucul/export_irc.c View File

@@ -34,7 +34,7 @@
* This function generates and returns an IRC representation of * This function generates and returns an IRC representation of
* the current image. * 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[] = 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->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++) 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 */ /* 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);
} }

+ 5
- 5
cucul/export_ps.c View File

@@ -59,7 +59,7 @@ static char const *ps_header =
* This function generates and returns a Postscript representation of * This function generates and returns a Postscript representation of
* the current image. * 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[] = 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 */ /* 200 is arbitrary but should be ok */
ex->size = strlen(ps_header) + (qq->width * qq->height * 200); 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 */ /* Header */
cur += sprintf(cur, "%s", ps_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"); cur += sprintf(cur, "showpage\n");


/* Crop to really used size */ /* 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);
} }



+ 5
- 5
cucul/export_svg.c View File

@@ -44,7 +44,7 @@ static char const svg_header[] =
* This function generates and returns a SVG representation of * This function generates and returns a SVG representation of
* the current image. * 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[] = 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 */ /* 200 is arbitrary but should be ok */
ex->size = strlen(svg_header) + (qq->width * qq->height * 200); 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 */ /* Header */
cur += sprintf(cur, svg_header, qq->width * 6, qq->height * 10, 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"); cur += sprintf(cur, "</svg>\n");


/* Crop to really used size */ /* 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);
} }



+ 5
- 5
src/cacaserver.c View File

@@ -103,7 +103,7 @@ struct server
char prefix[sizeof(INIT_PREFIX)]; char prefix[sizeof(INIT_PREFIX)];


cucul_t *qq; cucul_t *qq;
struct cucul_export *ex;
struct cucul_buffer *ex;


int client_count; int client_count;
struct client *clients; 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)); memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX));
c->stop += 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; c->stop += server->ex->size;


return 0; 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); memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret);
c->stop = 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; c->stop += server->ex->size;


return 0; return 0;
} }


/* Send actual data */ /* 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(ret == -1)
{ {
if(errno == EAGAIN) if(errno == EAGAIN)
@@ -497,7 +497,7 @@ static int send_data(struct server *server, struct client *c)
return 0; 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; c->stop = server->ex->size - ret;


return 0; return 0;


+ 2
- 2
src/img2irc.c View File

@@ -24,7 +24,7 @@ int main(int argc, char **argv)
{ {
/* libcucul context */ /* libcucul context */
cucul_t *qq; cucul_t *qq;
struct cucul_export *export;
struct cucul_buffer *export;
struct image *i; struct image *i;
int cols = 56, lines; int cols = 56, lines;


@@ -59,7 +59,7 @@ int main(int argc, char **argv)
unload_image(i); unload_image(i);


export = cucul_create_export(qq, "irc"); 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_export(export);


cucul_free(qq); cucul_free(qq);


+ 2
- 2
test/export.c View File

@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{ {
cucul_t *qq; cucul_t *qq;
struct cucul_dither *dither; struct cucul_dither *dither;
struct cucul_export *buffer;
struct cucul_buffer *buffer;
int x, y; int x, y;


if(argc != 2) if(argc != 2)
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");


buffer = cucul_create_export(qq, argv[1]); 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_export(buffer);


cucul_free(qq); cucul_free(qq);


Loading…
Cancel
Save