fix the SUSE fix for cut output-delimiter

This commit is contained in:
Ondřej Vašík 2011-09-09 14:53:00 +02:00
commit fbca36cbd7
2 changed files with 41 additions and 15 deletions

View File

@ -75,7 +75,7 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ while (0) + while (0)
+ +
+/* Get wide character on BUFPOS. BUFPOS is not included after that. +/* Get wide character on BUFPOS. BUFPOS is not included after that.
+ If byte sequence is not valid as a character, CONVFAIL is 1. Otherwise 0. */ + If byte sequence is not valid as a character, CONVFAIL is 1. Otherwise 0. */
+#define GET_NEXT_WC_FROM_BUFFER(WC, BUFPOS, BUFLEN, MBLENGTH, STATE, CONVFAIL) \ +#define GET_NEXT_WC_FROM_BUFFER(WC, BUFPOS, BUFLEN, MBLENGTH, STATE, CONVFAIL) \
+ do \ + do \
+ { \ + { \
@ -226,7 +226,7 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
} }
max_range_endpoint = 0; max_range_endpoint = 0;
@@ -582,6 +664,63 @@ cut_bytes (FILE *stream) @@ -582,6 +664,77 @@ cut_bytes (FILE *stream)
} }
} }
@ -234,11 +234,11 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+/* This function is in use for the following case. +/* This function is in use for the following case.
+ +
+ 1. Read from the stream STREAM, printing to standard output any selected + 1. Read from the stream STREAM, printing to standard output any selected
+ characters. + characters.
+ +
+ 2. Read from stream STREAM, printing to standard output any selected bytes, + 2. Read from stream STREAM, printing to standard output any selected bytes,
+ without splitting multibyte characters. */ + without splitting multibyte characters. */
+ +
+static void +static void
+cut_characters_or_cut_bytes_no_split (FILE *stream) +cut_characters_or_cut_bytes_no_split (FILE *stream)
+{ +{
@ -251,6 +251,9 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ as same character as WC. */ + as same character as WC. */
+ mbstate_t state; /* State of the stream. */ + mbstate_t state; /* State of the stream. */
+ int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */ + int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */
+ /* Whether to begin printing delimiters between ranges for the current line.
+ Set after we've begun printing data corresponding to the first range. */
+ bool print_delimiter = false;
+ +
+ idx = 0; + idx = 0;
+ buflen = 0; + buflen = 0;
@ -273,12 +276,23 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ { + {
+ putchar ('\n'); + putchar ('\n');
+ idx = 0; + idx = 0;
+ print_delimiter = false;
+ } + }
+ else + else
+ { + {
+ bool range_start;
+ bool *rs = output_delimiter_specified ? &range_start : NULL;
+ idx += (operating_mode == byte_mode) ? mblength : 1; + idx += (operating_mode == byte_mode) ? mblength : 1;
+ if (print_kth (idx, NULL)) + if (print_kth (idx, rs))
+ fwrite (bufpos, mblength, sizeof(char), stdout); + {
+ if (rs && *rs && print_delimiter)
+ {
+ fwrite (output_delimiter_string, sizeof (char),
+ output_delimiter_length, stdout);
+ }
+ print_delimiter = true;
+ fwrite (bufpos, mblength, sizeof(char), stdout);
+ }
+ } + }
+ +
+ buflen -= mblength; + buflen -= mblength;
@ -286,11 +300,11 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ } + }
+} +}
+#endif +#endif
+ +
/* Read from stream STREAM, printing to standard output any selected fields. */ /* Read from stream STREAM, printing to standard output any selected fields. */
static void static void
@@ -704,13 +843,192 @@ cut_fields (FILE *stream) @@ -704,13 +843,195 @@ cut_fields (FILE *stream)
} }
} }
@ -310,7 +324,7 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ size_t mblength; /* The byte size of a multibyte character which shows + size_t mblength; /* The byte size of a multibyte character which shows
+ as same character as WC. */ + as same character as WC. */
+ mbstate_t state; /* State of the stream. */ + mbstate_t state; /* State of the stream. */
+ int convfail; /* 1, when conversion is failed. Otherwise 0. */ + int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */
+ +
+ found_any_selected_field = 0; + found_any_selected_field = 0;
+ field_idx = 1; + field_idx = 1;
@ -321,7 +335,10 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ c = getc (stream); + c = getc (stream);
+ empty_input = (c == EOF); + empty_input = (c == EOF);
+ if (c != EOF) + if (c != EOF)
+ {
+ ungetc (c, stream); + ungetc (c, stream);
+ wc = 0;
+ }
+ else + else
+ wc = WEOF; + wc = WEOF;
+ +
@ -607,7 +624,7 @@ diff -urNp coreutils-8.13-orig/src/cut.c coreutils-8.13/src/cut.c
+ if (MB_CUR_MAX <= 1 || force_singlebyte_mode) + if (MB_CUR_MAX <= 1 || force_singlebyte_mode)
+#endif +#endif
+ { + {
+ static char dummy[2]; + static char dummy[2];
+ dummy[0] = delim; + dummy[0] = delim;
+ dummy[1] = '\0'; + dummy[1] = '\0';
+ output_delimiter_string = dummy; + output_delimiter_string = dummy;
@ -1551,7 +1568,7 @@ diff -urNp coreutils-8.13-orig/src/join.c coreutils-8.13/src/join.c
- return xmemcoll (beg1, len1, beg2, len2); - return xmemcoll (beg1, len1, beg2, len2);
- diff = memcmp (beg1, beg2, MIN (len1, len2)); - diff = memcmp (beg1, beg2, MIN (len1, len2));
+ copy[0] = (unsigned char *) beg[0]; + copy[0] = (unsigned char *) beg[0];
+ copy[1] = (unsigned char *) beg[1]; + copy[1] = (unsigned char *) beg[1];
} }
+ if (hard_LC_COLLATE) + if (hard_LC_COLLATE)
@ -1632,7 +1649,7 @@ diff -urNp coreutils-8.13-orig/src/join.c coreutils-8.13/src/join.c
case 't': case 't':
{ {
- unsigned char newtab = optarg[0]; - unsigned char newtab = optarg[0];
+ char *newtab; + char *newtab = NULL;
+ size_t newtablen; + size_t newtablen;
+ newtab = xstrdup (optarg); + newtab = xstrdup (optarg);
+#if HAVE_MBRTOWC +#if HAVE_MBRTOWC
@ -1654,7 +1671,8 @@ diff -urNp coreutils-8.13-orig/src/join.c coreutils-8.13/src/join.c
+ newtablen = 1; + newtablen = 1;
if (! newtab) if (! newtab)
+ { + {
newtab = '\n'; /* '' => process the whole line. */ - newtab = '\n'; /* '' => process the whole line. */
+ newtab = "\n"; /* '' => process the whole line. */
+ } + }
else if (optarg[1]) else if (optarg[1])
{ {
@ -3085,7 +3103,7 @@ diff -urNp coreutils-8.13-orig/src/sort.c coreutils-8.13/src/sort.c
else if (key->random) else if (key->random)
diff = compare_random (ta, tlena, tb, tlenb); diff = compare_random (ta, tlena, tb, tlenb);
else if (key->version) else if (key->version)
@@ -2632,6 +3066,179 @@ keycompare (struct line const *a, struct @@ -2632,6 +3066,180 @@ keycompare (struct line const *a, struct
return key->reverse ? -diff : diff; return key->reverse ? -diff : diff;
} }
@ -3167,7 +3185,8 @@ diff -urNp coreutils-8.13-orig/src/sort.c coreutils-8.13/src/sort.c
+ if (MBLENGTH == (size_t)-2 || MBLENGTH == (size_t)-1) \ + if (MBLENGTH == (size_t)-2 || MBLENGTH == (size_t)-1) \
+ STATE = state_bak; \ + STATE = state_bak; \
+ if (!ignore) \ + if (!ignore) \
+ COPY[NEW_LEN++] = TEXT[i++]; \ + COPY[NEW_LEN++] = TEXT[i]; \
+ i++; \
+ continue; \ + continue; \
+ } \ + } \
+ \ + \

View File

@ -324,8 +324,15 @@ fi
- new upstream release 8.13 - new upstream release 8.13
- temporarily disable recently added multibyte checks in - temporarily disable recently added multibyte checks in
misc/cut test misc/cut test
- fix the SUSE fix for cut output-delimiter
- drop coreutils-libs subpackage, no longer needed - drop coreutils-libs subpackage, no longer needed
* Mon Sep 05 2011 Ondrej Vasik <ovasik@redhat.com> - 8.12-7
- incorporate some i18n patch fixes from OpenSUSE:
- fix cut output-delimiter option
- prevent infinite loop in sort when ignoring chars
- prevent using unitialized variable in cut
* Tue Aug 23 2011 Ondrej Vasik <ovasik@redhat.com> - 8.12-6 * Tue Aug 23 2011 Ondrej Vasik <ovasik@redhat.com> - 8.12-6
- su: fix shell suspend in tcsh (#597928) - su: fix shell suspend in tcsh (#597928)