| @@ -167,7 +167,7 @@ static void network_display(caca_t *kk) | |||||
| { | { | ||||
| int size; | int size; | ||||
| char *to_send = cucul_get_ansi(kk->qq, 0, &size);; | char *to_send = cucul_get_ansi(kk->qq, 0, &size);; | ||||
| to_send = realloc(to_send, kk->qq->width * kk->qq->height * 15 * 3); | |||||
| /* ANSI code for move(0,0)*/ | /* ANSI code for move(0,0)*/ | ||||
| if (send(kk->drv.p->new_fd, "\033[1,1H", 6, 0) == -1) { | if (send(kk->drv.p->new_fd, "\033[1,1H", 6, 0) == -1) { | ||||
| @@ -179,10 +179,6 @@ static void network_display(caca_t *kk) | |||||
| perror("send"); | perror("send"); | ||||
| return; | return; | ||||
| } | } | ||||
| if(to_send) { | |||||
| free(to_send); | |||||
| } | |||||
| } | } | ||||
| static void network_handle_resize(caca_t *kk) | static void network_handle_resize(caca_t *kk) | ||||
| @@ -72,6 +72,8 @@ cucul_t * cucul_init(void) | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| qq->ansi_buffer = NULL; | |||||
| return qq; | return qq; | ||||
| } | } | ||||
| @@ -270,6 +272,9 @@ void cucul_end(cucul_t *qq) | |||||
| free(qq->chars); | free(qq->chars); | ||||
| free(qq->attr); | free(qq->attr); | ||||
| if(qq->ansi_buffer) | |||||
| free(qq->ansi_buffer); | |||||
| free(qq); | free(qq); | ||||
| } | } | ||||
| @@ -45,6 +45,10 @@ struct cucul_context | |||||
| enum cucul_feature background, antialiasing, dithering; | enum cucul_feature background, antialiasing, dithering; | ||||
| unsigned int refcount; | unsigned int refcount; | ||||
| /* Exporters facilities */ | |||||
| unsigned char *ansi_buffer; | |||||
| }; | }; | ||||
| /* Initialisation functions */ | /* Initialisation functions */ | ||||
| @@ -275,13 +275,15 @@ char * cucul_get_ansi(cucul_t *qq, int trailing, int *size) | |||||
| 30, 34, 32, 36, 31, 35, 33, 37, /* light colors handling is done later */ | 30, 34, 32, 36, 31, 35, 33, 37, /* light colors handling is done later */ | ||||
| }; | }; | ||||
| char *buffer, *cur; | |||||
| char *cur; | |||||
| unsigned int x, y; | unsigned int x, y; | ||||
| /* 20 bytes assumed for max length per pixel. | /* 20 bytes assumed for max length per pixel. | ||||
| * 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) */ | ||||
| buffer = malloc(((qq->height*9) + (qq->width * qq->height * 20)) * sizeof(char)); | |||||
| cur = buffer; | |||||
| if(qq->ansi_buffer) | |||||
| free(qq->ansi_buffer); | |||||
| qq->ansi_buffer = malloc(((qq->height*9) + (qq->width * qq->height * 20)) * sizeof(char)); | |||||
| cur = qq->ansi_buffer; | |||||
| // *cur++ = ''; | // *cur++ = ''; | ||||
| @@ -321,9 +323,9 @@ char * cucul_get_ansi(cucul_t *qq, int trailing, int *size) | |||||
| } | } | ||||
| /* Crop to really used size */ | /* Crop to really used size */ | ||||
| *size = (strlen(buffer) + 1)* sizeof(char); | |||||
| buffer = realloc(buffer, *size); | |||||
| *size = (strlen(qq->ansi_buffer) + 1)* sizeof(char); | |||||
| qq->ansi_buffer = realloc(qq->ansi_buffer, *size); | |||||
| return buffer; | |||||
| return qq->ansi_buffer; | |||||
| } | } | ||||