Browse Source

* Exporters now return size of generated data

tags/v0.99.beta14
Jean-Yves Lamoureux jylam 19 years ago
parent
commit
b9ab5e0e5a
3 changed files with 24 additions and 25 deletions
  1. +7
    -12
      caca/driver_network.c
  2. +4
    -4
      cucul/cucul.h
  3. +13
    -9
      cucul/export.c

+ 7
- 12
caca/driver_network.c View File

@@ -44,7 +44,7 @@ struct driver_private
unsigned int width, height;
unsigned int port;
int sockfd, new_fd;
struct sockaddr_in my_addr; // my address information
struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
socklen_t sin_size;
int clilen;
@@ -126,6 +126,7 @@ static int network_init_graphics(caca_t *kk)
(unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0x00FF0000)>>16,
(unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0xFF000000)>>24);
/* FIXME, handle >255 sizes */
codes[16] = (unsigned char) kk->drv.p->width&0xff;
codes[18] = (unsigned char) kk->drv.p->height&0xff;

@@ -164,14 +165,8 @@ static unsigned int network_get_window_height(caca_t *kk)

static void network_display(caca_t *kk)
{
/* Clear screen */
/* if (send(kk->drv.p->new_fd, "\033?75l\033[2J\033[H", 12, 0) == -1) {
perror("send");
return;
}
*/

char *to_send = cucul_get_ansi(kk->qq, 0);;
int size;
char *to_send = cucul_get_ansi(kk->qq, 0, &size);;
to_send = realloc(to_send, kk->qq->width * kk->qq->height * 15 * 3);

@@ -179,15 +174,15 @@ static void network_display(caca_t *kk)
perror("send");
return;
}
if (send(kk->drv.p->new_fd, to_send, kk->qq->width * kk->qq->height * 15, 0) == -1) {
if (send(kk->drv.p->new_fd, to_send, size, 0) == -1) {
perror("send");
return;
}
if (send(kk->drv.p->new_fd, "\033?75l\033[2J\033[H", 12, 0) == -1) {
/* if (send(kk->drv.p->new_fd, "\033?75l\033[2J\033[H", 12, 0) == -1) {
perror("send");
return;
}
*/
}
static void network_handle_resize(caca_t *kk)
{


+ 4
- 4
cucul/cucul.h View File

@@ -203,10 +203,10 @@ void cucul_free_bitmap(cucul_t *, struct cucul_bitmap *);
* These functions exports current image to various text formats
*
* @{ */
char* cucul_get_html(cucul_t *);
char* cucul_get_html3(cucul_t *);
char* cucul_get_irc(cucul_t *);
char* cucul_get_ansi(cucul_t *, int trailing);
char* cucul_get_html(cucul_t *, int *size);
char* cucul_get_html3(cucul_t *, int *size);
char* cucul_get_irc(cucul_t *, int *size);
char* cucul_get_ansi(cucul_t *, int trailing, int *size);
/* @} */

#ifdef __cplusplus


+ 13
- 9
cucul/export.c View File

@@ -35,7 +35,7 @@
* This function generates and returns the HTML representation of
* the current image.
*/
char* cucul_get_html(cucul_t *qq)
char* cucul_get_html(cucul_t *qq, int *size)
{
static int const palette[] =
{
@@ -94,7 +94,8 @@ char* cucul_get_html(cucul_t *qq)
cur += sprintf(cur, "</div></body></html>\n");

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
*size = (strlen(buffer) + 1) * sizeof(char);
buffer = realloc(buffer, *size);

return buffer;
}
@@ -107,7 +108,7 @@ char* cucul_get_html(cucul_t *qq)
* Won't work under gecko (mozilla rendering engine) unless you set
* a correct header.
*/
char* cucul_get_html3(cucul_t *qq)
char* cucul_get_html3(cucul_t *qq, int *size)
{
static int const palette[] =
{
@@ -170,8 +171,9 @@ char* cucul_get_html3(cucul_t *qq)
cur += sprintf(cur, "</table>\n");

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));

*size = (strlen(buffer) + 1) * sizeof(char);
buffer = realloc(buffer, *size);
return buffer;
}

@@ -180,7 +182,7 @@ char* cucul_get_html3(cucul_t *qq)
* This function generates and returns an IRC representation of
* the current image.
*/
char* cucul_get_irc(cucul_t *qq)
char* cucul_get_irc(cucul_t *qq, int *size)
{
static int const palette[] =
{
@@ -251,7 +253,8 @@ char* cucul_get_irc(cucul_t *qq)
*cur++ = '\x0f';

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
*size = (strlen(buffer) + 1) * sizeof(char);
buffer = realloc(buffer, *size);

return buffer;
}
@@ -264,7 +267,7 @@ char* cucul_get_irc(cucul_t *qq)
* able to cut/paste the result to a function like printf
* \return buffer containing generated ANSI codes as a big string
*/
char * cucul_get_ansi(cucul_t *qq, int trailing)
char * cucul_get_ansi(cucul_t *qq, int trailing, int *size)
{
static int const palette[] =
{
@@ -318,7 +321,8 @@ char * cucul_get_ansi(cucul_t *qq, int trailing)
}

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
*size = (strlen(buffer) + 1)* sizeof(char);
buffer = realloc(buffer, *size);

return buffer;
}


Loading…
Cancel
Save