- Timestamp:
- Apr 26, 2006, 12:22:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/import.c
r891 r893 244 244 if(buffer[i] == '\x1b' && buffer[i + 1] == '[') 245 245 { 246 unsigned int argv[1024]; /* Should be enough. Will it be? */ 247 unsigned int argc = 0; 246 unsigned int argc, argv[101]; 248 247 unsigned int param, inter, final; 249 248 250 /* Offset to parameter bytes */ 249 /* Compute offsets to parameter bytes, intermediate bytes and 250 * to the final byte. Only the final byte is mandatory, there 251 * can be zero of the others. 252 * 253 * +-----+------------------+---------------------+-----------------+ 254 * | CSI | parameter bytes | intermediate bytes | final byte | 255 * | | 0x30 - 0x3f | 0x20 - 0x2f | 0x40 - 0x7e | 256 * | ^[[ | 0123456789:;<=>? | SPC !"#$%&'()*+,-./ | azAZ@[\]^_`{|}~ | 257 * +-----+------------------+---------------------+-----------------+ 258 */ 251 259 param = 2; 252 260 253 /* Offset to intermediate bytes: skip parameter bytes */254 261 for(inter = param; i + inter < size; inter++) 255 262 if(buffer[i + inter] < 0x30 || buffer[i + inter] > 0x3f) 256 263 break; 257 264 258 /* Offset to final byte: skip intermediate bytes */259 265 for(final = inter; i + final < size; final++) 260 266 if(buffer[i + final] < 0x20 || buffer[i + final] > 0x2f) … … 266 272 skip += final; 267 273 274 /* Sanity checks */ 268 275 if(param < inter && buffer[i + param] >= 0x3c) 269 276 { … … 273 280 } 274 281 275 /* Parse parameter bytes, if any */ 282 if(final - param > 100) 283 continue; /* Suspiciously long sequence, skip it */ 284 285 /* ECMA-48 5.4.2: Parameter string format */ 276 286 if(param < inter) 277 287 { … … 287 297 } 288 298 289 /* Interpret final byte */ 299 /* Interpret final byte. The code representations are given in 300 * ECMA-48 5.4: Control sequences, and the code definitions are 301 * given in ECMA-48 8.3: Definition of control functions. */ 290 302 switch(buffer[i + final]) 291 303 { 292 case 'f': 293 case 'H': 304 case 'f': /* CUP - Cursor Position */ 305 case 'H': /* HVP - Character And Line Position */ 294 306 x = (argc > 1) ? argv[1] - 1 : 0; 295 307 y = (argc > 0) ? argv[0] - 1 : 0; 296 308 break; 297 case 'A': 309 case 'A': /* CUU - Cursor Up */ 298 310 y -= argc ? argv[0] : 1; 299 311 if(y < 0) 300 312 y = 0; 301 313 break; 302 case 'B': 314 case 'B': /* CUD - Cursor Down */ 303 315 y += argc ? argv[0] : 1; 304 316 break; 305 case 'C': 317 case 'C': /* CUF - Cursor Right */ 306 318 x += argc ? argv[0] : 1; 307 319 break; 308 case 'D': 320 case 'D': /* CUB - Cursor Left */ 309 321 x -= argc ? argv[0] : 1; 310 322 if(x < 0) 311 323 x = 0; 312 324 break; 313 case 's': 325 case 's': /* Private (save cursor position) */ 314 326 save_x = x; 315 327 save_y = y; 316 328 break; 317 case 'u': 329 case 'u': /* Private (reload cursor positin) */ 318 330 x = save_x; 319 331 y = save_y; 320 332 break; 321 case 'J': 333 case 'J': /* ED - Erase In Page */ 322 334 if(argv[0] == 2) 323 335 x = y = 0; 324 336 break; 325 case 'K': 326 // CLEAR END OF LINE 337 case 'K': /* EL - Erase In Line */ 327 338 for(j = x; j < width; j++) 328 339 _cucul_putchar32(cv, j, y, (uint32_t)' '); 329 340 x = width; 330 341 break; 331 case 'm': 342 case 'm': /* SGR - Select Graphic Rendition */ 332 343 for(j = 0; j < argc; j++) 333 344 manage_modifiers(argv[j], &fg, &bg,
Note: See TracChangeset
for help on using the changeset viewer.