Ignore:
Timestamp:
Apr 19, 2006, 11:07:55 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Added a new "caca" exporter.
  • Removed most code from the raw driver and replaced it with a call to the caca exporter.
  • Slightly changed the caca export format and updated code accordingly.
  • Improved cacaserver error reporting.
File:
1 edited

Legend:

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

    r813 r818  
    135135    server = malloc(sizeof(struct server));
    136136
    137     server->input = malloc(12);
     137    server->input = malloc(16);
    138138    server->read = 0;
    139139
     
    206206
    207207        /* Read data from stdin */
    208         read(0, buf, 12);
    209 
    210         while(buf[0] != 'C' && buf[1] != 'A' && buf[2] != 'C' && buf[3] != 'A')
    211         {
    212             memmove(buf, buf + 1, 11);
    213             read(0, buf + 11, 1);
    214         }
    215 
    216         width = ((uint32_t)buf[4] << 24) | ((uint32_t)buf[5] << 16)
    217               | ((uint32_t)buf[6] << 8) | (uint32_t)buf[7];
    218         height = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
     208        read(0, buf, 16);
     209
     210        while(buf[0] != 'C' || buf[1] != 'A' || buf[2] != 'C' || buf[3] != 'A')
     211        {
     212            memmove(buf, buf + 1, 15);
     213            read(0, buf + 15, 1);
     214        }
     215
     216        width = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
    219217               | ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];
    220 
    221         size = 12 + width * height * 8 + 4;
     218        height = ((uint32_t)buf[12] << 24) | ((uint32_t)buf[13] << 16)
     219                | ((uint32_t)buf[14] << 8) | (uint32_t)buf[15];
     220
     221        size = 16 + width * height * 8;
    222222        buf = server->input = realloc(server->input, size);
    223         read(0, buf + 12, size - 12);
     223        read(0, buf + 16, size - 16);
    224224
    225225        /* Free the previous canvas, if any */
     
    240240
    241241        /* Get ANSI representation of the image and skip the end-of buffer
    242          * linefeed ("\r\n\0", 3 bytes) */
     242         * linefeed ("\r\n", 2 bytes) */
    243243        server->buffer = cucul_create_export(server->canvas, "ansi");
    244         server->buflen -= 3;
     244        server->bufdata = cucul_get_buffer_data(server->buffer);
     245        server->buflen = cucul_get_buffer_size(server->buffer);
     246        server->buflen -= 2;
    245247
    246248        for(i = 0; i < server->client_count; i++)
     
    411413                ret = 0;
    412414            else
     415            {
     416                fprintf(stderr, "client %i failed (%s)\n",
     417                        c->fd, strerror(errno));
    413418                return -1;
     419            }
    414420        }
    415421
     
    459465            ret = 0;
    460466        else
     467        {
     468            fprintf(stderr, "client %i failed (%s)\n", c->fd, strerror(errno));
    461469            return -1;
     470        }
    462471    }
    463472
     
    488497            ret = 0;
    489498        else
     499        {
     500            fprintf(stderr, "client %i failed (%s)\n", c->fd, strerror(errno));
    490501            return -1;
     502        }
    491503    }
    492504
Note: See TracChangeset for help on using the changeset viewer.