From: Jim Meyering Date: Mon, 26 Apr 2004 15:31:13 +0000 (+0000) Subject: Fix POSIX-conformance bug: "sort -k 3,3.5b" is supposed to skip X-Git-Tag: v5.3.0~1678 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=41cc9a718acc174c9ed7aaaf59e92c88bd471fda;p=thirdparty%2Fcoreutils.git Fix POSIX-conformance bug: "sort -k 3,3.5b" is supposed to skip leading blanks when computing the location of the field end; it is not supposed to skip trailing blanks. Solaris 8 "sort" does conform to POSIX. Also fix the documentation to clarify this and related issues. (limfield): Use skipeblanks, not skipsblanks, to decode whether to skip leading blanks. (trailing_blanks): Remove. (fillbuf, getmonth, keycompare): Don't trim trailing blanks. --- diff --git a/src/sort.c b/src/sort.c index 942de4fff9..a5a557fb74 100644 --- a/src/sort.c +++ b/src/sort.c @@ -148,8 +148,8 @@ struct keyfield size_t echar; /* Additional characters in field. */ bool const *ignore; /* Boolean array of characters to ignore. */ char const *translate; /* Translation applied to characters. */ - bool skipsblanks; /* Skip leading blanks at start. */ - bool skipeblanks; /* Skip trailing blanks at finish. */ + bool skipsblanks; /* Skip leading blanks when finding start. */ + bool skipeblanks; /* Skip leading blanks when finding end. */ bool numeric; /* Flag for numeric comparison. Handle strings of digits with optional decimal point, but no exponential notation. */ @@ -912,7 +912,7 @@ limfield (const struct line *line, const struct keyfield *key) /* If we're skipping leading blanks, don't start counting characters until after skipping past any leading blanks. */ - if (key->skipsblanks) + if (key->skipeblanks) while (ptr < lim && blanks[UCHAR (*ptr)]) ++ptr; @@ -926,17 +926,6 @@ limfield (const struct line *line, const struct keyfield *key) return ptr; } -/* Return the number of trailing blanks in FIELD, with LEN bytes. */ - -static size_t -trailing_blanks (char const *field, size_t len) -{ - size_t i; - for (i = len; 0 < i && blanks[UCHAR (field[i - 1])]; i--) - continue; - return len - i; -} - /* Fill BUF reading from FP, moving buf->left bytes from the end of buf->buf to the beginning first. If EOF is reached and the file wasn't terminated by a newline, supply one. Set up BUF's line @@ -1023,11 +1012,6 @@ fillbuf (struct buffer *buf, register FILE *fp, char const *file) line_start++; line->keybeg = line_start; } - if (key->skipeblanks) - { - size_t keylen = line->keylim - line->keybeg; - line->keylim -= trailing_blanks (line->keybeg, keylen); - } } line_start = ptr; @@ -1312,7 +1296,6 @@ getmonth (const char *s, size_t len) month = alloca (len + 1); for (i = 0; i < len; ++i) month[i] = fold_toupper[UCHAR (s[i])]; - len -= trailing_blanks (month, len); month[len] = '\0'; do @@ -1358,12 +1341,6 @@ keycompare (const struct line *a, const struct line *b) size_t lena = lima <= texta ? 0 : lima - texta; size_t lenb = limb <= textb ? 0 : limb - textb; - if (key->skipeblanks) - { - lena -= trailing_blanks (texta, lena); - lenb -= trailing_blanks (textb, lenb); - } - /* Actually compare the fields. */ if (key->numeric | key->general_numeric) {