Not all platforms supports sighandler_t, so I changed it to use the older
[oota-llvm.git] / lib / Support / SlowOperationInformer.cpp
index 40759f6d48730db18b8a736f5230a54dd85adae6..c245f3655c2a289246ba1a55f48634a408acbae2 100644 (file)
@@ -17,6 +17,7 @@
 #include <sstream>
 #include <signal.h>
 #include <unistd.h>
+#include <cassert>
 using namespace llvm;
 
 /// OperationCancelled - This flag is set by the SIGINT signal handler if the
@@ -40,7 +41,7 @@ static RETSIGTYPE SigAlarmHandler(int Sig) {
   ShouldShowStatus = true;
 }
 
-static sighandler_t OldSigIntHandler;
+static void (*OldSigIntHandler) (int);
 
 
 SlowOperationInformer::SlowOperationInformer(const std::string &Name)
@@ -58,8 +59,12 @@ SlowOperationInformer::SlowOperationInformer(const std::string &Name)
 
 SlowOperationInformer::~SlowOperationInformer() {
   NestedSOI = false;
-  if (LastPrintAmount)
-    std::cout << "\n";
+  if (LastPrintAmount) {
+    // If we have printed something, make _sure_ we print the 100% amount, and
+    // also print a newline.
+    std::cout << std::string(LastPrintAmount, '\b') << "Progress "
+              << OperationName << ": 100%  \n";
+  }
 
   alarm(0);
   signal(SIGALRM, SIG_DFL);
@@ -86,8 +91,11 @@ void SlowOperationInformer::progress(unsigned Amount) {
   std::string ToPrint = std::string(LastPrintAmount, '\b');
 
   std::ostringstream OS;
-  OS << "Progress " << OperationName << ": " << Amount/10 << "." << Amount % 10
-     << "%";
+  OS << "Progress " << OperationName << ": " << Amount/10;
+  if (unsigned Rem = Amount % 10)
+    OS << "." << Rem << "%";
+  else
+    OS << "%  ";
 
   LastPrintAmount = OS.str().size();
   std::cout << ToPrint+OS.str() << std::flush;