Ignore:
Timestamp:
Nov 8, 2006, 6:26:57 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Convert all programs and tests to the new import/export API.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/cacaserver.c

    r1300 r1308  
    106106
    107107    cucul_canvas_t *canvas;
    108     cucul_buffer_t *buffer;
     108    void *buffer;
    109109    unsigned long int buflen;
    110     void *bufdata;
    111110
    112111    int client_count;
     
    185184    }
    186185
    187     server->canvas = NULL;
     186    server->canvas = cucul_create_canvas(0, 0);
    188187    server->buffer = NULL;
    189188
     
    197196    for(;;)
    198197    {
    199         cucul_buffer_t *b;
    200198        uint8_t *buf = server->input;
    201199        uint32_t control_size, data_size;
     
    225223        read(0, buf + 12, size - 12);
    226224
    227         /* Free the previous canvas, if any */
    228         if(server->canvas)
    229             cucul_free_canvas(server->canvas);
    230 
    231         b = cucul_load_memory(buf, size);
    232         server->canvas = cucul_import_canvas(b, "caca");
    233         cucul_free_buffer(b);
    234 
    235         if(!server->canvas)
     225        if(cucul_import_memory(server->canvas, buf, size, "caca") < 0)
    236226            continue; /* Load error */
    237227
     
    239229        if(server->buffer)
    240230        {
    241             cucul_free_buffer(server->buffer);
     231            free(server->buffer);
    242232            server->buffer = NULL;
    243233        }
     
    245235        /* Get ANSI representation of the image and skip the end-of buffer
    246236         * linefeed ("\r\n", 2 byte) */
    247         server->buffer = cucul_export_canvas(server->canvas, "utf8cr");
    248         server->bufdata = cucul_get_buffer_data(server->buffer);
    249         server->buflen = cucul_get_buffer_size(server->buffer);
     237        server->buffer = cucul_export_memory(server->canvas, "utf8cr",
     238                                             &server->buflen);
    250239        server->buflen -= 2;
    251240
     
    276265
    277266    if(server->buffer)
    278         cucul_free_buffer(server->buffer);
     267        free(server->buffer);
     268
     269    cucul_free_canvas(server->canvas);
    279270
    280271    /* Restore SIGPIPE handler */
     
    453444            memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX));
    454445            c->stop += strlen(ANSI_PREFIX);
    455             memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
     446            memcpy(c->outbuf + c->stop, server->buffer, server->buflen);
    456447            c->stop += server->buflen;
    457448
     
    488479        memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret);
    489480        c->stop = strlen(ANSI_PREFIX) - ret;
    490         memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
     481        memcpy(c->outbuf + c->stop, server->buffer, server->buflen);
    491482        c->stop += server->buflen;
    492483
     
    495486
    496487    /* Send actual data */
    497     ret = nonblock_write(c->fd, server->bufdata, server->buflen);
     488    ret = nonblock_write(c->fd, server->buffer, server->buflen);
    498489    if(ret == -1)
    499490    {
     
    518509        }
    519510
    520         memcpy(c->outbuf, server->bufdata, server->buflen - ret);
     511        memcpy(c->outbuf, server->buffer, server->buflen - ret);
    521512        c->stop = server->buflen - ret;
    522513
Note: See TracChangeset for help on using the changeset viewer.