Changeset 3595
- Timestamp:
- 07/31/09 02:01:25 (4 years ago)
- Location:
- libcaca/trunk/caca
- Files:
-
- 2 edited
-
caca_conio.c (modified) (3 diffs)
-
string.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca_conio.c
r3594 r3595 74 74 { 75 75 va_list args; 76 int ret; 76 77 77 78 conio_init(); 78 79 79 80 va_start(args, format); 80 caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args);81 ret = caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args); 81 82 va_end(args); 82 83 84 caca_gotoxy(cv, caca_wherex(cv) + ret, caca_wherey(cv)); 85 83 86 conio_refresh(); 84 87 85 /* FIXME: we should fix caca_vprintf so that it returns the number of 86 * characters that were printed. */ 87 return 0; 88 return ret; 88 89 } 89 90 … … 113 114 conio_init(); 114 115 115 /* TODO: implement this function */116 _caca_sleep(i * 1000); 116 117 } 117 118 … … 272 273 { 273 274 va_list args; 275 int ret; 274 276 275 277 conio_init(); 276 278 277 279 va_start(args, format); 278 caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args);280 ret = caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args); 279 281 va_end(args); 280 282 283 caca_gotoxy(cv, caca_wherex(cv) + ret, caca_wherey(cv)); 284 281 285 conio_refresh(); 282 286 283 /* FIXME: we should fix caca_vprintf so that it returns the number of284 * characters that were printed. */285 287 return 0; 286 288 } -
libcaca/trunk/caca/string.c
r3587 r3595 102 102 * character instead of an UTF-32 character, use the caca_put_str() function. 103 103 * 104 * This function returns the width of the printed character. If it is a 105 * fullwidth character, 2 is returned. Otherwise, 1 is returned. 106 * 104 107 * This function never fails. 105 108 * … … 108 111 * \param y Y coordinate. 109 112 * \param ch The character to print. 110 * \return This function always returns 0. 113 * \return The width of the printed character: 2 for a fullwidth character, 114 * 1 otherwise. 111 115 */ 112 116 int caca_put_char(caca_canvas_t *cv, int x, int y, uint32_t ch) 113 117 { 114 118 uint32_t *curchar, *curattr, attr; 115 int fullwidth, xmin, xmax; 119 int fullwidth, xmin, xmax, ret; 120 121 if(ch == CACA_MAGIC_FULLWIDTH) 122 return 1; 123 124 fullwidth = caca_utf32_is_fullwidth(ch); 125 ret = fullwidth ? 2 : 1; 116 126 117 127 if(x >= (int)cv->width || y < 0 || y >= (int)cv->height) 118 return 0; 119 120 if(ch == CACA_MAGIC_FULLWIDTH) 121 return 0; 122 123 fullwidth = caca_utf32_is_fullwidth(ch); 128 return ret; 124 129 125 130 if(x == -1 && fullwidth) … … 130 135 } 131 136 else if(x < 0) 132 return 0;137 return ret; 133 138 134 139 curchar = cv->chars + x + y * cv->width; … … 188 193 curattr[0] = attr; 189 194 190 return 0;195 return ret; 191 196 } 192 197 … … 231 236 * are handled when overwriting each other or at the canvas' boundaries. 232 237 * 238 * This function returns the number of cells printed by the string. It is 239 * not the number of characters printed, because fullwidth characters 240 * account for two cells. 241 * 233 242 * This function never fails. 234 243 * … … 237 246 * \param y Y coordinate. 238 247 * \param s The string to print. 239 * \return Th is function always returns 0.248 * \return The number of cells printed. 240 249 */ 241 250 int caca_put_str(caca_canvas_t *cv, int x, int y, char const *s) 242 251 { 243 252 size_t rd; 253 int len = 0; 244 254 245 255 if(y < 0 || y >= (int)cv->height || x >= (int)cv->width) 246 return 0; 247 248 while(*s && x < -1) 249 { 250 x += caca_utf32_is_fullwidth(caca_utf8_to_utf32(s, &rd)) ? 2 : 1; 256 { 257 while(*s) 258 { 259 len += caca_utf32_is_fullwidth(caca_utf8_to_utf32(s, &rd)) ? 2 : 1; 260 s += rd; 261 } 262 return len; 263 } 264 265 while(*s) 266 { 267 uint32_t ch = caca_utf8_to_utf32(s, &rd); 268 269 if(x + len >= -1 && x + len < (int)cv->width) 270 caca_put_char(cv, x + len, y, ch); 271 272 len += caca_utf32_is_fullwidth(ch) ? 2 : 1; 251 273 s += rd; 252 274 } 253 275 254 while(*s && x < (int)cv->width) 255 { 256 uint32_t ch = caca_utf8_to_utf32(s, &rd); 257 caca_put_char(cv, x, y, ch); 258 x += caca_utf32_is_fullwidth(ch) ? 2 : 1; 259 s += rd; 260 } 261 262 return 0; 276 return len; 263 277 } 264 278 … … 271 285 * same as for the C printf() function. 272 286 * 287 * This function returns the number of cells printed by the string. It is 288 * not the number of characters printed, because fullwidth characters 289 * account for two cells. 290 * 273 291 * This function never fails. 274 292 * … … 278 296 * \param format The format string to print. 279 297 * \param ... Arguments to the format string. 280 * \return Th is function always returns 0.298 * \return The number of cells printed. 281 299 */ 282 300 int caca_printf(caca_canvas_t *cv, int x, int y, char const *format, ...) … … 298 316 * same as for the C vprintf() function. 299 317 * 318 * This function returns the number of cells printed by the string. It is 319 * not the number of characters printed, because fullwidth characters 320 * account for two cells. 321 * 300 322 * This function never fails. 301 323 * … … 305 327 * \param format The format string to print. 306 328 * \param ap A va_list containting the arguments to the format string. 307 * \return Th is function always returns 0.329 * \return The number of cells printed. 308 330 */ 309 331 int caca_vprintf(caca_canvas_t *cv, int x, int y, char const *format, … … 312 334 char tmp[BUFSIZ]; 313 335 char *buf = tmp; 314 315 if(y < 0 || y >= (int)cv->height || x >= (int)cv->width) 316 return 0; 336 int ret; 317 337 318 338 if(cv->width - x + 1 > BUFSIZ) … … 326 346 buf[cv->width - x] = '\0'; 327 347 328 caca_put_str(cv, x, y, buf);348 ret = caca_put_str(cv, x, y, buf); 329 349 330 350 if(buf != tmp) 331 351 free(buf); 332 352 333 return 0;353 return ret; 334 354 } 335 355
Note: See TracChangeset
for help on using the changeset viewer.
