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.
This commit is contained in:
Jim Meyering committed 2004-04-26 15:31:13 +00:00
1 parent 431d661863
commit 41cc9a718a
1 file changed
+3 -26
+3 -26
View File
@@ -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)
{