Changes in editwin.c [830c36e:9a6cc40]
Legend:
- Unmodified
- Added
- Removed
-
editwin.c
r830c36e r9a6cc40 143 143 e->buffy=0; 144 144 owl_editwin_overwrite_string(e, text); 145 owl_editwin_overwrite_char(e, '\0');146 145 e->lock=strlen(text); 147 146 /* if (text[e->lock-1]=='\n') e->lock--; */ 148 /* e->buffx=x; */149 /* e->buffy=y; */147 e->buffx=x; 148 e->buffy=y; 150 149 owl_editwin_adjust_for_locktext(e); 151 150 owl_editwin_redisplay(e, 0); … … 252 251 253 252 /* start at topline */ 254 ptr1 =e->buff;255 for (i = 0; i <e->topline; i++) {256 ptr2 =strchr(ptr1, '\n');253 ptr1=e->buff; 254 for (i=0; i<e->topline; i++) { 255 ptr2=strchr(ptr1, '\n'); 257 256 if (!ptr2) { 258 257 /* we're already on the last line */ 259 258 break; 260 259 } 261 ptr1 = ptr2 +1;260 ptr1=ptr2+1; 262 261 } 263 262 /* ptr1 now stores the starting point */ 264 263 265 264 /* find the ending point and store it in ptr3 */ 266 ptr2 =ptr1;267 ptr3 =ptr1;268 for (i = 0; i <e->winlines; i++) {269 ptr3 =strchr(ptr2, '\n');265 ptr2=ptr1; 266 ptr3=ptr1; 267 for (i=0; i<e->winlines; i++) { 268 ptr3=strchr(ptr2, '\n'); 270 269 if (!ptr3) { 271 270 /* we've hit the last line */ 272 271 /* print everything to the end */ 273 ptr3 = e->buff + e->bufflen -1;272 ptr3=e->buff+e->bufflen-1; 274 273 ptr3--; 275 274 break; 276 275 } 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') {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') { 285 284 waddstr(e->curswin, buff); 286 285 } else { 287 286 /* translate to echochar, *except* for the locktext */ 288 287 int len; 289 int dolocklen = e->lock - (ptr1 -e->buff);290 291 for (i = 0; i <dolocklen; i++) {288 int dolocklen=e->lock-(ptr1-e->buff); 289 290 for (i=0; i<dolocklen; i++) { 292 291 waddch(e->curswin, buff[i]); 293 292 } 294 len =strlen(buff);295 for (i = 0; i <len-dolocklen; i++) {293 len=strlen(buff); 294 for (i=0; i<len-dolocklen; i++) { 296 295 waddch(e->curswin, e->echochar); 297 296 } 298 297 } 299 wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e));298 wmove(e->curswin, e->buffy-e->topline, e->buffx); 300 299 wnoutrefresh(e->curswin); 301 if (update ==1) {300 if (update==1) { 302 301 doupdate(); 303 302 } 304 303 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 319 /* Insert n bytes at cursor.*/320 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/321 {322 int i, z;323 324 if ((e->bufflen + n) > (e->allocated - 5)) {325 _owl_editwin_addspace(e);326 }327 328 e->bufflen += n;329 e->buff[e->bufflen] = '\0';330 331 z = _owl_editwin_get_index_from_xy(e);332 for (i = e->bufflen - 1; i > z; i--) {333 e->buff[i] = e->buff[i - n];334 }335 304 } 336 305 … … 344 313 int i, z; 345 314 346 z =_owl_editwin_get_index_from_xy(e);315 z=_owl_editwin_get_index_from_xy(e); 347 316 /* move back and line wrap the previous word */ 348 for (i = z -1; ; i--) {317 for (i=z-1; ; i--) { 349 318 /* move back until you find a space or hit the beginning of the line */ 350 if (e->buff[i] ==' ') {319 if (e->buff[i]==' ') { 351 320 /* replace the space with a newline */ 352 e->buff[i] ='\n';321 e->buff[i]='\n'; 353 322 e->buffy++; 354 e->buffx = z - i -1;323 e->buffx=z-i-1; 355 324 /* were we on the last line */ 356 325 return(0); 357 } else if (e->buff[i] == '\n' || i <=e->lock) {358 /* we hit the beg inning of the line or the buffer, we cannot326 } else if (e->buff[i]=='\n' || i<=e->lock) { 327 /* we hit the begginning of the line or the buffer, we cannot 359 328 * wrap. 360 329 */ … … 367 336 * characters over) 368 337 */ 369 void owl_editwin_insert_char(owl_editwin *e, gunichar c) 370 { 371 int z, i, ret, len; 372 char tmp[6]; 373 memset(tmp, '\0', 6); 338 void owl_editwin_insert_char(owl_editwin *e, char c) 339 { 340 341 int z, i, ret; 374 342 375 343 /* \r is \n */ 376 if (c =='\r') {377 c ='\n';378 } 379 380 if (c == '\n' && e->style ==OWL_EDITWIN_STYLE_ONELINE) {344 if (c=='\r') { 345 c='\n'; 346 } 347 348 if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) { 381 349 /* perhaps later this will change some state that allows the string 382 350 to be read */ … … 384 352 } 385 353 386 g_unichar_to_utf8(c, tmp);387 len = strlen(tmp);388 389 354 /* make sure there is enough memory for the new text */ 390 if ((e->bufflen + len) > (e->allocated -5)) {355 if ((e->bufflen+1) > (e->allocated-5)) { 391 356 _owl_editwin_addspace(e); 392 357 } 393 358 394 359 /* get the insertion point */ 395 z =_owl_editwin_get_index_from_xy(e);360 z=_owl_editwin_get_index_from_xy(e); 396 361 397 362 /* If we're going to insert at the last column do word wrapping, unless it's a \n */ 398 if ((e->buffx + 1 == e->wrapcol) && (c !='\n')) {399 ret =_owl_editwin_linewrap_word(e);400 if (ret ==-1) {363 if ((e->buffx+1==e->wrapcol) && (c!='\n')) { 364 ret=_owl_editwin_linewrap_word(e); 365 if (ret==-1) { 401 366 /* we couldn't wrap, insert a hard newline instead */ 402 367 owl_editwin_insert_char(e, '\n'); … … 404 369 } 405 370 371 z=_owl_editwin_get_index_from_xy(e); 406 372 /* shift all the other characters right */ 407 if (z != e->bufflen) { 408 _owl_editwin_insert_bytes(e, len); 409 } 410 411 /* insert the new character */ 412 for(i = 0; i < len; i++) { 413 e->buff[z + i] = tmp[i]; 414 } 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; 415 379 416 380 /* housekeeping */ 417 e->bufflen += len; 418 e->buff[e->bufflen] = '\0'; 381 e->bufflen++; 382 e->buff[e->bufflen]='\0'; 383 384 /* advance the cursor */ 385 if (c=='\n') { 386 e->buffx=0; 387 e->buffy++; 388 } else { 389 e->buffx++; 390 } 391 } 392 393 /* overwrite the character at the current point with 'c' */ 394 void owl_editwin_overwrite_char(owl_editwin *e, char c) 395 { 396 int z; 419 397 420 /* advance the cursor */421 z += len;422 _owl_editwin_set_xy_by_index(e, z);423 }424 425 /* overwrite the character at the current point with 'c' */426 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c)427 {428 int z, oldlen, newlen, i;429 char tmp[6];430 memset(tmp, '\0', 6);431 432 398 /* \r is \n */ 433 if (c =='\r') {434 c ='\n';435 } 436 437 if (c == '\n' && e->style ==OWL_EDITWIN_STYLE_ONELINE) {399 if (c=='\r') { 400 c='\n'; 401 } 402 403 if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) { 438 404 /* perhaps later this will change some state that allows the string 439 405 to be read */ … … 441 407 } 442 408 443 g_unichar_to_utf8(c, tmp); 444 newlen = strlen(tmp); 445 446 z = _owl_editwin_get_index_from_xy(e); 447 { 448 char *t = g_utf8_find_next_char(e->buff + z, NULL); 449 oldlen = (t ? (t - (e->buff + z)) : 0); 450 } 451 452 /* only if we are at the end of the buffer do we create new space here */ 453 if (z == e->bufflen) { 454 if ((e->bufflen+newlen) > (e->allocated-5)) { 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)) { 455 414 _owl_editwin_addspace(e); 456 415 } 457 416 } 458 /* if not at the end of the buffer, adjust based in char size difference. */459 else if (oldlen > newlen) {460 _owl_editwin_remove_bytes(e, oldlen-newlen);461 }462 else /* oldlen < newlen */ {463 _owl_editwin_insert_bytes(e, newlen-oldlen);464 }465 /* Overwrite the old char*/466 for (i = 0; i < newlen; i++) {467 e->buff[z+i] = tmp[i];468 }469 470 /* housekeeping */471 if (z == e->bufflen) {472 e->bufflen += newlen;473 e->buff[e->bufflen] = '\0';474 }475 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 } 425 476 426 /* advance the cursor */ 477 z += newlen; 478 _owl_editwin_set_xy_by_index(e, z); 427 if (c=='\n') { 428 e->buffx=0; 429 e->buffy++; 430 } else { 431 e->buffx++; 432 } 433 479 434 } 480 435 … … 484 439 void owl_editwin_delete_char(owl_editwin *e) 485 440 { 486 int z; 487 char *p1, *p2; 488 gunichar c; 489 490 if (e->bufflen == 0) return; 441 int z, i; 442 443 if (e->bufflen==0) return; 491 444 492 445 /* get the deletion point */ 493 z = _owl_editwin_get_index_from_xy(e); 494 495 if (z == e->bufflen) return; 496 497 p1 = e->buff + z; 498 p2 = g_utf8_next_char(p1); 499 c = g_utf8_get_char(p2); 500 while (g_unichar_ismark(c)) { 501 p2 = g_utf8_next_char(p2); 502 c = g_utf8_get_char(p2); 503 } 504 _owl_editwin_remove_bytes(e, p2-p1); 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'; 505 455 } 506 456 … … 513 463 { 514 464 int z; 515 char *p1, *p2, *p3, *tmp;516 517 if (e->bufflen ==0) return;465 char tmp; 466 467 if (e->bufflen==0) return; 518 468 519 469 /* get the cursor point */ 520 z =_owl_editwin_get_index_from_xy(e);521 522 if (z ==e->bufflen) {470 z=_owl_editwin_get_index_from_xy(e); 471 472 if (z==e->bufflen) { 523 473 /* point is after last character */ 524 474 z--; 525 475 } 526 476 527 if (z -1 < e->lock) {477 if (z-1 < e->lock) { 528 478 /* point is at beginning of buffer, do nothing */ 529 479 return; 530 480 } 531 481 532 /* Transpose two utf-8 unicode glyphs. */ 533 p1 = e->buff + z; 534 535 p2 = g_utf8_find_next_char(p1, NULL); 536 while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) { 537 p2 = g_utf8_find_next_char(p2, NULL); 538 } 539 if (p2 == NULL) return; 540 541 p3 = g_utf8_find_prev_char(e->buff, p1); 542 while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) { 543 p3 = g_utf8_find_prev_char(p3, NULL); 544 } 545 if (p3 == NULL) return; 546 547 tmp = owl_malloc(p2 - p3 + 5); 548 *tmp = '\0'; 549 strncat(tmp, p1, p2 - p1); 550 strncat(tmp, p3, p1 - p3); 551 strncpy(p3, tmp, p2 - p3); 552 owl_free(tmp); 553 _owl_editwin_set_xy_by_index(e, p3 - e->buff); 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); 554 486 } 555 487 … … 559 491 void owl_editwin_insert_string(owl_editwin *e, char *string) 560 492 { 561 char *p; 562 gunichar c; 563 if (!g_utf8_validate(string, -1, NULL)) { 564 owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); 565 return; 566 } 567 p = string; 568 c = g_utf8_get_char(p); 569 while (c) { 570 owl_editwin_process_char(e, c); 571 p = g_utf8_next_char(p); 572 c = g_utf8_get_char(p); 493 int i, j; 494 495 j=strlen(string); 496 for (i=0; i<j; i++) { 497 owl_editwin_insert_char(e, string[i]); 573 498 } 574 499 } … … 580 505 void owl_editwin_overwrite_string(owl_editwin *e, char *string) 581 506 { 582 char *p; 583 gunichar c; 584 585 if (!g_utf8_validate(string, -1, NULL)) { 586 owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string."); 587 return; 588 } 589 p = string; 590 c = g_utf8_get_char(p); 591 while (c) { 592 owl_editwin_overwrite_char(e, c); 593 p = g_utf8_next_char(p); 594 c = g_utf8_get_char(p); 507 int i, j; 508 509 j=strlen(string); 510 for (i=0; i<j; i++) { 511 owl_editwin_overwrite_char(e, string[i]); 595 512 } 596 513 } … … 603 520 int i; 604 521 char *ptr1, *ptr2; 605 gunichar c; 606 607 if (e->bufflen == 0) return(0); 522 523 if (e->bufflen==0) return(0); 608 524 609 525 /* first go to the yth line */ 610 ptr1 =e->buff;611 for (i = 0; i <e->buffy; i++) {612 ptr2= 526 ptr1=e->buff; 527 for (i=0; i<e->buffy; i++) { 528 ptr2=strchr(ptr1, '\n'); 613 529 if (!ptr2) { 614 530 /* we're already on the last line */ 615 531 break; 616 532 } 617 ptr1 = ptr2 + 1; 618 } 619 620 /* now go to the xth cell */ 621 ptr2 = ptr1; 622 i = 0; 623 while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) { 624 c = g_utf8_get_char(ptr2); 625 i += (c == '\n' ? 1 : mk_wcwidth(c)); 626 ptr2 = g_utf8_next_char(ptr2); 627 } 628 while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) { 629 ptr2 = g_utf8_next_char(ptr2); 630 } 631 if (ptr2 == NULL) return e->bufflen; 632 return(ptr2 - e->buff); 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); 633 550 } 634 551 635 552 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 636 553 { 637 char *ptr1, *ptr2, *target; 638 gunichar c; 639 640 e->buffx = 0; 641 e->buffy = 0; 642 643 ptr1 = e->buff; 644 target = ptr1 + index; 645 /* target sanitizing */ 646 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 647 /* middle of a utf-8 character, back up to previous character. */ 648 target = g_utf8_find_prev_char(e->buff, target); 649 } 650 c = g_utf8_get_char(target); 651 while (g_unichar_ismark(c) && target > e->buff) { 652 /* Adjust the target off of combining characters and the like. */ 653 target = g_utf8_find_prev_char(e->buff, target); 654 c = g_utf8_get_char(target); 655 } 656 /* If we start with a mark, something is wrong.*/ 657 if (g_unichar_ismark(c)) return; 658 659 /* Now our target should be acceptable. */ 660 ptr2 = strchr(ptr1, '\n'); 661 while (ptr2 != NULL && ptr2 < target) { 662 e->buffy++; 663 ptr1 = ptr2 + 1; 664 ptr2 = strchr(ptr1, '\n'); 665 } 666 ptr2 = ptr1; 667 while (ptr2 != NULL && ptr2 < target) { 668 c = g_utf8_get_char(ptr2); 669 e->buffx += mk_wcwidth(c); 670 ptr2 = g_utf8_next_char(ptr2); 671 } 672 } 673 674 int _owl_editwin_cursor_adjustment(owl_editwin *e) 675 { 676 char *ptr1, *ptr2; 677 gunichar c; 678 int x, i; 679 680 ptr1 = e->buff; 681 ptr2 = strchr(ptr1, '\n'); 682 for (i = 0; ptr2 != NULL && i < e->buffy; i++) { 683 ptr1 = ptr2 + 1; 684 ptr2 = strchr(ptr1, '\n'); 685 } 686 ptr2 = ptr1; 687 x = 0; 688 while (ptr2 != NULL && x < e->buffx) { 689 if (*ptr2 == '\n') return 0; 690 c = g_utf8_get_char(ptr2); 691 x += mk_wcwidth(c); 692 ptr2 = g_utf8_next_char(ptr2); 693 } 694 return x - e->buffx; 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 } 695 566 } 696 567 … … 699 570 /* if we happen to have the cursor over locked text 700 571 * move it to be out of the locktext region */ 701 if (_owl_editwin_get_index_from_xy(e) <e->lock) {572 if (_owl_editwin_get_index_from_xy(e)<e->lock) { 702 573 _owl_editwin_set_xy_by_index(e, e->lock); 703 574 } … … 719 590 { 720 591 if (e->buffy > 0) e->buffy--; 721 if (e->buffx >= owl_editwin_get_numc ells_on_line(e, e->buffy)) {722 e->buffx=owl_editwin_get_numc ells_on_line(e, e->buffy);592 if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) { 593 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 723 594 } 724 595 … … 737 608 738 609 /* if we're past the last character move back */ 739 if (e->buffx >= owl_editwin_get_numc ells_on_line(e, e->buffy)) {740 e->buffx=owl_editwin_get_numc ells_on_line(e, e->buffy);610 if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) { 611 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 741 612 } 742 613 … … 752 623 void owl_editwin_key_left(owl_editwin *e) 753 624 { 754 int i; 755 char * p; 756 i = _owl_editwin_get_index_from_xy(e); 757 p = e->buff + i; 758 p = g_utf8_find_prev_char(e->buff, p); 759 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 760 p = g_utf8_find_prev_char(e->buff, p); 761 } 762 if (p == NULL) p = e->buff; 763 _owl_editwin_set_xy_by_index(e, p - e->buff); 764 765 if (e->buffy - e->topline < 0) { 766 e->topline -= e->winlines / 2; 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; 767 636 } 768 637 … … 774 643 { 775 644 int i; 776 char * p; 777 i = _owl_editwin_get_index_from_xy(e); 778 p = e->buff + i; 779 p = g_utf8_find_next_char(p, NULL); 780 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 781 p = g_utf8_find_next_char(p, NULL); 782 } 783 if (p == NULL) { 784 _owl_editwin_set_xy_by_index(e, e->bufflen); 785 } 786 else { 787 _owl_editwin_set_xy_by_index(e, p - e->buff); 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 } 788 656 } 789 657 790 658 /* do we need to scroll down? */ 791 if (e->buffy -e->topline >= e->winlines) {792 e->topline += e->winlines /2;659 if (e->buffy-e->topline >= e->winlines) { 660 e->topline+=e->winlines/2; 793 661 } 794 662 } … … 796 664 void owl_editwin_move_to_nextword(owl_editwin *e) 797 665 { 798 /* asedeno: needs fixing for utf-8*/799 666 int i, x; 800 667 … … 836 703 void owl_editwin_move_to_previousword(owl_editwin *e) 837 704 { 838 /* asedeno: needs fixing for utf-8*/839 705 int i, x; 840 706 … … 872 738 void owl_editwin_delete_nextword(owl_editwin *e) 873 739 { 874 /* asedeno: needs fixing for utf-8*/875 740 int z; 876 741 … … 903 768 void owl_editwin_delete_previousword(owl_editwin *e) 904 769 { 905 /* asedeno: needs fixing for utf-8*/906 770 /* go backwards to the last non-space character, then delete chars */ 907 771 int i, startpos, endpos; … … 917 781 void owl_editwin_delete_to_endofline(owl_editwin *e) 918 782 { 919 /* asedeno: needs fixing for utf-8*/920 783 int i; 921 784 922 if (owl_editwin_get_numchars_on_line(e, e->buffy) >e->buffx) {785 if (owl_editwin_get_numchars_on_line(e, e->buffy)>e->buffx) { 923 786 /* normal line */ 924 787 i=_owl_editwin_get_index_from_xy(e); … … 941 804 void owl_editwin_move_to_line_end(owl_editwin *e) 942 805 { 943 e->buffx=owl_editwin_get_numc ells_on_line(e, e->buffy);806 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 944 807 } 945 808 … … 954 817 /* go to last char */ 955 818 e->buffy=owl_editwin_get_numlines(e)-1; 956 e->buffx=owl_editwin_get_numc ells_on_line(e, e->buffy);819 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 957 820 owl_editwin_key_right(e); 958 821 … … 978 841 void owl_editwin_fill_paragraph(owl_editwin *e) 979 842 { 980 /* asedeno: needs fixing for utf-8*/981 843 int i, save; 982 844 … … 995 857 /* main loop */ 996 858 while (1) { 997 i =_owl_editwin_get_index_from_xy(e);859 i=_owl_editwin_get_index_from_xy(e); 998 860 999 861 /* bail if we hit the end of the buffer */ 1000 if (i >= e->bufflen || e->buff[i] == '\0') break;862 if (i>=e->bufflen) break; 1001 863 1002 864 /* bail if we hit the end of the paragraph */ 1003 if (e->buff[i] == '\n' && e->buff[i+1] =='\n') break;865 if (e->buff[i]=='\n' && e->buff[i+1]=='\n') break; 1004 866 1005 867 /* if we've travelled too far, linewrap */ … … 1009 871 1010 872 /* did we hit the end of a line too soon? */ 1011 i =_owl_editwin_get_index_from_xy(e);1012 if (e->buff[i] == '\n' && e->buffx < e->fillcol -1) {873 i=_owl_editwin_get_index_from_xy(e); 874 if (e->buff[i]=='\n' && e->buffx<e->fillcol-1) { 1013 875 /* ********* we need to make sure we don't pull in a word that's too long ***********/ 1014 876 e->buff[i]=' '; … … 1016 878 1017 879 /* fix spacing */ 1018 i =_owl_editwin_get_index_from_xy(e);1019 if (e->buff[i] == ' ' && e->buff[i+1] ==' ') {1020 if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] =='?') {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]=='?') { 1021 883 owl_editwin_key_right(e); 1022 884 } else { 1023 885 owl_editwin_delete_char(e); 1024 886 /* if we did this ahead of the save point, adjust it */ 1025 if (i <save) save--;887 if (i<save) save--; 1026 888 } 1027 889 } else { … … 1049 911 int owl_editwin_check_dotsend(owl_editwin *e) 1050 912 { 1051 char *p, *p_n, *p_p; 1052 gunichar c; 913 int i; 1053 914 1054 915 if (!e->dotsend) return(0); 1055 1056 p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen); 1057 p_n = g_utf8_find_next_char(p, NULL); 1058 p_p = g_utf8_find_prev_char(e->buff, p); 1059 c = g_utf8_get_char(p); 1060 while (p != NULL) { 1061 if (*p == '.' 1062 && p_p != NULL && (*p_p == '\n' || *p_p == '\r') 1063 && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) { 1064 e->bufflen = p - e->buff; 1065 e->buff[e->bufflen] = '\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'; 1066 922 return(1); 1067 923 } 1068 if (c != '\0' && !g_unichar_isspace(c)) return(0); 1069 p_n = p; 1070 p = p_p; 1071 c = g_utf8_get_char(p); 1072 p_p = g_utf8_find_prev_char(e->buff, p); 924 if (!isspace((int) e->buff[i])) { 925 return(0); 926 } 1073 927 } 1074 928 return(0); 1075 929 } 1076 930 1077 void owl_editwin_post_process_char(owl_editwin *e, gunicharj)931 void owl_editwin_post_process_char(owl_editwin *e, int j) 1078 932 { 1079 933 /* check if we need to scroll down */ … … 1088 942 } 1089 943 1090 void owl_editwin_process_char(owl_editwin *e, gunicharj)944 void owl_editwin_process_char(owl_editwin *e, int j) 1091 945 { 1092 946 if (j == ERR) return; 1093 if ( g_unichar_iscntrl(j) && (j != 10) && (j != 13)) {947 if (j>127 || ((j<32) && (j!=10) && (j!=13))) { 1094 948 return; 1095 } 1096 else { 949 } else { 1097 950 owl_editwin_insert_char(e, j); 1098 951 } … … 1122 975 } 1123 976 1124 /* now count characters */ 1125 i = 0; 1126 ptr2 = ptr1; 1127 while (ptr2 - e->buff < e->bufflen 1128 && *ptr2 != '\n') { 1129 ++i; 1130 ptr2 = g_utf8_next_char(ptr2); 1131 } 1132 return i; 1133 } 1134 1135 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line) 1136 { 1137 int i; 1138 char *ptr1, *ptr2; 1139 gunichar c; 1140 1141 if (e->bufflen==0) return(0); 1142 1143 /* first go to the yth line */ 1144 ptr1=e->buff; 1145 for (i=0; i<line; i++) { 1146 ptr2=strchr(ptr1, '\n'); 1147 if (!ptr2) { 1148 /* we're already on the last line */ 1149 return(0); 1150 } 1151 ptr1=ptr2+1; 1152 } 1153 1154 /* now count cells */ 1155 i = 0; 1156 ptr2 = ptr1; 1157 while (ptr2 - e->buff < e->bufflen 1158 && *ptr2 != '\n') { 1159 c = g_utf8_get_char(ptr2); 1160 i += mk_wcwidth(c); 1161 ptr2 = g_utf8_next_char(ptr2); 1162 } 1163 return i; 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 */ 1164 983 } 1165 984
Note: See TracChangeset
for help on using the changeset viewer.