#include <stdio.h>
#include <math.h>
#include "progress.h"

void progress_start(struct progress_state *state, const char *msg, int N)
{
  state->msg = msg;
  state->N = N;
  state->old_p = -1;
}

void progress(struct progress_state *state, int i)
{
  int new_p = (int)floor((float)i/state->N*100);

  if (new_p == state->old_p)
    return;

  printf("%s: %d %%  \r", state->msg, new_p);
  fflush(stdout);

  state->old_p = new_p; 
}

void progress_finish(struct progress_state *state)
{
  printf("\n");
}
