diff --git a/README b/README
index efedade..f64f3d3 100644
--- a/README
+++ b/README
@@ -10,6 +10,7 @@ Building libcaca
--enable-x11: support for native X11 rendering
--enable-gl: support for OpenGL rendering
--enable-win32: support for the Windows console
+ --enable-network: support for network output
--disable-imlib2: remove Imlib2 support in cacaview
diff --git a/cucul/cucul.c b/cucul/cucul.c
index 2ffbd3f..c484600 100644
--- a/cucul/cucul.c
+++ b/cucul/cucul.c
@@ -75,6 +75,9 @@ cucul_t * cucul_init(void)
}
qq->ansi_buffer = NULL;
+ qq->irc_buffer = NULL;
+ qq->html3_buffer = NULL;
+ qq->html_buffer = NULL;
return qq;
}
@@ -276,6 +279,13 @@ void cucul_end(cucul_t *qq)
if(qq->ansi_buffer)
free(qq->ansi_buffer);
+ if(qq->irc_buffer)
+ free(qq->irc_buffer);
+ if(qq->html3_buffer)
+ free(qq->html3_buffer);
+ if(qq->html_buffer)
+ free(qq->html_buffer);
+
free(qq);
}
diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h
index abfe3c1..a51df3c 100644
--- a/cucul/cucul_internals.h
+++ b/cucul/cucul_internals.h
@@ -47,7 +47,12 @@ struct cucul_context
unsigned int refcount;
/* Exporters facilities */
- unsigned char *ansi_buffer;
+ char *ansi_buffer;
+ char *irc_buffer;
+ char *html3_buffer;
+ char *html_buffer;
+
+
};
diff --git a/cucul/export.c b/cucul/export.c
index 1758217..22d8411 100644
--- a/cucul/export.c
+++ b/cucul/export.c
@@ -44,14 +44,17 @@ char* cucul_get_html(cucul_t *qq, int *size)
0x000, 0x008, 0x080, 0x088, 0x800, 0x808, 0x880, 0x888,
0x444, 0x44f, 0x4f4, 0x4ff, 0xf44, 0xf4f, 0xff4, 0xfff,
};
- char *buffer, *cur;
+ char *cur;
unsigned int x, y, len;
/* 13000 -> css palette
* 40 -> max size used for a pixel (plus 10, never know)*/
/* FIXME: Check this value */
- buffer = malloc((13000 + ((qq->width*qq->height) * 40)) * sizeof(char));
- cur = buffer;
+ if(qq->html_buffer)
+ free(qq->html_buffer);
+
+ qq->html_buffer = malloc((13000 + ((qq->width*qq->height) * 40)) * sizeof(char));
+ cur = qq->html_buffer;
/* HTML header */
cur += sprintf(cur, "\n
\nGenerated by libcaca %s\n", VERSION);
@@ -96,10 +99,10 @@ char* cucul_get_html(cucul_t *qq, int *size)
cur += sprintf(cur, "\n");
/* Crop to really used size */
- *size = (strlen(buffer) + 1) * sizeof(char);
- buffer = realloc(buffer, *size);
+ *size = (strlen(qq->html_buffer) + 1) * sizeof(char);
+ qq->html_buffer = realloc(qq->html_buffer, *size);
- return buffer;
+ return qq->html_buffer;
}
/** \brief Generate HTML3 representation of current image.
@@ -119,13 +122,17 @@ char* cucul_get_html3(cucul_t *qq, int *size)
0x444444, 0x4444ff, 0x44ff44, 0x44ffff,
0xff4444, 0xff44ff, 0xffff44, 0xffffff,
};
- char *buffer, *cur;
+ char *cur;
unsigned int x, y, len;
/* 13000 -> css palette
* 40 -> max size used for a pixel (plus 10, never know) */
- buffer = malloc((13000 + ((qq->width*qq->height)*40))*sizeof(char));
- cur = buffer;
+
+ if(qq->html3_buffer)
+ free(qq->html3_buffer);
+
+ qq->html3_buffer = malloc((13000 + ((qq->width*qq->height)*40))*sizeof(char));
+ cur = qq->html3_buffer;
/* Table */
cur += sprintf(cur, "\n",
@@ -173,10 +180,10 @@ char* cucul_get_html3(cucul_t *qq, int *size)
cur += sprintf(cur, "
\n");
/* Crop to really used size */
- *size = (strlen(buffer) + 1) * sizeof(char);
- buffer = realloc(buffer, *size);
+ *size = (strlen(qq->html3_buffer) + 1) * sizeof(char);
+ qq->html3_buffer = realloc(qq->html3_buffer, *size);
- return buffer;
+ return qq->html3_buffer;
}
/** \brief Generate IRC representation of current image.
@@ -192,7 +199,7 @@ char* cucul_get_irc(cucul_t *qq, int *size)
14, 12, 9, 11, 4, 13, 8, 0, /* Light */
};
- char *buffer, *cur;
+ char *cur;
unsigned int x, y;
/* 11 bytes assumed for max length per pixel. Worst case scenario:
@@ -202,8 +209,12 @@ char* cucul_get_irc(cucul_t *qq, int *size)
* \r\n 2 bytes
* In real life, the average bytes per pixel value will be around 5.
*/
- buffer = malloc((2 + (qq->width * qq->height * 11)) * sizeof(char));
- cur = buffer;
+
+ if(qq->irc_buffer)
+ free(qq->irc_buffer);
+
+ qq->irc_buffer = malloc((2 + (qq->width * qq->height * 11)) * sizeof(char));
+ cur = qq->irc_buffer;
*cur++ = '\x0f';
@@ -255,10 +266,10 @@ char* cucul_get_irc(cucul_t *qq, int *size)
*cur++ = '\x0f';
/* Crop to really used size */
- *size = (strlen(buffer) + 1) * sizeof(char);
- buffer = realloc(buffer, *size);
+ *size = (strlen(qq->irc_buffer) + 1) * sizeof(char);
+ qq->irc_buffer = realloc(qq->irc_buffer, *size);
- return buffer;
+ return qq->irc_buffer;
}
/** \brief Generate ANSI representation of current image.