chiark / gitweb /
introduce progress_eol and make stderr line buffered
[matchsticks-search.git] / main.c
diff --git a/main.c b/main.c
index 0cc8d9b8317012885e665c15767d51b9874a8976..a81687172b545275b1c5b10d1c27c8c14bc78873 100644 (file)
--- a/main.c
+++ b/main.c
@@ -91,6 +91,11 @@ static unsigned printcounter;
 
 static int ncpus = 1;
 
+static void progress_eol(void) {
+  fprintf(stderr,"        \r");
+  fflush(stderr);
+}
+
 static AdjWord *xalloc_adjmatrix(void) {
   return xmalloc(sizeof(*adjmatrix)*n);
 }
@@ -99,6 +104,7 @@ static void prep(void) {
   adjall = ~((~(AdjWord)0) << m);
   adjmatrix = xalloc_adjmatrix();
   glp_term_out(GLP_OFF);
+  setlinebuf(stderr);
 }
 
 static AdjWord one_adj_bit(int bitnum) {
@@ -332,7 +338,7 @@ static void optimise(bool doprint) {
  out:
   if (prob)
     glp_delete_prob(prob);
-  if (doprint) { PRINTF("        \r"); fflush(stdout); }
+  if (doprint) progress_eol();
 }
 
 static void iterate_recurse(int i, AdjWord min) {