- Timestamp:
- Apr 26, 2006, 10:21:46 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/import.c
r888 r889 73 73 return import_caca(data, size); 74 74 75 /* If we find ESC[ tuple, we guess it's an ANSI file */75 /* If we find ESC[ argv, we guess it's an ANSI file */ 76 76 while(i<size-1) 77 77 { … … 202 202 203 203 #define IS_ALPHA(x) (x>='A' && x<='z') 204 #define END_ TUP0x1337204 #define END_ARG 0x1337 205 205 static int parse_tuple(unsigned int *, unsigned char const *, int); 206 206 static void manage_modifiers(int, uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *); … … 211 211 unsigned char const *buffer = (unsigned char const*)data; 212 212 unsigned int i; 213 unsigned int count = 0;214 unsigned int tuple[1024]; /* Should be enough. Will it be ? */215 213 int x = 0, y = 0; 216 214 unsigned int width = 80, height = 25; … … 246 244 if(buffer[i] == '\x1b' && buffer[i + 1] == '[') /* ESC code */ 247 245 { 246 unsigned int argv[1024]; /* Should be enough. Will it be? */ 247 unsigned int argc = 0; 248 248 unsigned char c = '\0'; 249 249 … … 258 258 } 259 259 260 skip += parse_tuple(tuple, buffer + i, size - i); 261 count = 0; 262 263 while(tuple[count] != END_TUP) 264 count++; /* Gruik */ 260 skip += parse_tuple(argv, buffer + i, size - i); 261 262 while(argv[argc] != END_ARG) 263 argc++; /* Gruik */ 265 264 266 265 switch(c) … … 268 267 case 'f': 269 268 case 'H': 270 if(tuple[0] == END_TUP) 271 x = y = 0; 272 else 269 switch(argc) 273 270 { 274 y = tuple[0] - 1; 275 x = tuple[1] == END_TUP ? 0 : tuple[1] - 1; 271 case 0: x = y = 0; break; 272 case 1: y = argv[0] - 1; x = 0; break; 273 case 2: y = argv[0] - 1; x = argv[1] - 1; break; 276 274 } 277 275 break; 278 276 case 'A': 279 y -= tuple[0] == END_TUP ? 1 : tuple[0];277 y -= argc ? argv[0] : 1; 280 278 if(y < 0) 281 279 y = 0; 282 280 break; 283 281 case 'B': 284 y += tuple[0] == END_TUP ? 1 : tuple[0];282 y += argc ? argv[0] : 1; 285 283 break; 286 284 case 'C': 287 x += tuple[0] == END_TUP ? 1 : tuple[0];285 x += argc ? argv[0] : 1; 288 286 break; 289 287 case 'D': 290 x -= tuple[0] == END_TUP ? 1 : tuple[0];288 x -= argc ? argv[0] : 1; 291 289 if(x < 0) 292 290 x = 0; … … 301 299 break; 302 300 case 'J': 303 if( tuple[0] == 2)301 if(argv[0] == 2) 304 302 x = y = 0; 305 303 break; … … 311 309 break; 312 310 case 'm': 313 for(j = 0; j < count; j++) 314 manage_modifiers(tuple[j], &fg, &bg, &save_fg, &save_bg, &bold, &reverse); 311 for(j = 0; j < argc; j++) 312 manage_modifiers(argv[j], &fg, &bg, 313 &save_fg, &save_bg, &bold, &reverse); 315 314 if(bold && fg < 8) 316 315 fg += 8; … … 360 359 unsigned char nbr[1024]; 361 360 362 ret[0] = END_ TUP;361 ret[0] = END_ARG; 363 362 364 363 for(i = 0; i < size; i++) … … 371 370 t++; 372 371 } 373 ret[t] = END_ TUP;372 ret[t] = END_ARG; 374 373 j = 0; 375 374 return i; … … 386 385 ret[t] = atoi((char*)nbr); 387 386 t++; 388 ret[t] = END_ TUP;387 ret[t] = END_ARG; 389 388 j = 0; 390 389 } … … 393 392 } 394 393 395 static void manage_modifiers(int i, uint8_t *fg, uint8_t *bg, uint8_t *save_fg, uint8_t *save_bg, uint8_t *bold, uint8_t *reverse) 394 static void manage_modifiers(int i, uint8_t *fg, uint8_t *bg, uint8_t *save_fg, 395 uint8_t *save_bg, uint8_t *bold, uint8_t *reverse) 396 396 { 397 397 static uint8_t const ansi2cucul[] =
Note: See TracChangeset
for help on using the changeset viewer.