# include "opihi.h"

static int Nint = 0;

/* return FALSE if we are called many times in a row 
   without a valid answer or any answer */

void handle_interrupt (int input) {
  
  char string[64];
  int Nask;

  signal (SIGINT, SIG_IGN);

  Nask = 0;
  Nint ++;
  if (Nint > 10) { 
    interrupt = TRUE;
    return;
  }
  if (Nint > 100) { 
    exit (3);
  }
  
  while (1) {
    fprintf (stderr, "operation halted, continue? (y/n) ");
    fscanf (stdin, "%s", string);
    
    if ((string[0] == 'y') || (string[0] == 'Y')) {
      interrupt = FALSE;
      signal (SIGINT, handle_interrupt);
      Nint = 0;
      return;
    }

    if ((string[0] == 'n') || (string[0] == 'N')) {
      interrupt = TRUE;
      signal (SIGINT, handle_interrupt);
      Nint = 0;
      return;
    }
    Nask ++;
    if (Nask > 10) {
      interrupt = TRUE;
      signal (SIGINT, handle_interrupt);
      Nint = 0;
      return;
    }
  }  

}
