#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define SF_NAME "/tmp/calc_data"
#define SF_SIZE 256

typedef struct {
  float num1;
  float num2;
  char operation;
  int ready_flags; // 1 - nums-ready, 2 - op-ready
} calc_data;

#define err(exit_code, msg, line)                                              \
  do {                                                                         \
    EXIT_CODE = exit_code;                                                     \
    char buf[256];                                                             \
    snprintf(buf, sizeof(buf), "%s:%d: error: %s", __FILE__, line, msg);       \
    perror(buf);                                                               \
  } while (0)

#define SPINNER "|/-\\"
#define spin(msg, delay_ms)                                                    \
  do {                                                                         \
    static int i = 0;                                                          \
    printf("\r%s %c ", msg, SPINNER[i % (sizeof(SPINNER) - 1)]);               \
    fflush(stdout);                                                            \
    usleep(delay_ms * 1000);                                                   \
    i++;                                                                       \
  } while (0)
