From 6261ef058b2a47880217606547e48069fe2c146c Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 25 Oct 2010 12:22:25 +0100
Subject: [PATCH] ENH: setSet : proper exit upon eof

---
 .../mesh/manipulation/setSet/setSet.C         | 25 ++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C
index 7b204e984f0..117d5283a58 100644
--- a/applications/utilities/mesh/manipulation/setSet/setSet.C
+++ b/applications/utilities/mesh/manipulation/setSet/setSet.C
@@ -934,18 +934,31 @@ int main(int argc, char *argv[])
                 {
                     char* linePtr = readline("readline>");
 
-                    rawLine = string(linePtr);
+                    if (linePtr)
+                    {
+                        rawLine = string(linePtr);
+
+                        if (*linePtr)
+                        {
+                            add_history(linePtr);
+                            write_history(historyFile);
+                        }
 
-                    if (*linePtr)
+                        free(linePtr);   // readline uses malloc, not new.
+                    }
+                    else
                     {
-                        add_history(linePtr);
-                        write_history(historyFile);
+                        break;
                     }
-
-                    free(linePtr);   // readline uses malloc, not new.
                 }
 #               else
                 {
+                    if (!std::cin.good())
+                    {
+                        Info<< "End of cin" << endl;
+                        // No error.
+                        break;
+                    }
                     Info<< "Command>" << flush;
                     std::getline(std::cin, rawLine);
                 }
-- 
GitLab