summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-11-19 02:49:15 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-11-19 02:50:59 -0800
commita99b612d1a2ce392a7ca6c59724013a965e81e04 (patch)
treef54bea2b3fde9af935797c86d78642d1f29bddbb
parent16c0d20ba4923c496ef4e499319b6d18ca81711a (diff)
downloadgrep-a99b612d1a2ce392a7ca6c59724013a965e81e04.tar.gz
grep: -T no longer outputs BS
* NEWS: Document this (Bug#24451). * src/grep.c (print_line_head): Do not attempt to backspace output. * tests/initial-tab: New test. * tests/Makefile.am (TESTS): Add it.
-rw-r--r--NEWS4
-rw-r--r--src/grep.c25
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/initial-tab32
4 files changed, 42 insertions, 20 deletions
diff --git a/NEWS b/NEWS
index 29a0e8d2..0037edd7 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,10 @@ GNU grep NEWS -*- outline -*-
grep -m0 -L PAT FILE now outputs "FILE". [bug introduced in grep-2.5]
+ To output ':' and tab-align the following character C, grep -T no
+ longer outputs tab-backspace-':'-C, an approach that has problems if
+ run inside an Emacs shell window. [bug introduced in grep-2.5.2]
+
grep's use of getprogname no longer causes a build failure on HP-UX.
** Improvements
diff --git a/src/grep.c b/src/grep.c
index a794af48..86cf18b9 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1134,13 +1134,11 @@ print_line_head (char *beg, size_t len, char const *lim, char sep)
}
}
- bool pending_sep = false;
-
if (out_file)
{
print_filename ();
if (filename_mask)
- pending_sep = true;
+ print_sep (sep);
else
putchar_errno (0);
}
@@ -1153,34 +1151,21 @@ print_line_head (char *beg, size_t len, char const *lim, char sep)
totalnl = add_count (totalnl, 1);
lastnl = lim;
}
- if (pending_sep)
- print_sep (sep);
print_offset (totalnl, 4, line_num_color);
- pending_sep = true;
+ print_sep (sep);
}
if (out_byte)
{
uintmax_t pos = add_count (totalcc, beg - bufbeg);
pos = dossified_pos (pos);
- if (pending_sep)
- print_sep (sep);
print_offset (pos, 6, byte_num_color);
- pending_sep = true;
- }
-
- if (pending_sep)
- {
- /* This assumes sep is one column wide.
- Try doing this any other way with Unicode
- (and its combining and wide characters)
- filenames and you're wasting your efforts. */
- if (align_tabs)
- fputs_errno ("\t\b");
-
print_sep (sep);
}
+ if (align_tabs && (out_file | out_line | out_byte) && len != 0)
+ putchar_errno ('\t');
+
return true;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b6f0df32..56e860f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -108,6 +108,7 @@ TESTS = \
in-eq-out-infloop \
include-exclude \
inconsistent-range \
+ initial-tab \
invalid-multibyte-infloop \
khadafy \
kwset-abuse \
diff --git a/tests/initial-tab b/tests/initial-tab
new file mode 100755
index 00000000..af5efb37
--- /dev/null
+++ b/tests/initial-tab
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Exercise -T.
+
+# Copyright 2016 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+printf 'x\n\n' > in || framework_failure_
+
+grep -T '^' in > out || fail=1
+compare in out || fail=1
+
+printf 'in:\tx\nin:\n' > exp || framework_failure_
+grep -T '^' in /dev/null > out || fail=1
+compare exp out || fail=1
+
+Exit $fail