sort: adjust the leading blanks --debug warning
authorPádraig Brady <P@draigBrady.com>
Sat, 22 May 2010 13:19:50 +0000 (14:19 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 24 May 2010 11:12:24 +0000 (12:12 +0100)
* src/sort.c (key_warnings): Always warn about significant leading
blanks when character offsets are specified, unless they key is
possibly a line offset, i.e. of the form -k1.x,1.y.  Also suppress
this warning if the user could be sorting right aligned indexes.

src/sort.c
tests/misc/sort-debug-warn

index 8a9309a..e6cc2c2 100644 (file)
@@ -2261,8 +2261,14 @@ 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 maybe_space_aligned = !hard_LC_COLLATE && default_key_compare (key)
+                                 && !(key->schar || key->echar);
+      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 || maybe_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);
 
index 3a7b01a..1ba6c04 100755 (executable)
@@ -26,7 +26,6 @@ fi
 cat <<\EOF > exp
 sort: using simple byte comparison
 sort: key 1 has zero width and will be ignored
-sort: leading blanks are significant in key 1; consider also specifying `b'
 sort: using simple byte comparison
 sort: options `-bghMRrV' are ignored
 sort: using simple byte comparison
@@ -35,14 +34,12 @@ sort: option `-r' only applies to last-resort comparison
 sort: using simple byte comparison
 sort: option `-r' only applies to last-resort comparison
 sort: using simple byte comparison
-sort: leading blanks are significant in key 2; consider also specifying `b'
 sort: options `-bg' are ignored
 sort: using simple byte comparison
 sort: using simple byte comparison
 sort: option `-b' is ignored
 sort: using simple byte comparison
 sort: using simple byte comparison
-sort: leading blanks are significant in key 1; consider also specifying `b'
 sort: using simple byte comparison
 sort: leading blanks are significant in key 1; consider also specifying `b'
 sort: using simple byte comparison
@@ -84,7 +81,7 @@ sort: option `-b' is ignored
 sort: option `-r' only applies to last-resort comparison
 EOF
 
-sort --debug -rb -k2n +2 -1b /dev/null 2>out
+sort --debug -rb -k2n +2.2 -1b /dev/null 2>out
 
 compare exp out || fail=1