source:
clfs-sysroot/patches/diffutils-2.8.7-i18n-1.patch@
28f76f2
Last change on this file since 28f76f2 was e84c831, checked in by , 16 years ago | |
---|---|
|
|
File size: 17.9 KB |
-
diffutils-2.8.7
Submitted By: Jim Gifford <jim at cross-lfs dot org> Date: 2009-01-08 Initial Package Version: 2.8.7 Upstream Status: Unkown Origin: Mandriva Description: i18n Updates diff -Naur diffutils-2.8.7.orig/src/diff.c diffutils-2.8.7/src/diff.c
old new 273 273 re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING); 274 274 excluded = new_exclude (); 275 275 276 #ifdef HANDLE_MULTIBYTE 277 if (MB_CUR_MAX > 1) 278 lines_differ = lines_differ_multibyte; 279 else 280 #endif 281 lines_differ = lines_differ_singlebyte; 282 276 283 /* Decode the options. */ 277 284 278 285 while ((c = getopt_long (argc, argv, shortopts, longopts, 0)) != -1) -
diffutils-2.8.7
diff -Naur diffutils-2.8.7.orig/src/diff.h diffutils-2.8.7/src/diff.h
old new 25 25 #include <stdio.h> 26 26 #include <unlocked-io.h> 27 27 28 /* For platform which support the ISO C amendement 1 functionality we 29 support user defined character classes. */ 30 #if defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H 31 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */ 32 # include <wchar.h> 33 # include <wctype.h> 34 /* # if defined (HAVE_MBRTOWC) */ 35 # define HANDLE_MULTIBYTE 1 36 /* # endif */ 37 #endif 38 39 #define TAB_WIDTH 8 40 28 41 /* What kind of changes a hunk contains. */ 29 42 enum changes 30 43 { … … 352 365 extern char const pr_program[]; 353 366 char *concat (char const *, char const *, char const *); 354 367 char *dir_file_pathname (char const *, char const *); 355 bool lines_differ (char const *, char const *); 368 369 bool (*lines_differ) (char const *, char const *); 370 bool lines_differ_singlebyte (char const *, char const *); 371 #ifdef HANDLE_MULTIBYTE 372 bool lines_differ_multibyte (char const *, char const *); 373 #endif 374 356 375 lin translate_line_number (struct file_data const *, lin); 357 376 struct change *find_change (struct change *); 358 377 struct change *find_reverse_change (struct change *); -
diffutils-2.8.7
diff -Naur diffutils-2.8.7.orig/src/io.c diffutils-2.8.7/src/io.c
old new 25 25 #include <file-type.h> 26 26 #include <setmode.h> 27 27 #include <xalloc.h> 28 #include <assert.h> 28 29 29 30 /* Rotate an unsigned value to the left. */ 30 31 #define ROL(v, n) ((v) << (n) | (v) >> (sizeof (v) * CHAR_BIT - (n))) … … 212 213 213 214 214 215 /* Split the file into lines, simultaneously computing the equivalence 215 216 class for each line. */ 217 #ifdef HANDLE_MULTIBYTE 218 # define MBC2WC(P, END, MBLENGTH, WC, STATE, CONVFAIL) \ 219 do \ 220 { \ 221 mbstate_t state_bak = STATE; \ 222 \ 223 CONVFAIL = 0; \ 224 MBLENGTH = mbrtowc (&WC, P, END - (char const *)P, &STATE); \ 225 \ 226 switch (MBLENGTH) \ 227 { \ 228 case (size_t)-2: \ 229 case (size_t)-1: \ 230 STATE = state_bak; \ 231 ++CONVFAIL; \ 232 /* Fall through. */ \ 233 case 0: \ 234 MBLENGTH = 1; \ 235 } \ 236 } \ 237 while (0) 238 #endif 216 239 217 240 static void -
diffutils-2.8.7
find_and_hash_each_line (struct file_data *current) @@ -238,12 +261,280 @@ bool same_length_diff_contents_compare_anyway = diff_length_compare_anyway | ignore_case; +#ifdef HANDLE_MULTIBYTE + wchar_t wc; + size_t mblength; + mbstate_t state; + int convfail; + + memset (&state, '\0', sizeof (mbstate_t)); +#endif + while (p < suffix_begin) { char const *ip = p; h = 0; +#ifdef HANDLE_MULTIBYTE + if (MB_CUR_MAX > 1) + { + wchar_t lo_wc; + char mbc[MB_LEN_MAX]; + mbstate_t state_wc; + + /* Hash this line until we find a newline. */ + switch (ignore_white_space) + { + case IGNORE_ALL_SPACE: + while (1) + { + if (*p == '\n') + { + ++p; + break; + } + + MBC2WC (p, suffix_begin, mblength, wc, state, convfail); + + if (convfail) + mbc[0] = *p++; + else if (!iswspace (wc)) + { + bool flag = 0; + + if (ignore_case) + { + lo_wc = towlower (wc); + if (lo_wc != wc) + { + flag = 1; + + p += mblength; + memset (&state_wc, '\0', sizeof(mbstate_t)); + mblength = wcrtomb (mbc, lo_wc, &state_wc); + + assert (mblength != (size_t)-1 && + mblength != (size_t)-2); + + mblength = (mblength < 1) ? 1 : mblength; + } + } + + if (!flag) + { + for (i = 0; i < mblength; i++) + mbc[i] = *p++; + } + } + else + { + p += mblength; + continue; + } + + for (i = 0; i < mblength; i++) + h = HASH (h, mbc[i]); + } + break; + + case IGNORE_SPACE_CHANGE: + while (1) + { + if (*p == '\n') + { + ++p; + break; + } + MBC2WC (p, suffix_begin, mblength, wc, state, convfail); + + if (!convfail && iswspace (wc)) + { + while (1) + { + if (*p == '\n') + { + ++p; + goto hashing_done; + } + + p += mblength; + MBC2WC (p, suffix_begin, mblength, wc, state, convfail); + if (convfail || (!convfail && !iswspace (wc))) + break; + } + h = HASH (h, ' '); + } + + /* WC is now the first non-space. */ + if (convfail) + mbc[0] = *p++; + else + { + bool flag = 0; + + if (ignore_case) + { + lo_wc = towlower (wc); + if (lo_wc != wc) + { + flag = 1; + + p += mblength; + memset (&state_wc, '\0', sizeof(mbstate_t)); + mblength = wcrtomb (mbc, lo_wc, &state_wc); + + assert (mblength != (size_t)-1 && + mblength != (size_t)-2); + + mblength = (mblength < 1) ? 1 : mblength; + } + } + + if (!flag) + { + for (i = 0; i < mblength; i++) + mbc[i] = *p++; + } + } + + for (i = 0; i < mblength; i++) + h = HASH (h, mbc[i]); + } + break; + + case IGNORE_TAB_EXPANSION: + { + size_t column = 0; + + while (1) + { + if (*p == '\n') + { + ++p; + break; + } + + MBC2WC (p, suffix_begin, mblength, wc, state, convfail); + + if (convfail) + { + h = HASH (h, *p++); + ++column; + } + else + { + bool flag; + + switch (wc) + { + case L'\b': + column -= 0 < column; + h = HASH (h, '\b'); + ++p; + break; + + case L'\t': + { + int repetitions; + + repetitions = TAB_WIDTH - column % TAB_WIDTH; + column += repetitions; + do + h = HASH (h, ' '); + while (--repetitions != 0); + ++p; + } + break; + + case L'\r': + column = 0; + h = HASH (h, '\r'); + ++p; + break; + + default: + flag = 0; + column += wcwidth (wc); + if (ignore_case) + { + lo_wc = towlower (wc); + if (lo_wc != wc) + { + flag = 1; + p += mblength; + memset (&state_wc, '\0', sizeof(mbstate_t)); + mblength = wcrtomb (mbc, lo_wc, &state_wc); + + assert (mblength != (size_t)-1 && + mblength != (size_t)-2); + + mblength = (mblength < 1) ? 1 : mblength; + } + } + + if (!flag) + { + for (i = 0; i < mblength; i++) + mbc[i] = *p++; + } + + for (i = 0; i < mblength; i++) + h = HASH (h, mbc[i]); + } + } + } + } + break; + + default: + while (1) + { + if (*p == '\n') + { + ++p; + break; + } + + MBC2WC (p, suffix_begin, mblength, wc, state, convfail); + + if (convfail) + mbc[0] = *p++; + else + { + int flag = 0; + + if (ignore_case) + { + lo_wc = towlower (wc); + if (lo_wc != wc) + { + flag = 1; + p += mblength; + memset (&state_wc, '\0', sizeof(mbstate_t)); + mblength = wcrtomb (mbc, lo_wc, &state_wc); + + assert (mblength != (size_t)-1 && + mblength != (size_t)-2); + + mblength = (mblength < 1) ? 1 : mblength; + } + } + + if (!flag) + { + for (i = 0; i < mblength; i++) + mbc[i] = *p++; + } + } + + for (i = 0; i < mblength; i++) + h = HASH (h, mbc[i]); + } + } + } + else +#endif /* Hash this line until we find a newline. */ if (ignore_case) switch (ignore_white_space) diff -Naur diffutils-2.8.7.orig/src/side.c diffutils-2.8.7/src/side.c
old new 73 73 register size_t out_position = 0; 74 74 register char const *text_pointer = line[0]; 75 75 register char const *text_limit = line[1]; 76 #if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H 77 unsigned char mbc[MB_LEN_MAX]; 78 wchar_t wc; 79 mbstate_t state, state_bak; 80 size_t mbc_pos, mblength; 81 int mbc_loading_flag = 0; 82 int wc_width; 83 84 memset (&state, '\0', sizeof (mbstate_t)); 85 #endif 76 86 77 87 while (text_pointer < text_limit) 78 88 { 79 89 register unsigned char c = *text_pointer++; 80 90 91 #if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H 92 if (MB_CUR_MAX > 1 && mbc_loading_flag) 93 { 94 mbc_loading_flag = 0; 95 state_bak = state; 96 mbc[mbc_pos++] = c; 97 98 process_mbc: 99 mblength = mbrtowc (&wc, mbc, mbc_pos, &state); 100 101 switch (mblength) 102 { 103 case (size_t)-2: /* Incomplete multibyte character. */ 104 mbc_loading_flag = 1; 105 state = state_bak; 106 break; 107 108 case (size_t)-1: /* Invalid as a multibyte character. */ 109 if (in_position++ < out_bound) 110 { 111 out_position = in_position; 112 putc (mbc[0], out); 113 } 114 memmove (mbc, mbc + 1, --mbc_pos); 115 if (mbc_pos > 0) 116 { 117 mbc[mbc_pos] = '\0'; 118 goto process_mbc; 119 } 120 break; 121 122 default: 123 wc_width = wcwidth (wc); 124 if (wc_width < 1) /* Unprintable multibyte character. */ 125 { 126 if (in_position <= out_bound) 127 fprintf (out, "%lc", (wint_t)wc); 128 } 129 else /* Printable multibyte character. */ 130 { 131 in_position += wc_width; 132 if (in_position <= out_bound) 133 { 134 out_position = in_position; 135 fprintf (out, "%lc", (wint_t)wc); 136 } 137 } 138 } 139 continue; 140 } 141 #endif 81 142 switch (c) 82 143 { 83 144 case '\t': … … 135 196 break; 136 197 137 198 default: 138 if (! isprint (c)) 139 goto control_char; 199 #if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H 200 if (MB_CUR_MAX > 1) 201 { 202 memset (mbc, '\0', MB_LEN_MAX); 203 mbc_pos = 0; 204 mbc[mbc_pos++] = c; 205 state_bak = state; 206 207 mblength = mbrtowc (&wc, mbc, mbc_pos, &state); 208 209 /* The value of mblength is always less than 2 here. */ 210 switch (mblength) 211 { 212 case (size_t)-2: /* Incomplete multibyte character. */ 213 state = state_bak; 214 mbc_loading_flag = 1; 215 continue; 216 217 case (size_t)-1: /* Invalid as a multibyte character. */ 218 state = state_bak; 219 break; 220 221 default: 222 if (! iswprint (wc)) 223 goto control_char; 224 } 225 } 226 else 227 #endif 228 { 229 if (! isprint (c)) 230 goto control_char; 231 } 140 232 /* falls through */ 141 233 case ' ': 142 234 if (in_position++ < out_bound) -
diffutils-2.8.7
diff -Naur diffutils-2.8.7.orig/src/util.c diffutils-2.8.7/src/util.c
old new 319 319 Return nonzero if the lines differ. */ 320 320 321 321 bool 322 lines_differ (char const *s1, char const *s2)322 lines_differ_singlebyte (char const *s1, char const *s2) 323 323 { 324 324 register char const *t1 = s1; 325 325 register char const *t2 = s2; … … 458 458 return start; 459 459 } 460 460 461 #ifdef HANDLE_MULTIBYTE 462 # define MBC2WC(T, END, MBLENGTH, WC, STATE, CONVFAIL) \ 463 do \ 464 { \ 465 mbstate_t bak = STATE; \ 466 \ 467 CONVFAIL = 0; \ 468 MBLENGTH = mbrtowc (&WC, T, END - T, &STATE); \ 469 \ 470 switch (MBLENGTH) \ 471 { \ 472 case (size_t)-2: \ 473 case (size_t)-1: \ 474 STATE = bak; \ 475 ++CONVFAIL; \ 476 /* Fall through. */ \ 477 case 0: \ 478 MBLENGTH = 1; \ 479 } \ 480 } \ 481 while (0) 482 483 bool 484 lines_differ_multibyte (char const *s1, char const *s2) 485 { 486 unsigned char const *end1, *end2; 487 unsigned char c1, c2; 488 wchar_t wc1, wc2, wc1_bak, wc2_bak; 489 size_t mblen1, mblen2; 490 mbstate_t state1, state2, state1_bak, state2_bak; 491 int convfail1, convfail2, convfail1_bak, convfail2_bak; 492 493 unsigned char const *t1 = (unsigned char const *) s1; 494 unsigned char const *t2 = (unsigned char const *) s2; 495 unsigned char const *t1_bak, *t2_bak; 496 size_t column = 0; 497 498 if (ignore_white_space == IGNORE_NO_WHITE_SPACE && !ignore_case) 499 { 500 while (*t1 != '\n') 501 if (*t1++ != * t2++) 502 return 1; 503 return 0; 504 } 505 506 memset (&state1, '\0', sizeof (mbstate_t)); 507 memset (&state2, '\0', sizeof (mbstate_t)); 508 509 end1 = s1 + strlen (s1); 510 end2 = s2 + strlen (s2); 511 512 while (1) 513 { 514 c1 = *t1; 515 c2 = *t2; 516 MBC2WC (t1, end1, mblen1, wc1, state1, convfail1); 517 MBC2WC (t2, end2, mblen2, wc2, state2, convfail2); 518 519 /* Test for exact char equality first, since it's a common case. */ 520 if (convfail1 ^ convfail2) 521 break; 522 else if (convfail1 && convfail2 && c1 != c2) 523 break; 524 else if (!convfail1 && !convfail2 && wc1 != wc2) 525 { 526 switch (ignore_white_space) 527 { 528 case IGNORE_ALL_SPACE: 529 /* For -w, just skip past any white space. */ 530 while (1) 531 { 532 if (convfail1) 533 break; 534 else if (wc1 == L'\n' || !iswspace (wc1)) 535 break; 536 537 t1 += mblen1; 538 c1 = *t1; 539 MBC2WC (t1, end1, mblen1, wc1, state1, convfail1); 540 } 541 542 while (1) 543 { 544 if (convfail2) 545 break; 546 else if (wc2 == L'\n' || !iswspace (wc2)) 547 break; 548 549 t2 += mblen2; 550 c2 = *t2; 551 MBC2WC (t2, end2, mblen2, wc2, state2, convfail2); 552 } 553 t1 += mblen1; 554 t2 += mblen2; 555 break; 556 557 case IGNORE_SPACE_CHANGE: 558 /* For -b, advance past any sequence of white space in 559 line 1 and consider it just one space, or nothing at 560 all if it is at the end of the line. */ 561 if (wc1 != L'\n' && iswspace (wc1)) 562 { 563 size_t mblen_bak; 564 mbstate_t state_bak; 565 566 do 567 { 568 t1 += mblen1; 569 mblen_bak = mblen1; 570 state_bak = state1; 571 MBC2WC (t1, end1, mblen1, wc1, state1, convfail1); 572 } 573 while (!convfail1 && (wc1 != L'\n' && iswspace (wc1))); 574 575 state1 = state_bak; 576 mblen1 = mblen_bak; 577 t1 -= mblen1; 578 convfail1 = 0; 579 wc1 = L' '; 580 } 581 582 /* Likewise for line 2. */ 583 if (wc2 != L'\n' && iswspace (wc2)) 584 { 585 size_t mblen_bak; 586 mbstate_t state_bak; 587 588 do 589 { 590 t2 += mblen2; 591 mblen_bak = mblen2; 592 state_bak = state2; 593 MBC2WC (t2, end2, mblen2, wc2, state2, convfail2); 594 } 595 while (!convfail2 && (wc2 != L'\n' && iswspace (wc2))); 596 597 state2 = state_bak; 598 mblen2 = mblen_bak; 599 t2 -= mblen2; 600 convfail2 = 0; 601 wc2 = L' '; 602 } 603 604 if (wc1 != wc2) 605 { 606 if (wc2 == L' ' && wc1 != L'\n' && 607 t1 > (unsigned char const *)s1 && 608 !convfail1_bak && iswspace (wc1_bak)) 609 { 610 t1 = t1_bak; 611 wc1 = wc1_bak; 612 state1 = state1_bak; 613 convfail1 = convfail1_bak; 614 continue; 615 } 616 if (wc1 == L' ' && wc2 != L'\n' 617 && t2 > (unsigned char const *)s2 618 && !convfail2_bak && iswspace (wc2_bak)) 619 { 620 t2 = t2_bak; 621 wc2 = wc2_bak; 622 state2 = state2_bak; 623 convfail2 = convfail2_bak; 624 continue; 625 } 626 } 627 628 t1_bak = t1; t2_bak = t2; 629 wc1_bak = wc1; wc2_bak = wc2; 630 state1_bak = state1; state2_bak = state2; 631 convfail1_bak = convfail1; convfail2_bak = convfail2; 632 633 if (wc1 == L'\n') 634 wc1 = L' '; 635 else 636 t1 += mblen1; 637 638 if (wc2 == L'\n') 639 wc2 = L' '; 640 else 641 t2 += mblen2; 642 643 break; 644 645 case IGNORE_TAB_EXPANSION: 646 if ((wc1 == L' ' && wc2 == L'\t') 647 || (wc1 == L'\t' && wc2 == L' ')) 648 { 649 size_t column2 = column; 650 651 while (1) 652 { 653 if (convfail1) 654 { 655 ++t1; 656 break; 657 } 658 else if (wc1 == L' ') 659 column++; 660 else if (wc1 == L'\t') 661 column += TAB_WIDTH - column % TAB_WIDTH; 662 else 663 { 664 t1 += mblen1; 665 break; 666 } 667 668 t1 += mblen1; 669 c1 = *t1; 670 MBC2WC (t1, end1, mblen1, wc1, state1, convfail1); 671 } 672 673 while (1) 674 { 675 if (convfail2) 676 { 677 ++t2; 678 break; 679 } 680 else if (wc2 == L' ') 681 column2++; 682 else if (wc2 == L'\t') 683 column2 += TAB_WIDTH - column2 % TAB_WIDTH; 684 else 685 { 686 t2 += mblen2; 687 break; 688 } 689 690 t2 += mblen2; 691 c2 = *t2; 692 MBC2WC (t2, end2, mblen2, wc2, state2, convfail2); 693 } 694 695 if (column != column2) 696 return 1; 697 } 698 else 699 { 700 t1 += mblen1; 701 t2 += mblen2; 702 } 703 break; 704 705 case IGNORE_NO_WHITE_SPACE: 706 t1 += mblen1; 707 t2 += mblen2; 708 break; 709 } 710 711 /* Lowercase all letters if -i is specified. */ 712 if (ignore_case) 713 { 714 if (!convfail1) 715 wc1 = towlower (wc1); 716 if (!convfail2) 717 wc2 = towlower (wc2); 718 } 719 720 if (convfail1 ^ convfail2) 721 break; 722 else if (convfail1 && convfail2 && c1 != c2) 723 break; 724 else if (!convfail1 && !convfail2 && wc1 != wc2) 725 break; 726 } 727 else 728 { 729 t1_bak = t1; t2_bak = t2; 730 wc1_bak = wc1; wc2_bak = wc2; 731 state1_bak = state1; state2_bak = state2; 732 convfail1_bak = convfail1; convfail2_bak = convfail2; 733 734 t1 += mblen1; t2 += mblen2; 735 } 736 737 if (!convfail1 && wc1 == L'\n') 738 return 0; 739 740 column += convfail1 ? 1 : 741 (wc1 == L'\t') ? TAB_WIDTH - column % TAB_WIDTH : wcwidth (wc1); 742 } 743 744 return 1; 745 } 746 #endif 747 461 748 struct change * 462 749 find_reverse_change (struct change *start) 463 750 {
Note:
See TracBrowser
for help on using the repository browser.