From a3721c43f96beb255c533118bfaba1ddf8d9a6be Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 7 Dec 2016 12:20:04 -0800
Subject: [PATCH] grep: simplify finalize_input

* src/grep.c (finalize_input): Simplify without changing behavior.
It's still a bit of a rat's-nest, but it's a cozier rat's-nest.
---
 src/grep.c | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index 4538f225..1e910cb7 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1758,29 +1758,14 @@ drain_input (int fd, struct stat const *st)
 static void
 finalize_input (int fd, struct stat const *st, bool ineof)
 {
-  if (fd != STDIN_FILENO)
-    return;
-
-  if (outleft)
-    {
-      if (ineof)
-        return;
-      if (seek_failed)
-        {
-          if (drain_input (fd, st))
-            return;
-        }
-      else if (0 <= lseek (fd, 0, SEEK_END))
-        return;
-    }
-  else
-    {
-      if (seek_failed || bufoffset == after_last_match
-          || 0 <= lseek (fd, after_last_match, SEEK_SET))
-        return;
-    }
-
-  suppressible_error (errno);
+  if (fd == STDIN_FILENO
+      && (outleft
+          ? (!ineof && (seek_failed
+                        ? ! drain_input (fd, st)
+                        : lseek (fd, 0, SEEK_END) < 0))
+          : (bufoffset != after_last_match && !seek_failed
+             && lseek (fd, after_last_match, SEEK_SET) < 0)))
+    suppressible_error (errno);
 }
 
 static bool
-- 
2.11.0

