[92584937] | 1 | Submitted By: Jim Gifford <jim at cross-lfs dot org>
|
---|
| 2 | Date: 2009-01-08
|
---|
| 3 | Initial Package Version: 2.8.7
|
---|
| 4 | Upstream Status: Unkown
|
---|
| 5 | Origin: Mandriva
|
---|
| 6 | Description: i18n Updates
|
---|
| 7 |
|
---|
| 8 | diff -Naur diffutils-2.8.7.orig/src/diff.c diffutils-2.8.7/src/diff.c
|
---|
| 9 | --- diffutils-2.8.7.orig/src/diff.c 2004-04-12 00:44:35.000000000 -0700
|
---|
| 10 | +++ diffutils-2.8.7/src/diff.c 2009-01-08 13:26:42.000000000 -0800
|
---|
| 11 | @@ -273,6 +273,13 @@
|
---|
| 12 | re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING);
|
---|
| 13 | excluded = new_exclude ();
|
---|
| 14 |
|
---|
| 15 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 16 | + if (MB_CUR_MAX > 1)
|
---|
| 17 | + lines_differ = lines_differ_multibyte;
|
---|
| 18 | + else
|
---|
| 19 | +#endif
|
---|
| 20 | + lines_differ = lines_differ_singlebyte;
|
---|
| 21 | +
|
---|
| 22 | /* Decode the options. */
|
---|
| 23 |
|
---|
| 24 | while ((c = getopt_long (argc, argv, shortopts, longopts, 0)) != -1)
|
---|
| 25 | diff -Naur diffutils-2.8.7.orig/src/diff.h diffutils-2.8.7/src/diff.h
|
---|
| 26 | --- diffutils-2.8.7.orig/src/diff.h 2004-04-12 00:44:35.000000000 -0700
|
---|
| 27 | +++ diffutils-2.8.7/src/diff.h 2009-01-08 13:26:42.000000000 -0800
|
---|
| 28 | @@ -25,6 +25,19 @@
|
---|
| 29 | #include <stdio.h>
|
---|
| 30 | #include <unlocked-io.h>
|
---|
| 31 |
|
---|
| 32 | +/* For platform which support the ISO C amendement 1 functionality we
|
---|
| 33 | + support user defined character classes. */
|
---|
| 34 | +#if defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H
|
---|
| 35 | +/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
|
---|
| 36 | +# include <wchar.h>
|
---|
| 37 | +# include <wctype.h>
|
---|
| 38 | +/* # if defined (HAVE_MBRTOWC) */
|
---|
| 39 | +# define HANDLE_MULTIBYTE 1
|
---|
| 40 | +/* # endif */
|
---|
| 41 | +#endif
|
---|
| 42 | +
|
---|
| 43 | +#define TAB_WIDTH 8
|
---|
| 44 | +
|
---|
| 45 | /* What kind of changes a hunk contains. */
|
---|
| 46 | enum changes
|
---|
| 47 | {
|
---|
| 48 | @@ -352,7 +365,13 @@
|
---|
| 49 | extern char const pr_program[];
|
---|
| 50 | char *concat (char const *, char const *, char const *);
|
---|
| 51 | char *dir_file_pathname (char const *, char const *);
|
---|
| 52 | -bool lines_differ (char const *, char const *);
|
---|
| 53 | +
|
---|
| 54 | +bool (*lines_differ) (char const *, char const *);
|
---|
| 55 | +bool lines_differ_singlebyte (char const *, char const *);
|
---|
| 56 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 57 | +bool lines_differ_multibyte (char const *, char const *);
|
---|
| 58 | +#endif
|
---|
| 59 | +
|
---|
| 60 | lin translate_line_number (struct file_data const *, lin);
|
---|
| 61 | struct change *find_change (struct change *);
|
---|
| 62 | struct change *find_reverse_change (struct change *);
|
---|
| 63 | diff -Naur diffutils-2.8.7.orig/src/io.c diffutils-2.8.7/src/io.c
|
---|
| 64 | --- diffutils-2.8.7.orig/src/io.c 2004-04-12 00:44:35.000000000 -0700
|
---|
| 65 | +++ diffutils-2.8.7/src/io.c 2009-01-08 13:26:42.000000000 -0800
|
---|
| 66 | @@ -25,6 +25,7 @@
|
---|
| 67 | #include <file-type.h>
|
---|
| 68 | #include <setmode.h>
|
---|
| 69 | #include <xalloc.h>
|
---|
| 70 | +#include <assert.h>
|
---|
| 71 |
|
---|
| 72 | /* Rotate an unsigned value to the left. */
|
---|
| 73 | #define ROL(v, n) ((v) << (n) | (v) >> (sizeof (v) * CHAR_BIT - (n)))
|
---|
| 74 | @@ -212,6 +213,28 @@
|
---|
| 75 | |
---|
| 76 |
|
---|
| 77 | /* Split the file into lines, simultaneously computing the equivalence
|
---|
| 78 | class for each line. */
|
---|
| 79 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 80 | +# define MBC2WC(P, END, MBLENGTH, WC, STATE, CONVFAIL) \
|
---|
| 81 | +do \
|
---|
| 82 | +{ \
|
---|
| 83 | + mbstate_t state_bak = STATE; \
|
---|
| 84 | + \
|
---|
| 85 | + CONVFAIL = 0; \
|
---|
| 86 | + MBLENGTH = mbrtowc (&WC, P, END - (char const *)P, &STATE); \
|
---|
| 87 | + \
|
---|
| 88 | + switch (MBLENGTH) \
|
---|
| 89 | + { \
|
---|
| 90 | + case (size_t)-2: \
|
---|
| 91 | + case (size_t)-1: \
|
---|
| 92 | + STATE = state_bak; \
|
---|
| 93 | + ++CONVFAIL; \
|
---|
| 94 | + /* Fall through. */ \
|
---|
| 95 | + case 0: \
|
---|
| 96 | + MBLENGTH = 1; \
|
---|
| 97 | + } \
|
---|
| 98 | +} \
|
---|
| 99 | +while (0)
|
---|
| 100 | +#endif
|
---|
| 101 |
|
---|
| 102 | static void
|
---|
| 103 | find_and_hash_each_line (struct file_data *current)
|
---|
| 104 | @@ -238,12 +261,280 @@
|
---|
| 105 | bool same_length_diff_contents_compare_anyway =
|
---|
| 106 | diff_length_compare_anyway | ignore_case;
|
---|
| 107 |
|
---|
| 108 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 109 | + wchar_t wc;
|
---|
| 110 | + size_t mblength;
|
---|
| 111 | + mbstate_t state;
|
---|
| 112 | + int convfail;
|
---|
| 113 | +
|
---|
| 114 | + memset (&state, '\0', sizeof (mbstate_t));
|
---|
| 115 | +#endif
|
---|
| 116 | +
|
---|
| 117 | while (p < suffix_begin)
|
---|
| 118 | {
|
---|
| 119 | char const *ip = p;
|
---|
| 120 |
|
---|
| 121 | h = 0;
|
---|
| 122 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 123 | + if (MB_CUR_MAX > 1)
|
---|
| 124 | + {
|
---|
| 125 | + wchar_t lo_wc;
|
---|
| 126 | + char mbc[MB_LEN_MAX];
|
---|
| 127 | + mbstate_t state_wc;
|
---|
| 128 | +
|
---|
| 129 | + /* Hash this line until we find a newline. */
|
---|
| 130 | + switch (ignore_white_space)
|
---|
| 131 | + {
|
---|
| 132 | + case IGNORE_ALL_SPACE:
|
---|
| 133 | + while (1)
|
---|
| 134 | + {
|
---|
| 135 | + if (*p == '\n')
|
---|
| 136 | + {
|
---|
| 137 | + ++p;
|
---|
| 138 | + break;
|
---|
| 139 | + }
|
---|
| 140 | +
|
---|
| 141 | + MBC2WC (p, suffix_begin, mblength, wc, state, convfail);
|
---|
| 142 | +
|
---|
| 143 | + if (convfail)
|
---|
| 144 | + mbc[0] = *p++;
|
---|
| 145 | + else if (!iswspace (wc))
|
---|
| 146 | + {
|
---|
| 147 | + bool flag = 0;
|
---|
| 148 | +
|
---|
| 149 | + if (ignore_case)
|
---|
| 150 | + {
|
---|
| 151 | + lo_wc = towlower (wc);
|
---|
| 152 | + if (lo_wc != wc)
|
---|
| 153 | + {
|
---|
| 154 | + flag = 1;
|
---|
| 155 | +
|
---|
| 156 | + p += mblength;
|
---|
| 157 | + memset (&state_wc, '\0', sizeof(mbstate_t));
|
---|
| 158 | + mblength = wcrtomb (mbc, lo_wc, &state_wc);
|
---|
| 159 | +
|
---|
| 160 | + assert (mblength != (size_t)-1 &&
|
---|
| 161 | + mblength != (size_t)-2);
|
---|
| 162 | +
|
---|
| 163 | + mblength = (mblength < 1) ? 1 : mblength;
|
---|
| 164 | + }
|
---|
| 165 | + }
|
---|
| 166 | +
|
---|
| 167 | + if (!flag)
|
---|
| 168 | + {
|
---|
| 169 | + for (i = 0; i < mblength; i++)
|
---|
| 170 | + mbc[i] = *p++;
|
---|
| 171 | + }
|
---|
| 172 | + }
|
---|
| 173 | + else
|
---|
| 174 | + {
|
---|
| 175 | + p += mblength;
|
---|
| 176 | + continue;
|
---|
| 177 | + }
|
---|
| 178 | +
|
---|
| 179 | + for (i = 0; i < mblength; i++)
|
---|
| 180 | + h = HASH (h, mbc[i]);
|
---|
| 181 | + }
|
---|
| 182 | + break;
|
---|
| 183 | +
|
---|
| 184 | + case IGNORE_SPACE_CHANGE:
|
---|
| 185 | + while (1)
|
---|
| 186 | + {
|
---|
| 187 | + if (*p == '\n')
|
---|
| 188 | + {
|
---|
| 189 | + ++p;
|
---|
| 190 | + break;
|
---|
| 191 | + }
|
---|
| 192 |
|
---|
| 193 | + MBC2WC (p, suffix_begin, mblength, wc, state, convfail);
|
---|
| 194 | +
|
---|
| 195 | + if (!convfail && iswspace (wc))
|
---|
| 196 | + {
|
---|
| 197 | + while (1)
|
---|
| 198 | + {
|
---|
| 199 | + if (*p == '\n')
|
---|
| 200 | + {
|
---|
| 201 | + ++p;
|
---|
| 202 | + goto hashing_done;
|
---|
| 203 | + }
|
---|
| 204 | +
|
---|
| 205 | + p += mblength;
|
---|
| 206 | + MBC2WC (p, suffix_begin, mblength, wc, state, convfail);
|
---|
| 207 | + if (convfail || (!convfail && !iswspace (wc)))
|
---|
| 208 | + break;
|
---|
| 209 | + }
|
---|
| 210 | + h = HASH (h, ' ');
|
---|
| 211 | + }
|
---|
| 212 | +
|
---|
| 213 | + /* WC is now the first non-space. */
|
---|
| 214 | + if (convfail)
|
---|
| 215 | + mbc[0] = *p++;
|
---|
| 216 | + else
|
---|
| 217 | + {
|
---|
| 218 | + bool flag = 0;
|
---|
| 219 | +
|
---|
| 220 | + if (ignore_case)
|
---|
| 221 | + {
|
---|
| 222 | + lo_wc = towlower (wc);
|
---|
| 223 | + if (lo_wc != wc)
|
---|
| 224 | + {
|
---|
| 225 | + flag = 1;
|
---|
| 226 | +
|
---|
| 227 | + p += mblength;
|
---|
| 228 | + memset (&state_wc, '\0', sizeof(mbstate_t));
|
---|
| 229 | + mblength = wcrtomb (mbc, lo_wc, &state_wc);
|
---|
| 230 | +
|
---|
| 231 | + assert (mblength != (size_t)-1 &&
|
---|
| 232 | + mblength != (size_t)-2);
|
---|
| 233 | +
|
---|
| 234 | + mblength = (mblength < 1) ? 1 : mblength;
|
---|
| 235 | + }
|
---|
| 236 | + }
|
---|
| 237 | +
|
---|
| 238 | + if (!flag)
|
---|
| 239 | + {
|
---|
| 240 | + for (i = 0; i < mblength; i++)
|
---|
| 241 | + mbc[i] = *p++;
|
---|
| 242 | + }
|
---|
| 243 | + }
|
---|
| 244 | +
|
---|
| 245 | + for (i = 0; i < mblength; i++)
|
---|
| 246 | + h = HASH (h, mbc[i]);
|
---|
| 247 | + }
|
---|
| 248 | + break;
|
---|
| 249 | +
|
---|
| 250 | + case IGNORE_TAB_EXPANSION:
|
---|
| 251 | + {
|
---|
| 252 | + size_t column = 0;
|
---|
| 253 | +
|
---|
| 254 | + while (1)
|
---|
| 255 | + {
|
---|
| 256 | + if (*p == '\n')
|
---|
| 257 | + {
|
---|
| 258 | + ++p;
|
---|
| 259 | + break;
|
---|
| 260 | + }
|
---|
| 261 | +
|
---|
| 262 | + MBC2WC (p, suffix_begin, mblength, wc, state, convfail);
|
---|
| 263 | +
|
---|
| 264 | + if (convfail)
|
---|
| 265 | + {
|
---|
| 266 | + h = HASH (h, *p++);
|
---|
| 267 | + ++column;
|
---|
| 268 | + }
|
---|
| 269 | + else
|
---|
| 270 | + {
|
---|
| 271 | + bool flag;
|
---|
| 272 | +
|
---|
| 273 | + switch (wc)
|
---|
| 274 | + {
|
---|
| 275 | + case L'\b':
|
---|
| 276 | + column -= 0 < column;
|
---|
| 277 | + h = HASH (h, '\b');
|
---|
| 278 | + ++p;
|
---|
| 279 | + break;
|
---|
| 280 | +
|
---|
| 281 | + case L'\t':
|
---|
| 282 | + {
|
---|
| 283 | + int repetitions;
|
---|
| 284 | +
|
---|
| 285 | + repetitions = TAB_WIDTH - column % TAB_WIDTH;
|
---|
| 286 | + column += repetitions;
|
---|
| 287 | + do
|
---|
| 288 | + h = HASH (h, ' ');
|
---|
| 289 | + while (--repetitions != 0);
|
---|
| 290 | + ++p;
|
---|
| 291 | + }
|
---|
| 292 | + break;
|
---|
| 293 | +
|
---|
| 294 | + case L'\r':
|
---|
| 295 | + column = 0;
|
---|
| 296 | + h = HASH (h, '\r');
|
---|
| 297 | + ++p;
|
---|
| 298 | + break;
|
---|
| 299 | +
|
---|
| 300 | + default:
|
---|
| 301 | + flag = 0;
|
---|
| 302 | + column += wcwidth (wc);
|
---|
| 303 | + if (ignore_case)
|
---|
| 304 | + {
|
---|
| 305 | + lo_wc = towlower (wc);
|
---|
| 306 | + if (lo_wc != wc)
|
---|
| 307 | + {
|
---|
| 308 | + flag = 1;
|
---|
| 309 | + p += mblength;
|
---|
| 310 | + memset (&state_wc, '\0', sizeof(mbstate_t));
|
---|
| 311 | + mblength = wcrtomb (mbc, lo_wc, &state_wc);
|
---|
| 312 | +
|
---|
| 313 | + assert (mblength != (size_t)-1 &&
|
---|
| 314 | + mblength != (size_t)-2);
|
---|
| 315 | +
|
---|
| 316 | + mblength = (mblength < 1) ? 1 : mblength;
|
---|
| 317 | + }
|
---|
| 318 | + }
|
---|
| 319 | +
|
---|
| 320 | + if (!flag)
|
---|
| 321 | + {
|
---|
| 322 | + for (i = 0; i < mblength; i++)
|
---|
| 323 | + mbc[i] = *p++;
|
---|
| 324 | + }
|
---|
| 325 | +
|
---|
| 326 | + for (i = 0; i < mblength; i++)
|
---|
| 327 | + h = HASH (h, mbc[i]);
|
---|
| 328 | + }
|
---|
| 329 | + }
|
---|
| 330 | + }
|
---|
| 331 | + }
|
---|
| 332 | + break;
|
---|
| 333 | +
|
---|
| 334 | + default:
|
---|
| 335 | + while (1)
|
---|
| 336 | + {
|
---|
| 337 | + if (*p == '\n')
|
---|
| 338 | + {
|
---|
| 339 | + ++p;
|
---|
| 340 | + break;
|
---|
| 341 | + }
|
---|
| 342 | +
|
---|
| 343 | + MBC2WC (p, suffix_begin, mblength, wc, state, convfail);
|
---|
| 344 | +
|
---|
| 345 | + if (convfail)
|
---|
| 346 | + mbc[0] = *p++;
|
---|
| 347 | + else
|
---|
| 348 | + {
|
---|
| 349 | + int flag = 0;
|
---|
| 350 | +
|
---|
| 351 | + if (ignore_case)
|
---|
| 352 | + {
|
---|
| 353 | + lo_wc = towlower (wc);
|
---|
| 354 | + if (lo_wc != wc)
|
---|
| 355 | + {
|
---|
| 356 | + flag = 1;
|
---|
| 357 | + p += mblength;
|
---|
| 358 | + memset (&state_wc, '\0', sizeof(mbstate_t));
|
---|
| 359 | + mblength = wcrtomb (mbc, lo_wc, &state_wc);
|
---|
| 360 | +
|
---|
| 361 | + assert (mblength != (size_t)-1 &&
|
---|
| 362 | + mblength != (size_t)-2);
|
---|
| 363 | +
|
---|
| 364 | + mblength = (mblength < 1) ? 1 : mblength;
|
---|
| 365 | + }
|
---|
| 366 | + }
|
---|
| 367 | +
|
---|
| 368 | + if (!flag)
|
---|
| 369 | + {
|
---|
| 370 | + for (i = 0; i < mblength; i++)
|
---|
| 371 | + mbc[i] = *p++;
|
---|
| 372 | + }
|
---|
| 373 | + }
|
---|
| 374 | +
|
---|
| 375 | + for (i = 0; i < mblength; i++)
|
---|
| 376 | + h = HASH (h, mbc[i]);
|
---|
| 377 | + }
|
---|
| 378 | + }
|
---|
| 379 | + }
|
---|
| 380 | + else
|
---|
| 381 | +#endif
|
---|
| 382 | /* Hash this line until we find a newline. */
|
---|
| 383 | if (ignore_case)
|
---|
| 384 | switch (ignore_white_space)
|
---|
| 385 | diff -Naur diffutils-2.8.7.orig/src/side.c diffutils-2.8.7/src/side.c
|
---|
| 386 | --- diffutils-2.8.7.orig/src/side.c 2004-04-12 00:44:35.000000000 -0700
|
---|
| 387 | +++ diffutils-2.8.7/src/side.c 2009-01-08 13:26:42.000000000 -0800
|
---|
| 388 | @@ -73,11 +73,72 @@
|
---|
| 389 | register size_t out_position = 0;
|
---|
| 390 | register char const *text_pointer = line[0];
|
---|
| 391 | register char const *text_limit = line[1];
|
---|
| 392 | +#if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H
|
---|
| 393 | + unsigned char mbc[MB_LEN_MAX];
|
---|
| 394 | + wchar_t wc;
|
---|
| 395 | + mbstate_t state, state_bak;
|
---|
| 396 | + size_t mbc_pos, mblength;
|
---|
| 397 | + int mbc_loading_flag = 0;
|
---|
| 398 | + int wc_width;
|
---|
| 399 | +
|
---|
| 400 | + memset (&state, '\0', sizeof (mbstate_t));
|
---|
| 401 | +#endif
|
---|
| 402 |
|
---|
| 403 | while (text_pointer < text_limit)
|
---|
| 404 | {
|
---|
| 405 | register unsigned char c = *text_pointer++;
|
---|
| 406 |
|
---|
| 407 | +#if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H
|
---|
| 408 | + if (MB_CUR_MAX > 1 && mbc_loading_flag)
|
---|
| 409 | + {
|
---|
| 410 | + mbc_loading_flag = 0;
|
---|
| 411 | + state_bak = state;
|
---|
| 412 | + mbc[mbc_pos++] = c;
|
---|
| 413 | +
|
---|
| 414 | +process_mbc:
|
---|
| 415 | + mblength = mbrtowc (&wc, mbc, mbc_pos, &state);
|
---|
| 416 | +
|
---|
| 417 | + switch (mblength)
|
---|
| 418 | + {
|
---|
| 419 | + case (size_t)-2: /* Incomplete multibyte character. */
|
---|
| 420 | + mbc_loading_flag = 1;
|
---|
| 421 | + state = state_bak;
|
---|
| 422 | + break;
|
---|
| 423 | +
|
---|
| 424 | + case (size_t)-1: /* Invalid as a multibyte character. */
|
---|
| 425 | + if (in_position++ < out_bound)
|
---|
| 426 | + {
|
---|
| 427 | + out_position = in_position;
|
---|
| 428 | + putc (mbc[0], out);
|
---|
| 429 | + }
|
---|
| 430 | + memmove (mbc, mbc + 1, --mbc_pos);
|
---|
| 431 | + if (mbc_pos > 0)
|
---|
| 432 | + {
|
---|
| 433 | + mbc[mbc_pos] = '\0';
|
---|
| 434 | + goto process_mbc;
|
---|
| 435 | + }
|
---|
| 436 | + break;
|
---|
| 437 | +
|
---|
| 438 | + default:
|
---|
| 439 | + wc_width = wcwidth (wc);
|
---|
| 440 | + if (wc_width < 1) /* Unprintable multibyte character. */
|
---|
| 441 | + {
|
---|
| 442 | + if (in_position <= out_bound)
|
---|
| 443 | + fprintf (out, "%lc", (wint_t)wc);
|
---|
| 444 | + }
|
---|
| 445 | + else /* Printable multibyte character. */
|
---|
| 446 | + {
|
---|
| 447 | + in_position += wc_width;
|
---|
| 448 | + if (in_position <= out_bound)
|
---|
| 449 | + {
|
---|
| 450 | + out_position = in_position;
|
---|
| 451 | + fprintf (out, "%lc", (wint_t)wc);
|
---|
| 452 | + }
|
---|
| 453 | + }
|
---|
| 454 | + }
|
---|
| 455 | + continue;
|
---|
| 456 | + }
|
---|
| 457 | +#endif
|
---|
| 458 | switch (c)
|
---|
| 459 | {
|
---|
| 460 | case '\t':
|
---|
| 461 | @@ -135,8 +196,39 @@
|
---|
| 462 | break;
|
---|
| 463 |
|
---|
| 464 | default:
|
---|
| 465 | - if (! isprint (c))
|
---|
| 466 | - goto control_char;
|
---|
| 467 | +#if defined HAVE_WCHAR_H && defined HAVE_WCTYPE_H
|
---|
| 468 | + if (MB_CUR_MAX > 1)
|
---|
| 469 | + {
|
---|
| 470 | + memset (mbc, '\0', MB_LEN_MAX);
|
---|
| 471 | + mbc_pos = 0;
|
---|
| 472 | + mbc[mbc_pos++] = c;
|
---|
| 473 | + state_bak = state;
|
---|
| 474 | +
|
---|
| 475 | + mblength = mbrtowc (&wc, mbc, mbc_pos, &state);
|
---|
| 476 | +
|
---|
| 477 | + /* The value of mblength is always less than 2 here. */
|
---|
| 478 | + switch (mblength)
|
---|
| 479 | + {
|
---|
| 480 | + case (size_t)-2: /* Incomplete multibyte character. */
|
---|
| 481 | + state = state_bak;
|
---|
| 482 | + mbc_loading_flag = 1;
|
---|
| 483 | + continue;
|
---|
| 484 | +
|
---|
| 485 | + case (size_t)-1: /* Invalid as a multibyte character. */
|
---|
| 486 | + state = state_bak;
|
---|
| 487 | + break;
|
---|
| 488 | +
|
---|
| 489 | + default:
|
---|
| 490 | + if (! iswprint (wc))
|
---|
| 491 | + goto control_char;
|
---|
| 492 | + }
|
---|
| 493 | + }
|
---|
| 494 | + else
|
---|
| 495 | +#endif
|
---|
| 496 | + {
|
---|
| 497 | + if (! isprint (c))
|
---|
| 498 | + goto control_char;
|
---|
| 499 | + }
|
---|
| 500 | /* falls through */
|
---|
| 501 | case ' ':
|
---|
| 502 | if (in_position++ < out_bound)
|
---|
| 503 | diff -Naur diffutils-2.8.7.orig/src/util.c diffutils-2.8.7/src/util.c
|
---|
| 504 | --- diffutils-2.8.7.orig/src/util.c 2004-04-12 00:44:35.000000000 -0700
|
---|
| 505 | +++ diffutils-2.8.7/src/util.c 2009-01-08 13:26:42.000000000 -0800
|
---|
| 506 | @@ -319,7 +319,7 @@
|
---|
| 507 | Return nonzero if the lines differ. */
|
---|
| 508 |
|
---|
| 509 | bool
|
---|
| 510 | -lines_differ (char const *s1, char const *s2)
|
---|
| 511 | +lines_differ_singlebyte (char const *s1, char const *s2)
|
---|
| 512 | {
|
---|
| 513 | register char const *t1 = s1;
|
---|
| 514 | register char const *t2 = s2;
|
---|
| 515 | @@ -458,6 +458,293 @@
|
---|
| 516 | return start;
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | +#ifdef HANDLE_MULTIBYTE
|
---|
| 520 | +# define MBC2WC(T, END, MBLENGTH, WC, STATE, CONVFAIL) \
|
---|
| 521 | +do \
|
---|
| 522 | +{ \
|
---|
| 523 | + mbstate_t bak = STATE; \
|
---|
| 524 | + \
|
---|
| 525 | + CONVFAIL = 0; \
|
---|
| 526 | + MBLENGTH = mbrtowc (&WC, T, END - T, &STATE); \
|
---|
| 527 | + \
|
---|
| 528 | + switch (MBLENGTH) \
|
---|
| 529 | + { \
|
---|
| 530 | + case (size_t)-2: \
|
---|
| 531 | + case (size_t)-1: \
|
---|
| 532 | + STATE = bak; \
|
---|
| 533 | + ++CONVFAIL; \
|
---|
| 534 | + /* Fall through. */ \
|
---|
| 535 | + case 0: \
|
---|
| 536 | + MBLENGTH = 1; \
|
---|
| 537 | + } \
|
---|
| 538 | +} \
|
---|
| 539 | +while (0)
|
---|
| 540 | +
|
---|
| 541 | +bool
|
---|
| 542 | +lines_differ_multibyte (char const *s1, char const *s2)
|
---|
| 543 | +{
|
---|
| 544 | + unsigned char const *end1, *end2;
|
---|
| 545 | + unsigned char c1, c2;
|
---|
| 546 | + wchar_t wc1, wc2, wc1_bak, wc2_bak;
|
---|
| 547 | + size_t mblen1, mblen2;
|
---|
| 548 | + mbstate_t state1, state2, state1_bak, state2_bak;
|
---|
| 549 | + int convfail1, convfail2, convfail1_bak, convfail2_bak;
|
---|
| 550 | +
|
---|
| 551 | + unsigned char const *t1 = (unsigned char const *) s1;
|
---|
| 552 | + unsigned char const *t2 = (unsigned char const *) s2;
|
---|
| 553 | + unsigned char const *t1_bak, *t2_bak;
|
---|
| 554 | + size_t column = 0;
|
---|
| 555 | +
|
---|
| 556 | + if (ignore_white_space == IGNORE_NO_WHITE_SPACE && !ignore_case)
|
---|
| 557 | + {
|
---|
| 558 | + while (*t1 != '\n')
|
---|
| 559 | + if (*t1++ != * t2++)
|
---|
| 560 | + return 1;
|
---|
| 561 | + return 0;
|
---|
| 562 | + }
|
---|
| 563 | +
|
---|
| 564 | + memset (&state1, '\0', sizeof (mbstate_t));
|
---|
| 565 | + memset (&state2, '\0', sizeof (mbstate_t));
|
---|
| 566 | +
|
---|
| 567 | + end1 = s1 + strlen (s1);
|
---|
| 568 | + end2 = s2 + strlen (s2);
|
---|
| 569 | +
|
---|
| 570 | + while (1)
|
---|
| 571 | + {
|
---|
| 572 | + c1 = *t1;
|
---|
| 573 | + c2 = *t2;
|
---|
| 574 | + MBC2WC (t1, end1, mblen1, wc1, state1, convfail1);
|
---|
| 575 | + MBC2WC (t2, end2, mblen2, wc2, state2, convfail2);
|
---|
| 576 | +
|
---|
| 577 | + /* Test for exact char equality first, since it's a common case. */
|
---|
| 578 | + if (convfail1 ^ convfail2)
|
---|
| 579 | + break;
|
---|
| 580 | + else if (convfail1 && convfail2 && c1 != c2)
|
---|
| 581 | + break;
|
---|
| 582 | + else if (!convfail1 && !convfail2 && wc1 != wc2)
|
---|
| 583 | + {
|
---|
| 584 | + switch (ignore_white_space)
|
---|
| 585 | + {
|
---|
| 586 | + case IGNORE_ALL_SPACE:
|
---|
| 587 | + /* For -w, just skip past any white space. */
|
---|
| 588 | + while (1)
|
---|
| 589 | + {
|
---|
| 590 | + if (convfail1)
|
---|
| 591 | + break;
|
---|
| 592 | + else if (wc1 == L'\n' || !iswspace (wc1))
|
---|
| 593 | + break;
|
---|
| 594 | +
|
---|
| 595 | + t1 += mblen1;
|
---|
| 596 | + c1 = *t1;
|
---|
| 597 | + MBC2WC (t1, end1, mblen1, wc1, state1, convfail1);
|
---|
| 598 | + }
|
---|
| 599 | +
|
---|
| 600 | + while (1)
|
---|
| 601 | + {
|
---|
| 602 | + if (convfail2)
|
---|
| 603 | + break;
|
---|
| 604 | + else if (wc2 == L'\n' || !iswspace (wc2))
|
---|
| 605 | + break;
|
---|
| 606 | +
|
---|
| 607 | + t2 += mblen2;
|
---|
| 608 | + c2 = *t2;
|
---|
| 609 | + MBC2WC (t2, end2, mblen2, wc2, state2, convfail2);
|
---|
| 610 | + }
|
---|
| 611 | + t1 += mblen1;
|
---|
| 612 | + t2 += mblen2;
|
---|
| 613 | + break;
|
---|
| 614 | +
|
---|
| 615 | + case IGNORE_SPACE_CHANGE:
|
---|
| 616 | + /* For -b, advance past any sequence of white space in
|
---|
| 617 | + line 1 and consider it just one space, or nothing at
|
---|
| 618 | + all if it is at the end of the line. */
|
---|
| 619 | + if (wc1 != L'\n' && iswspace (wc1))
|
---|
| 620 | + {
|
---|
| 621 | + size_t mblen_bak;
|
---|
| 622 | + mbstate_t state_bak;
|
---|
| 623 | +
|
---|
| 624 | + do
|
---|
| 625 | + {
|
---|
| 626 | + t1 += mblen1;
|
---|
| 627 | + mblen_bak = mblen1;
|
---|
| 628 | + state_bak = state1;
|
---|
| 629 | + MBC2WC (t1, end1, mblen1, wc1, state1, convfail1);
|
---|
| 630 | + }
|
---|
| 631 | + while (!convfail1 && (wc1 != L'\n' && iswspace (wc1)));
|
---|
| 632 | +
|
---|
| 633 | + state1 = state_bak;
|
---|
| 634 | + mblen1 = mblen_bak;
|
---|
| 635 | + t1 -= mblen1;
|
---|
| 636 | + convfail1 = 0;
|
---|
| 637 | + wc1 = L' ';
|
---|
| 638 | + }
|
---|
| 639 | +
|
---|
| 640 | + /* Likewise for line 2. */
|
---|
| 641 | + if (wc2 != L'\n' && iswspace (wc2))
|
---|
| 642 | + {
|
---|
| 643 | + size_t mblen_bak;
|
---|
| 644 | + mbstate_t state_bak;
|
---|
| 645 | +
|
---|
| 646 | + do
|
---|
| 647 | + {
|
---|
| 648 | + t2 += mblen2;
|
---|
| 649 | + mblen_bak = mblen2;
|
---|
| 650 | + state_bak = state2;
|
---|
| 651 | + MBC2WC (t2, end2, mblen2, wc2, state2, convfail2);
|
---|
| 652 | + }
|
---|
| 653 | + while (!convfail2 && (wc2 != L'\n' && iswspace (wc2)));
|
---|
| 654 | +
|
---|
| 655 | + state2 = state_bak;
|
---|
| 656 | + mblen2 = mblen_bak;
|
---|
| 657 | + t2 -= mblen2;
|
---|
| 658 | + convfail2 = 0;
|
---|
| 659 | + wc2 = L' ';
|
---|
| 660 | + }
|
---|
| 661 | +
|
---|
| 662 | + if (wc1 != wc2)
|
---|
| 663 | + {
|
---|
| 664 | + if (wc2 == L' ' && wc1 != L'\n' &&
|
---|
| 665 | + t1 > (unsigned char const *)s1 &&
|
---|
| 666 | + !convfail1_bak && iswspace (wc1_bak))
|
---|
| 667 | + {
|
---|
| 668 | + t1 = t1_bak;
|
---|
| 669 | + wc1 = wc1_bak;
|
---|
| 670 | + state1 = state1_bak;
|
---|
| 671 | + convfail1 = convfail1_bak;
|
---|
| 672 | + continue;
|
---|
| 673 | + }
|
---|
| 674 | + if (wc1 == L' ' && wc2 != L'\n'
|
---|
| 675 | + && t2 > (unsigned char const *)s2
|
---|
| 676 | + && !convfail2_bak && iswspace (wc2_bak))
|
---|
| 677 | + {
|
---|
| 678 | + t2 = t2_bak;
|
---|
| 679 | + wc2 = wc2_bak;
|
---|
| 680 | + state2 = state2_bak;
|
---|
| 681 | + convfail2 = convfail2_bak;
|
---|
| 682 | + continue;
|
---|
| 683 | + }
|
---|
| 684 | + }
|
---|
| 685 | +
|
---|
| 686 | + t1_bak = t1; t2_bak = t2;
|
---|
| 687 | + wc1_bak = wc1; wc2_bak = wc2;
|
---|
| 688 | + state1_bak = state1; state2_bak = state2;
|
---|
| 689 | + convfail1_bak = convfail1; convfail2_bak = convfail2;
|
---|
| 690 | +
|
---|
| 691 | + if (wc1 == L'\n')
|
---|
| 692 | + wc1 = L' ';
|
---|
| 693 | + else
|
---|
| 694 | + t1 += mblen1;
|
---|
| 695 | +
|
---|
| 696 | + if (wc2 == L'\n')
|
---|
| 697 | + wc2 = L' ';
|
---|
| 698 | + else
|
---|
| 699 | + t2 += mblen2;
|
---|
| 700 | +
|
---|
| 701 | + break;
|
---|
| 702 | +
|
---|
| 703 | + case IGNORE_TAB_EXPANSION:
|
---|
| 704 | + if ((wc1 == L' ' && wc2 == L'\t')
|
---|
| 705 | + || (wc1 == L'\t' && wc2 == L' '))
|
---|
| 706 | + {
|
---|
| 707 | + size_t column2 = column;
|
---|
| 708 | +
|
---|
| 709 | + while (1)
|
---|
| 710 | + {
|
---|
| 711 | + if (convfail1)
|
---|
| 712 | + {
|
---|
| 713 | + ++t1;
|
---|
| 714 | + break;
|
---|
| 715 | + }
|
---|
| 716 | + else if (wc1 == L' ')
|
---|
| 717 | + column++;
|
---|
| 718 | + else if (wc1 == L'\t')
|
---|
| 719 | + column += TAB_WIDTH - column % TAB_WIDTH;
|
---|
| 720 | + else
|
---|
| 721 | + {
|
---|
| 722 | + t1 += mblen1;
|
---|
| 723 | + break;
|
---|
| 724 | + }
|
---|
| 725 | +
|
---|
| 726 | + t1 += mblen1;
|
---|
| 727 | + c1 = *t1;
|
---|
| 728 | + MBC2WC (t1, end1, mblen1, wc1, state1, convfail1);
|
---|
| 729 | + }
|
---|
| 730 | +
|
---|
| 731 | + while (1)
|
---|
| 732 | + {
|
---|
| 733 | + if (convfail2)
|
---|
| 734 | + {
|
---|
| 735 | + ++t2;
|
---|
| 736 | + break;
|
---|
| 737 | + }
|
---|
| 738 | + else if (wc2 == L' ')
|
---|
| 739 | + column2++;
|
---|
| 740 | + else if (wc2 == L'\t')
|
---|
| 741 | + column2 += TAB_WIDTH - column2 % TAB_WIDTH;
|
---|
| 742 | + else
|
---|
| 743 | + {
|
---|
| 744 | + t2 += mblen2;
|
---|
| 745 | + break;
|
---|
| 746 | + }
|
---|
| 747 | +
|
---|
| 748 | + t2 += mblen2;
|
---|
| 749 | + c2 = *t2;
|
---|
| 750 | + MBC2WC (t2, end2, mblen2, wc2, state2, convfail2);
|
---|
| 751 | + }
|
---|
| 752 | +
|
---|
| 753 | + if (column != column2)
|
---|
| 754 | + return 1;
|
---|
| 755 | + }
|
---|
| 756 | + else
|
---|
| 757 | + {
|
---|
| 758 | + t1 += mblen1;
|
---|
| 759 | + t2 += mblen2;
|
---|
| 760 | + }
|
---|
| 761 | + break;
|
---|
| 762 | +
|
---|
| 763 | + case IGNORE_NO_WHITE_SPACE:
|
---|
| 764 | + t1 += mblen1;
|
---|
| 765 | + t2 += mblen2;
|
---|
| 766 | + break;
|
---|
| 767 | + }
|
---|
| 768 | +
|
---|
| 769 | + /* Lowercase all letters if -i is specified. */
|
---|
| 770 | + if (ignore_case)
|
---|
| 771 | + {
|
---|
| 772 | + if (!convfail1)
|
---|
| 773 | + wc1 = towlower (wc1);
|
---|
| 774 | + if (!convfail2)
|
---|
| 775 | + wc2 = towlower (wc2);
|
---|
| 776 | + }
|
---|
| 777 | +
|
---|
| 778 | + if (convfail1 ^ convfail2)
|
---|
| 779 | + break;
|
---|
| 780 | + else if (convfail1 && convfail2 && c1 != c2)
|
---|
| 781 | + break;
|
---|
| 782 | + else if (!convfail1 && !convfail2 && wc1 != wc2)
|
---|
| 783 | + break;
|
---|
| 784 | + }
|
---|
| 785 | + else
|
---|
| 786 | + {
|
---|
| 787 | + t1_bak = t1; t2_bak = t2;
|
---|
| 788 | + wc1_bak = wc1; wc2_bak = wc2;
|
---|
| 789 | + state1_bak = state1; state2_bak = state2;
|
---|
| 790 | + convfail1_bak = convfail1; convfail2_bak = convfail2;
|
---|
| 791 | +
|
---|
| 792 | + t1 += mblen1; t2 += mblen2;
|
---|
| 793 | + }
|
---|
| 794 | +
|
---|
| 795 | + if (!convfail1 && wc1 == L'\n')
|
---|
| 796 | + return 0;
|
---|
| 797 | +
|
---|
| 798 | + column += convfail1 ? 1 :
|
---|
| 799 | + (wc1 == L'\t') ? TAB_WIDTH - column % TAB_WIDTH : wcwidth (wc1);
|
---|
| 800 | + }
|
---|
| 801 | +
|
---|
| 802 | + return 1;
|
---|
| 803 | +}
|
---|
| 804 | +#endif
|
---|
| 805 | +
|
---|
| 806 | struct change *
|
---|
| 807 | find_reverse_change (struct change *start)
|
---|
| 808 | {
|
---|
| 809 |
|
---|