Ignore:
Timestamp:
Mar 29, 2006, 11:41:30 AM (15 years ago)
Author:
Sam Hocevar
Message:
  • cacaserver works again (but needs a complete rewrite because it's really become ugly). You can now emulate the previous network driver behaviour by doing: "CACA_DRIVER=raw cacaplas | cacaserver".
File:
1 edited

Legend:

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

    r706 r707  
    9898
    9999    /* Input buffer */
     100    uint8_t *input;
     101    unsigned int read;
    100102
    101103    char prefix[sizeof(INIT_PREFIX)];
    102104
     105    cucul_t *qq;
    103106    struct cucul_export *ex;
    104107
     
    115118int main(void)
    116119{
    117     cucul_t *qq;
    118120    int i, yes = 1, flags;
    119121    struct server *server;
     
    121123
    122124    server = malloc(sizeof(struct server));
     125
     126    server->input = malloc(12);
     127    server->read = 0;
    123128
    124129    server->client_count = 0;
     
    169174    }
    170175
     176    server->qq = NULL;
    171177    server->ex = NULL;
    172178
     
    180186    for(;;)
    181187    {
     188        uint8_t *buf = server->input;
     189        uint32_t width, height;
     190        unsigned int size;
     191
    182192        /* Manage new connections as this function will be called sometimes
    183193         * more often than display */
     
    185195
    186196        /* Read data from stdin */
    187         /* FIXME: read data, then continue if there was a new image */
     197        read(0, buf, 12);
     198
     199        while(buf[0] != 'C' && buf[1] != 'A' && buf[2] != 'C' && buf[3] != 'A')
     200        {
     201            memmove(buf, buf + 1, 11);
     202            read(0, buf + 11, 1);
     203        }
     204
     205        width = ((uint32_t)buf[4] << 24) | ((uint32_t)buf[5] << 16)
     206              | ((uint32_t)buf[6] << 8) | (uint32_t)buf[7];
     207        height = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
     208               | ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];
     209
     210        size = 12 + width * height * 5 + 4;
     211        server->input = realloc(server->input, size);
     212        read(0, buf + 12, size - 12);
     213
     214        /* Free the previous canvas, if any */
     215        if(server->qq)
     216            cucul_free(server->qq);
     217
     218        server->qq = cucul_load(buf, size);
    188219
    189220        /* Free the previous export buffer, if any */
     
    196227        /* Get ANSI representation of the image and skip the end-of buffer
    197228         * linefeed ("\r\n\0", 3 bytes) */
    198         server->ex = cucul_create_export(qq, "ansi");
     229        server->ex = cucul_create_export(server->qq, "ansi");
    199230        server->ex->size -= 3;
    200231
Note: See TracChangeset for help on using the changeset viewer.