GNU bug report logs -
#6176
[PATCH 1/2] sort: add a --debug option to highlight key extents
Previous Next
Reported by: Pádraig Brady <P <at> draigBrady.com>
Date: Tue, 11 May 2010 22:59:02 UTC
Severity: normal
Tags: patch
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
Full log
Message #50 received at 6176 <at> debbugs.gnu.org (full text, mbox):
I was reviewing some tricky sorting I've done previously to see did
the new --debug option warn me about the issues I encountered.
One thing I missed was that if one specifies character offsets,
then we should warn, even if the type implicitly skips spaces when sorting.
For example, one has to specify 'b' to both start and end positions
in the second key in the example below (which sorts apache access.log by date).
printf "127.0.0.1 - - [01/Jan/2008:02:08:26 +0000] ...\n" |
sort --debug -b -k4.9,4.12 -k4.5b,4.7Mb -k4.2,4.3 -k4.14,4
One caveat with always warning about a missing 'b' when character
offsets are specified, is that this form is now warned about: -k1.x,1.y
That is commonly used to specify offsets into a fixed spaced file.
I.E. it can be seen as a line offset, rather than a field offset.
So I've excluded that form from any warnings.
Also previously we would warn about a missing 'b' when
it could have been legitimately unused to support sorting
right aligned indexes, aligned with spaces.
I'm wary about being "too clever" with these warnings,
but I think it worth suppressing this warning in the
above 2 fairly common cases, as the user can still see the
blanks being included when the key annotations are displayed.
cheers,
Pádraig.
diff --git a/src/sort.c b/src/sort.c
index 8a9309a..bebbd11 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2261,8 +2261,13 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
error (0, 0, _("key %lu has zero width and will be ignored"), keynum);
/* Warn about significant leading blanks. */
- if (!gkey_only && tab == TAB_DEFAULT && !key->skipsblanks
- && !key_numeric (key) && !key->month)
+ bool implicit_skip = key_numeric (key) || key->month;
+ bool support_space_aligned = !hard_LC_COLLATE && default_key_compare (key) && !key->schar;
+ bool line_offset = key->eword == 0 && key->echar != 0; /* -k1.x,1.y */
+ if (!gkey_only && tab == TAB_DEFAULT && !line_offset
+ && ((!key->skipsblanks && !(implicit_skip || support_space_aligned))
+ || (!key->skipsblanks && key->schar)
+ || (!key->skipeblanks && key->echar)))
error (0, 0, _("leading blanks are significant in key %lu; "
"consider also specifying `b'"), keynum);
This bug report was last modified 15 years and 5 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.