Changeset 47519e1b
- Timestamp:
- Jan 2, 2008, 2:42:05 AM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- c60ade2
- Parents:
- 2febcae
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.in
r2bdfed9 r47519e1b 26 26 keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \ 27 27 aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \ 28 zbuddylist.c muxevents.c popexec.c obarray.c 28 zbuddylist.c muxevents.c popexec.c obarray.c wcwidth.c 29 29 OWL_SRC = owl.c 30 30 TESTER_SRC = tester.c -
editwin.c
r9a6cc40 r47519e1b 143 143 e->buffy=0; 144 144 owl_editwin_overwrite_string(e, text); 145 owl_editwin_overwrite_char(e, '\0'); 145 146 e->lock=strlen(text); 146 147 /* if (text[e->lock-1]=='\n') e->lock--; */ 147 e->buffx=x;148 e->buffy=y;148 /* e->buffx=x; */ 149 /* e->buffy=y; */ 149 150 owl_editwin_adjust_for_locktext(e); 150 151 owl_editwin_redisplay(e, 0); … … 251 252 252 253 /* start at topline */ 253 ptr1 =e->buff;254 for (i =0; i<e->topline; i++) {255 ptr2 =strchr(ptr1, '\n');254 ptr1 = e->buff; 255 for (i = 0; i < e->topline; i++) { 256 ptr2 = strchr(ptr1, '\n'); 256 257 if (!ptr2) { 257 258 /* we're already on the last line */ 258 259 break; 259 260 } 260 ptr1 =ptr2+1;261 ptr1 = ptr2 + 1; 261 262 } 262 263 /* ptr1 now stores the starting point */ 263 264 264 265 /* find the ending point and store it in ptr3 */ 265 ptr2 =ptr1;266 ptr3 =ptr1;267 for (i =0; i<e->winlines; i++) {268 ptr3 =strchr(ptr2, '\n');266 ptr2 = ptr1; 267 ptr3 = ptr1; 268 for (i = 0; i < e->winlines; i++) { 269 ptr3 = strchr(ptr2, '\n'); 269 270 if (!ptr3) { 270 271 /* we've hit the last line */ 271 272 /* print everything to the end */ 272 ptr3 =e->buff+e->bufflen-1;273 ptr3 = e->buff + e->bufflen - 1; 273 274 ptr3--; 274 275 break; 275 276 } 276 ptr2 =ptr3+1;277 } 278 ptr3 +=2;279 280 buff =owl_malloc(ptr3-ptr1+50);281 strncpy(buff, ptr1, ptr3 -ptr1);282 buff[ptr3 -ptr1]='\0';283 if (e->echochar =='\0') {277 ptr2 = ptr3 + 1; 278 } 279 ptr3 += 2; 280 281 buff = owl_malloc(ptr3 - ptr1 + 50); 282 strncpy(buff, ptr1, ptr3 - ptr1); 283 buff[ptr3 - ptr1] = '\0'; 284 if (e->echochar == '\0') { 284 285 waddstr(e->curswin, buff); 285 286 } else { 286 287 /* translate to echochar, *except* for the locktext */ 287 288 int len; 288 int dolocklen =e->lock-(ptr1-e->buff);289 290 for (i =0; i<dolocklen; i++) {289 int dolocklen = e->lock - (ptr1 - e->buff); 290 291 for (i = 0; i < dolocklen; i++) { 291 292 waddch(e->curswin, buff[i]); 292 293 } 293 len =strlen(buff);294 for (i =0; i<len-dolocklen; i++) {294 len = strlen(buff); 295 for (i = 0; i < len-dolocklen; i++) { 295 296 waddch(e->curswin, e->echochar); 296 297 } 297 298 } 298 wmove(e->curswin, e->buffy-e->topline, e->buffx );299 wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e)); 299 300 wnoutrefresh(e->curswin); 300 if (update ==1) {301 if (update == 1) { 301 302 doupdate(); 302 303 } 303 304 owl_free(buff); 305 } 306 307 /* Remove n bytes at cursor. */ 308 void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/ 309 { 310 int i = _owl_editwin_get_index_from_xy(e) + n; 311 for (; i < e->bufflen; i++) { 312 e->buff[i-n] = e->buff[i]; 313 } 314 315 e->bufflen -= n; 316 e->buff[e->bufflen] = '\0'; 317 } 318 /* Insert n bytes at cursor.*/ 319 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/ 320 { 321 int i, z; 322 323 if ((e->bufflen + n) > (e->allocated - 5)) { 324 _owl_editwin_addspace(e); 325 } 326 327 e->bufflen += n; 328 e->buff[e->bufflen] = '\0'; 329 330 z = _owl_editwin_get_index_from_xy(e); 331 for (i = e->bufflen - 1; i > z; i--) { 332 e->buff[i] = e->buff[i - n]; 333 } 304 334 } 305 335 … … 313 343 int i, z; 314 344 315 z =_owl_editwin_get_index_from_xy(e);345 z = _owl_editwin_get_index_from_xy(e); 316 346 /* move back and line wrap the previous word */ 317 for (i =z-1; ; i--) {347 for (i = z - 1; ; i--) { 318 348 /* move back until you find a space or hit the beginning of the line */ 319 if (e->buff[i] ==' ') {349 if (e->buff[i] == ' ') { 320 350 /* replace the space with a newline */ 321 e->buff[i] ='\n';351 e->buff[i] = '\n'; 322 352 e->buffy++; 323 e->buffx =z-i-1;353 e->buffx = z - i - 1; 324 354 /* were we on the last line */ 325 355 return(0); 326 } else if (e->buff[i] =='\n' || i<=e->lock) {327 /* we hit the beg ginning of the line or the buffer, we cannot356 } else if (e->buff[i] == '\n' || i <= e->lock) { 357 /* we hit the beginning of the line or the buffer, we cannot 328 358 * wrap. 329 359 */ … … 336 366 * characters over) 337 367 */ 338 void owl_editwin_insert_char(owl_editwin *e, char c) 339 { 340 341 int z, i, ret; 342 368 void owl_editwin_insert_char(owl_editwin *e, gunichar c) 369 { 370 int z, i, ret, len; 371 char tmp[6]; 372 memset(tmp, '\0', 6); 373 343 374 /* \r is \n */ 344 if (c =='\r') {345 c ='\n';346 } 347 348 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {375 if (c == '\r') { 376 c = '\n'; 377 } 378 379 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 349 380 /* perhaps later this will change some state that allows the string 350 381 to be read */ … … 352 383 } 353 384 385 g_unichar_to_utf8(c, tmp); 386 len = strlen(tmp); 387 354 388 /* make sure there is enough memory for the new text */ 355 if ((e->bufflen +1) > (e->allocated-5)) {389 if ((e->bufflen + len) > (e->allocated - 5)) { 356 390 _owl_editwin_addspace(e); 357 391 } 358 392 359 393 /* get the insertion point */ 360 z =_owl_editwin_get_index_from_xy(e);394 z = _owl_editwin_get_index_from_xy(e); 361 395 362 396 /* If we're going to insert at the last column do word wrapping, unless it's a \n */ 363 if ((e->buffx +1==e->wrapcol) && (c!='\n')) {364 ret =_owl_editwin_linewrap_word(e);365 if (ret ==-1) {397 if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) { 398 ret = _owl_editwin_linewrap_word(e); 399 if (ret == -1) { 366 400 /* we couldn't wrap, insert a hard newline instead */ 367 401 owl_editwin_insert_char(e, '\n'); … … 369 403 } 370 404 371 z=_owl_editwin_get_index_from_xy(e);372 405 /* shift all the other characters right */ 373 for (i=e->bufflen; i>z; i--) {374 e->buff[i]=e->buff[i-1]; 375 }376 377 /* insert the new one */378 e->buff[z]=c;406 _owl_editwin_insert_bytes(e, len); 407 408 /* insert the new character */ 409 for(i = 0; i < len; i++) { 410 e->buff[z + i] = tmp[i]; 411 } 379 412 380 413 /* housekeeping */ 381 e->bufflen ++;382 e->buff[e->bufflen] ='\0';414 e->bufflen += len; 415 e->buff[e->bufflen] = '\0'; 383 416 384 417 /* advance the cursor */ 385 if (c=='\n') { 386 e->buffx=0; 387 e->buffy++; 388 } else { 389 e->buffx++; 390 } 418 z += len; 419 _owl_editwin_set_xy_by_index(e, z); 391 420 } 392 421 393 422 /* overwrite the character at the current point with 'c' */ 394 void owl_editwin_overwrite_char(owl_editwin *e, char c) 395 { 396 int z; 423 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c) 424 { 425 int z, oldlen, newlen, i; 426 char tmp[6]; 427 memset(tmp, '\0', 6); 397 428 398 429 /* \r is \n */ 399 if (c =='\r') {400 c ='\n';401 } 402 403 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {430 if (c == '\r') { 431 c = '\n'; 432 } 433 434 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 404 435 /* perhaps later this will change some state that allows the string 405 436 to be read */ … … 407 438 } 408 439 409 z=_owl_editwin_get_index_from_xy(e); 410 411 /* only if we are at the end of the buffer do we create new space */ 412 if (z==e->bufflen) { 413 if ((e->bufflen+1) > (e->allocated-5)) { 414 _owl_editwin_addspace(e); 415 } 416 } 417 418 e->buff[z]=c; 419 420 /* housekeeping if we are at the end of the buffer */ 421 if (z==e->bufflen) { 422 e->bufflen++; 423 e->buff[e->bufflen]='\0'; 424 } 440 g_unichar_to_utf8(c, tmp); 441 newlen = strlen(tmp); 442 443 z = _owl_editwin_get_index_from_xy(e); 444 { 445 char *t = g_utf8_find_next_char(e->buff + z, NULL); 446 oldlen = (t ? (t - (e->buff + z)) : 1); 447 } 448 449 if ((e->bufflen + newlen - oldlen + 1) > (e->allocated - 5)) { 450 _owl_editwin_addspace(e); 451 } 452 453 if (oldlen > newlen) { 454 _owl_editwin_remove_bytes(e, oldlen-newlen); 455 } 456 else /* oldlen < newlen */ { 457 _owl_editwin_insert_bytes(e, newlen-oldlen); 458 } 459 /* Overwrite the old char*/ 460 for (i = 0; i < newlen; i++) { 461 e->buff[z+i] = tmp[i]; 462 } 463 464 /* housekeeping */ 465 e->buff[e->bufflen] = '\0'; 425 466 426 467 /* advance the cursor */ 427 if (c=='\n') { 428 e->buffx=0; 429 e->buffy++; 430 } else { 431 e->buffx++; 432 } 433 468 z += newlen; 469 _owl_editwin_set_xy_by_index(e, z); 434 470 } 435 471 … … 439 475 void owl_editwin_delete_char(owl_editwin *e) 440 476 { 441 int z, i; 442 443 if (e->bufflen==0) return; 477 int z; 478 char *p1, *p2; 479 gunichar c; 480 481 if (e->bufflen == 0) return; 444 482 445 483 /* get the deletion point */ 446 z=_owl_editwin_get_index_from_xy(e); 447 448 if (z==e->bufflen) return; 449 450 for (i=z; i<e->bufflen; i++) { 451 e->buff[i]=e->buff[i+1]; 452 } 453 e->bufflen--; 454 e->buff[e->bufflen]='\0'; 484 z = _owl_editwin_get_index_from_xy(e); 485 486 if (z == e->bufflen) return; 487 488 p1 = e->buff + z; 489 p2 = g_utf8_next_char(p1); 490 c = g_utf8_get_char(p2); 491 while (g_unichar_ismark(c)) { 492 p2 = g_utf8_next_char(p2); 493 c = g_utf8_get_char(p2); 494 } 495 _owl_editwin_remove_bytes(e, p2-p1); 455 496 } 456 497 … … 463 504 { 464 505 int z; 465 char tmp;466 467 if (e->bufflen ==0) return;506 char *p1, *p2, *p3, *tmp; 507 508 if (e->bufflen == 0) return; 468 509 469 510 /* get the cursor point */ 470 z =_owl_editwin_get_index_from_xy(e);471 472 if (z ==e->bufflen) {511 z = _owl_editwin_get_index_from_xy(e); 512 513 if (z == e->bufflen) { 473 514 /* point is after last character */ 474 515 z--; 475 516 } 476 517 477 if (z -1 < e->lock) {518 if (z - 1 < e->lock) { 478 519 /* point is at beginning of buffer, do nothing */ 479 520 return; 480 521 } 481 522 482 tmp=e->buff[z]; 483 e->buff[z]=e->buff[z-1]; 484 e->buff[z-1]=tmp; 485 owl_editwin_key_right(e); 523 /* Transpose two utf-8 unicode glyphs. */ 524 p1 = e->buff + z; 525 526 p2 = g_utf8_find_next_char(p1, NULL); 527 while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) { 528 p2 = g_utf8_find_next_char(p2, NULL); 529 } 530 if (p2 == NULL) return; 531 532 p3 = g_utf8_find_prev_char(e->buff, p1); 533 while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) { 534 p3 = g_utf8_find_prev_char(p3, NULL); 535 } 536 if (p3 == NULL) return; 537 538 tmp = owl_malloc(p2 - p3 + 5); 539 *tmp = '\0'; 540 strncat(tmp, p1, p2 - p1); 541 strncat(tmp, p3, p1 - p3); 542 strncpy(p3, tmp, p2 - p3); 543 owl_free(tmp); 544 _owl_editwin_set_xy_by_index(e, p3 - e->buff); 486 545 } 487 546 … … 491 550 void owl_editwin_insert_string(owl_editwin *e, char *string) 492 551 { 493 int i, j; 494 495 j=strlen(string); 496 for (i=0; i<j; i++) { 497 owl_editwin_insert_char(e, string[i]); 552 char *p; 553 gunichar c; 554 if (!g_utf8_validate(string, -1, NULL)) { 555 owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); 556 return; 557 } 558 p = string; 559 c = g_utf8_get_char(p); 560 while (c) { 561 owl_editwin_process_char(e, c); 562 p = g_utf8_next_char(p); 563 c = g_utf8_get_char(p); 498 564 } 499 565 } … … 505 571 void owl_editwin_overwrite_string(owl_editwin *e, char *string) 506 572 { 507 int i, j; 508 509 j=strlen(string); 510 for (i=0; i<j; i++) { 511 owl_editwin_overwrite_char(e, string[i]); 573 char *p; 574 gunichar c; 575 576 if (!g_utf8_validate(string, -1, NULL)) { 577 owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string."); 578 return; 579 } 580 p = string; 581 c = g_utf8_get_char(p); 582 while (c) { 583 owl_editwin_overwrite_char(e, c); 584 p = g_utf8_next_char(p); 585 c = g_utf8_get_char(p); 512 586 } 513 587 } … … 520 594 int i; 521 595 char *ptr1, *ptr2; 522 523 if (e->bufflen==0) return(0); 596 gunichar c; 597 598 if (e->bufflen == 0) return(0); 524 599 525 600 /* first go to the yth line */ 526 ptr1 =e->buff;527 for (i =0; i<e->buffy; i++) {528 ptr2= strchr(ptr1, '\n');601 ptr1 = e->buff; 602 for (i = 0; i < e->buffy; i++) { 603 ptr2= strchr(ptr1, '\n'); 529 604 if (!ptr2) { 530 605 /* we're already on the last line */ 531 606 break; 532 607 } 533 ptr1=ptr2+1; 534 } 535 536 /* now go to the xth character */ 537 ptr2=strchr(ptr1, '\n'); 538 if (!ptr2) { 539 ptr2=e->buff+e->bufflen; 540 } 541 542 if ((ptr2-ptr1) < e->buffx) { 543 ptr1=ptr2-1; 544 } else { 545 ptr1+=e->buffx; 546 } 547 548 /* printf("DEBUG: index is %i\r\n", ptr1-e->buff); */ 549 return(ptr1-e->buff); 608 ptr1 = ptr2 + 1; 609 } 610 611 /* now go to the xth cell */ 612 ptr2 = ptr1; 613 i = 0; 614 while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) { 615 c = g_utf8_get_char(ptr2); 616 i += (c == '\n' ? 1 : mk_wcwidth(c)); 617 ptr2 = g_utf8_next_char(ptr2); 618 } 619 while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) { 620 ptr2 = g_utf8_next_char(ptr2); 621 } 622 if (ptr2 == NULL) return e->bufflen; 623 return(ptr2 - e->buff); 550 624 } 551 625 552 626 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 553 627 { 554 int z, i; 555 556 z=_owl_editwin_get_index_from_xy(e); 557 if (index>z) { 558 for (i=0; i<index-z; i++) { 559 owl_editwin_key_right(e); 560 } 561 } else if (index<z) { 562 for (i=0; i<z-index; i++) { 563 owl_editwin_key_left(e); 564 } 565 } 628 char *ptr1, *ptr2, *target; 629 gunichar c; 630 631 e->buffx = 0; 632 e->buffy = 0; 633 634 ptr1 = e->buff; 635 target = ptr1 + index; 636 /* target sanitizing */ 637 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 638 /* middle of a utf-8 character, back up to previous character. */ 639 target = g_utf8_find_prev_char(e->buff, target); 640 } 641 c = g_utf8_get_char(target); 642 while (g_unichar_ismark(c) && target > e->buff) { 643 /* Adjust the target off of combining characters and the like. */ 644 target = g_utf8_find_prev_char(e->buff, target); 645 c = g_utf8_get_char(target); 646 } 647 /* If we start with a mark, something is wrong.*/ 648 if (g_unichar_ismark(c)) return; 649 650 /* Now our target should be acceptable. */ 651 ptr2 = strchr(ptr1, '\n'); 652 while (ptr2 != NULL && ptr2 < target) { 653 e->buffy++; 654 ptr1 = ptr2 + 1; 655 ptr2 = strchr(ptr1, '\n'); 656 } 657 ptr2 = ptr1; 658 while (ptr2 != NULL && ptr2 < target) { 659 c = g_utf8_get_char(ptr2); 660 e->buffx += mk_wcwidth(c); 661 ptr2 = g_utf8_next_char(ptr2); 662 } 663 } 664 665 int _owl_editwin_cursor_adjustment(owl_editwin *e) 666 { 667 char *ptr1, *ptr2; 668 gunichar c; 669 int x, i; 670 671 ptr1 = e->buff; 672 ptr2 = strchr(ptr1, '\n'); 673 for (i = 0; ptr2 != NULL && i < e->buffy; i++) { 674 ptr1 = ptr2 + 1; 675 ptr2 = strchr(ptr1, '\n'); 676 } 677 ptr2 = ptr1; 678 x = 0; 679 while (ptr2 != NULL && x < e->buffx) { 680 if (*ptr2 == '\n') return 0; 681 c = g_utf8_get_char(ptr2); 682 x += mk_wcwidth(c); 683 ptr2 = g_utf8_next_char(ptr2); 684 } 685 return x - e->buffx; 566 686 } 567 687 … … 570 690 /* if we happen to have the cursor over locked text 571 691 * move it to be out of the locktext region */ 572 if (_owl_editwin_get_index_from_xy(e) <e->lock) {692 if (_owl_editwin_get_index_from_xy(e) < e->lock) { 573 693 _owl_editwin_set_xy_by_index(e, e->lock); 574 694 } … … 590 710 { 591 711 if (e->buffy > 0) e->buffy--; 592 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {593 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);712 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 713 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 594 714 } 595 715 … … 608 728 609 729 /* if we're past the last character move back */ 610 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {611 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);730 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 731 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 612 732 } 613 733 … … 623 743 void owl_editwin_key_left(owl_editwin *e) 624 744 { 625 /* move left if we can, and maybe up a line */ 626 if (e->buffx>0) { 627 e->buffx--; 628 } else if (e->buffy>0) { 629 e->buffy--; 630 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 631 } 632 633 /* do we need to scroll up? */ 634 if (e->buffy-e->topline < 0) { 635 e->topline-=e->winlines/2; 745 int i; 746 char * p; 747 i = _owl_editwin_get_index_from_xy(e); 748 p = e->buff + i; 749 p = g_utf8_find_prev_char(e->buff, p); 750 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 751 p = g_utf8_find_prev_char(e->buff, p); 752 } 753 if (p == NULL) p = e->buff; 754 _owl_editwin_set_xy_by_index(e, p - e->buff); 755 756 if (e->buffy - e->topline < 0) { 757 e->topline -= e->winlines / 2; 636 758 } 637 759 … … 643 765 { 644 766 int i; 645 646 /* move right if we can, and skip down a line if needed */ 647 i=owl_editwin_get_numchars_on_line(e, e->buffy); 648 if (e->buffx < i) { 649 e->buffx++; 650 /* } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { */ 651 } else if (_owl_editwin_get_index_from_xy(e) < e->bufflen) { 652 if (e->style==OWL_EDITWIN_STYLE_MULTILINE) { 653 e->buffx=0; 654 e->buffy++; 655 } 767 char * p; 768 i = _owl_editwin_get_index_from_xy(e); 769 p = e->buff + i; 770 p = g_utf8_find_next_char(p, NULL); 771 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 772 p = g_utf8_find_next_char(p, NULL); 773 } 774 if (p == NULL) { 775 _owl_editwin_set_xy_by_index(e, e->bufflen); 776 } 777 else { 778 _owl_editwin_set_xy_by_index(e, p - e->buff); 656 779 } 657 780 658 781 /* do we need to scroll down? */ 659 if (e->buffy -e->topline >= e->winlines) {660 e->topline +=e->winlines/2;782 if (e->buffy - e->topline >= e->winlines) { 783 e->topline += e->winlines / 2; 661 784 } 662 785 } … … 664 787 void owl_editwin_move_to_nextword(owl_editwin *e) 665 788 { 789 /* asedeno: needs fixing for utf-8*/ 666 790 int i, x; 667 791 … … 703 827 void owl_editwin_move_to_previousword(owl_editwin *e) 704 828 { 829 /* asedeno: needs fixing for utf-8*/ 705 830 int i, x; 706 831 … … 738 863 void owl_editwin_delete_nextword(owl_editwin *e) 739 864 { 865 /* asedeno: needs fixing for utf-8*/ 740 866 int z; 741 867 … … 768 894 void owl_editwin_delete_previousword(owl_editwin *e) 769 895 { 896 /* asedeno: needs fixing for utf-8*/ 770 897 /* go backwards to the last non-space character, then delete chars */ 771 898 int i, startpos, endpos; … … 781 908 void owl_editwin_delete_to_endofline(owl_editwin *e) 782 909 { 910 /* asedeno: needs fixing for utf-8*/ 783 911 int i; 784 912 785 if (owl_editwin_get_numchars_on_line(e, e->buffy) >e->buffx) {913 if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) { 786 914 /* normal line */ 787 915 i=_owl_editwin_get_index_from_xy(e); … … 804 932 void owl_editwin_move_to_line_end(owl_editwin *e) 805 933 { 806 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);934 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 807 935 } 808 936 … … 817 945 /* go to last char */ 818 946 e->buffy=owl_editwin_get_numlines(e)-1; 819 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);947 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 820 948 owl_editwin_key_right(e); 821 949 … … 841 969 void owl_editwin_fill_paragraph(owl_editwin *e) 842 970 { 971 /* asedeno: needs fixing for utf-8*/ 843 972 int i, save; 844 973 … … 857 986 /* main loop */ 858 987 while (1) { 859 i =_owl_editwin_get_index_from_xy(e);988 i = _owl_editwin_get_index_from_xy(e); 860 989 861 990 /* bail if we hit the end of the buffer */ 862 if (i >=e->bufflen) break;991 if (i >= e->bufflen || e->buff[i] == '\0') break; 863 992 864 993 /* bail if we hit the end of the paragraph */ 865 if (e->buff[i] =='\n' && e->buff[i+1]=='\n') break;994 if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break; 866 995 867 996 /* if we've travelled too far, linewrap */ … … 871 1000 872 1001 /* did we hit the end of a line too soon? */ 873 i =_owl_editwin_get_index_from_xy(e);874 if (e->buff[i] =='\n' && e->buffx<e->fillcol-1) {1002 i = _owl_editwin_get_index_from_xy(e); 1003 if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) { 875 1004 /* ********* we need to make sure we don't pull in a word that's too long ***********/ 876 1005 e->buff[i]=' '; … … 878 1007 879 1008 /* fix spacing */ 880 i =_owl_editwin_get_index_from_xy(e);881 if (e->buff[i] ==' ' && e->buff[i+1]==' ') {882 if (e->buff[i-1] =='.' || e->buff[i-1]=='!' || e->buff[i-1]=='?') {1009 i = _owl_editwin_get_index_from_xy(e); 1010 if (e->buff[i] == ' ' && e->buff[i+1] == ' ') { 1011 if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') { 883 1012 owl_editwin_key_right(e); 884 1013 } else { 885 1014 owl_editwin_delete_char(e); 886 1015 /* if we did this ahead of the save point, adjust it */ 887 if (i <save) save--;1016 if (i < save) save--; 888 1017 } 889 1018 } else { … … 911 1040 int owl_editwin_check_dotsend(owl_editwin *e) 912 1041 { 913 int i; 1042 char *p, *p_n, *p_p; 1043 gunichar c; 914 1044 915 1045 if (!e->dotsend) return(0); 916 for (i=e->bufflen-1; i>0; i--) { 917 if (e->buff[i] == '.' 918 && (e->buff[i-1] == '\n' || e->buff[i-1] == '\r') 919 && (e->buff[i+1] == '\n' || e->buff[i+1] == '\r')) { 920 e->bufflen = i; 921 e->buff[i] = '\0'; 1046 1047 p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen); 1048 p_n = g_utf8_find_next_char(p, NULL); 1049 p_p = g_utf8_find_prev_char(e->buff, p); 1050 c = g_utf8_get_char(p); 1051 while (p != NULL) { 1052 if (*p == '.' 1053 && p_p != NULL && (*p_p == '\n' || *p_p == '\r') 1054 && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) { 1055 e->bufflen = p - e->buff; 1056 e->buff[e->bufflen] = '\0'; 922 1057 return(1); 923 1058 } 924 if (!isspace((int) e->buff[i])) { 925 return(0); 926 } 1059 if (c != '\0' && !g_unichar_isspace(c)) return(0); 1060 p_n = p; 1061 p = p_p; 1062 c = g_utf8_get_char(p); 1063 p_p = g_utf8_find_prev_char(e->buff, p); 927 1064 } 928 1065 return(0); 929 1066 } 930 1067 931 void owl_editwin_post_process_char(owl_editwin *e, intj)1068 void owl_editwin_post_process_char(owl_editwin *e, gunichar j) 932 1069 { 933 1070 /* check if we need to scroll down */ … … 942 1079 } 943 1080 944 void owl_editwin_process_char(owl_editwin *e, intj)1081 void owl_editwin_process_char(owl_editwin *e, gunichar j) 945 1082 { 946 1083 if (j == ERR) return; 947 if ( j>127 || ((j<32) && (j!=10) && (j!=13))) {1084 if (g_unichar_iscntrl(j) && (j != 10) && (j != 13)) { 948 1085 return; 949 } else { 1086 } 1087 else { 950 1088 owl_editwin_insert_char(e, j); 951 1089 } … … 975 1113 } 976 1114 977 /* now go to the xth character */ 978 ptr2=strchr(ptr1, '\n'); 979 if (!ptr2) { 980 return(e->buff + e->bufflen - ptr1); 981 } 982 return(ptr2-ptr1); /* don't count the newline for now */ 1115 /* now count characters */ 1116 i = 0; 1117 ptr2 = ptr1; 1118 while (ptr2 - e->buff < e->bufflen 1119 && *ptr2 != '\n') { 1120 ++i; 1121 ptr2 = g_utf8_next_char(ptr2); 1122 } 1123 return i; 1124 } 1125 1126 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line) 1127 { 1128 int i; 1129 char *ptr1, *ptr2; 1130 gunichar c; 1131 1132 if (e->bufflen==0) return(0); 1133 1134 /* first go to the yth line */ 1135 ptr1=e->buff; 1136 for (i=0; i<line; i++) { 1137 ptr2=strchr(ptr1, '\n'); 1138 if (!ptr2) { 1139 /* we're already on the last line */ 1140 return(0); 1141 } 1142 ptr1=ptr2+1; 1143 } 1144 1145 /* now count cells */ 1146 i = 0; 1147 ptr2 = ptr1; 1148 while (ptr2 - e->buff < e->bufflen 1149 && *ptr2 != '\n') { 1150 c = g_utf8_get_char(ptr2); 1151 i += mk_wcwidth(c); 1152 ptr2 = g_utf8_next_char(ptr2); 1153 } 1154 return i; 983 1155 } 984 1156 -
fmtext.c
r5376a95 r47519e1b 248 248 * must already be initiatlized with curses 249 249 */ 250 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search)250 void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/ 251 251 { 252 252 /* char *tmpbuff; */ … … 264 264 search_results = (do_search 265 265 ? owl_fmtext_search(f, owl_global_get_search_string(&g)) 266 : NULL); 267 if (search_results) search_len = strlen(owl_global_get_search_string(&g)); 266 : 0); 267 search_len = (search_results 268 ? strlen(owl_global_get_search_string(&g)) 269 : 0); 268 270 s = f->textbuff; 269 271 /* Set default attributes. */ … … 350 352 } 351 353 354 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 355 { 356 _owl_fmtext_curs_waddstr(f, w, owl_global_is_search_active(&g)); 357 } 358 359 void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w) 360 { 361 _owl_fmtext_curs_waddstr(f, w, 0); 362 } 352 363 353 364 /* start with line 'aline' (where the first line is 0) and print … … 413 424 st = 0; 414 425 padding = 0; 426 chwidth = 0; 415 427 ptr_c = ptr_s; 416 428 while(col <= bcol && ptr_c < ptr_e) { 417 429 gunichar c = g_utf8_get_char(ptr_c); 418 430 if (!_owl_fmtext_is_format_char(c)) { 419 chwidth = wcwidth(c);431 chwidth = mk_wcwidth(c); 420 432 421 433 if (col + chwidth > bcol) -
functions.c
r2febcae r47519e1b 2187 2187 void owl_function_start_command(char *line) 2188 2188 { 2189 int i, j;2190 2189 owl_editwin *tw; 2191 2190 … … 2198 2197 owl_global_set_needrefresh(&g); 2199 2198 2200 j=strlen(line); 2201 for (i=0; i<j; i++) { 2202 owl_editwin_process_char(tw, line[i]); 2203 } 2199 owl_editwin_insert_string(tw, line); 2204 2200 owl_editwin_redisplay(tw, 0); 2205 2201 -
keymap.c
rcf83b7a r47519e1b 202 202 /* processes a keypress. returns 0 if the keypress was handled, 203 203 * 1 if not handled, -1 on error, and -2 if j==ERR. */ 204 int owl_keyhandler_process(owl_keyhandler *kh, intj)204 int owl_keyhandler_process(owl_keyhandler *kh, gunichar j) 205 205 { 206 206 owl_keymap *km; -
message.c
r6201646 r47519e1b 540 540 owl_fmtext_colorizebg(&b, bgcolor); 541 541 542 owl_fmtext_curs_waddstr(&b, win , owl_global_is_search_active(&g));542 owl_fmtext_curs_waddstr(&b, win); 543 543 544 544 owl_fmtext_free(&a); -
owl.c
r5bc0f68 r47519e1b 70 70 owl_editwin *tw; 71 71 owl_popwin *pw; 72 int j, ret, initialsubs, debug, argcsave, followlast; 72 int ret, initialsubs, debug, argcsave, followlast; 73 gunichar j; 73 74 int newmsgs, nexttimediff; 74 75 struct sigaction sigact; … … 546 547 usleep(10000); 547 548 } else { 549 /* Pull in a full utf-8 character. */ 550 if (j & 0x80) { 551 char utf8buf[7]; 552 int bytes, i; 553 memset(utf8buf,'\0',7); 554 utf8buf[0] = j; 555 556 if (~j & 0x20) bytes = 2; 557 else if (~j & 0x10) bytes = 3; 558 else if (~j & 0x08) bytes = 4; 559 else if (~j & 0x04) bytes = 5; 560 else if (~j & 0x02) bytes = 6; 561 else bytes = 1; /* This won't validate */ 562 563 for (i = 1; i < bytes; i++) { 564 utf8buf[i] = wgetch(typwin); 565 } 566 if (g_utf8_validate(utf8buf, -1, NULL)) { 567 j = g_utf8_get_char(utf8buf); 568 } 569 else { 570 j = ERR; 571 } 572 } 548 573 owl_global_update_lastinputtime(&g); 549 574 /* find and activate the current keymap. -
text.c
rdd24b6a r47519e1b 77 77 while(col < bcol && ptr_c < ptr_e) { 78 78 gunichar c = g_utf8_get_char(ptr_c); 79 if (col + wcwidth(c) > bcol) break;80 col += wcwidth(c);79 if (col + mk_wcwidth(c) > bcol) break; 80 col += mk_wcwidth(c); 81 81 ptr_c = g_utf8_next_char(ptr_c); 82 82 if (col >= acol) { -
viewwin.c
r9866c3a r47519e1b 73 73 owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2); 74 74 75 owl_fmtext_curs_waddstr (&fm2, v->curswin, 0);75 owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin); 76 76 77 77 /* print the message at the bottom */
Note: See TracChangeset
for help on using the changeset viewer.