- Timestamp:
- Mar 29, 2006, 11:41:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/cacaserver.c
r706 r707 98 98 99 99 /* Input buffer */ 100 uint8_t *input; 101 unsigned int read; 100 102 101 103 char prefix[sizeof(INIT_PREFIX)]; 102 104 105 cucul_t *qq; 103 106 struct cucul_export *ex; 104 107 … … 115 118 int main(void) 116 119 { 117 cucul_t *qq;118 120 int i, yes = 1, flags; 119 121 struct server *server; … … 121 123 122 124 server = malloc(sizeof(struct server)); 125 126 server->input = malloc(12); 127 server->read = 0; 123 128 124 129 server->client_count = 0; … … 169 174 } 170 175 176 server->qq = NULL; 171 177 server->ex = NULL; 172 178 … … 180 186 for(;;) 181 187 { 188 uint8_t *buf = server->input; 189 uint32_t width, height; 190 unsigned int size; 191 182 192 /* Manage new connections as this function will be called sometimes 183 193 * more often than display */ … … 185 195 186 196 /* 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); 188 219 189 220 /* Free the previous export buffer, if any */ … … 196 227 /* Get ANSI representation of the image and skip the end-of buffer 197 228 * linefeed ("\r\n\0", 3 bytes) */ 198 server->ex = cucul_create_export( qq, "ansi");229 server->ex = cucul_create_export(server->qq, "ansi"); 199 230 server->ex->size -= 3; 200 231
Note: See TracChangeset
for help on using the changeset viewer.