#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include "shared.h"

int main(void) {
  time_t t = time(NULL);
  char s[256];
  strftime(s, 256, "%s", localtime(&t));

  __pid_t e_pid = fork();
  if (e_pid == -1) {
    err("Can't fork process for editor", __LINE__ - 1);
    return 1;
  }

  if (!e_pid && execl("build/editor", "build/editor", (char *)NULL)) {
    err("Can't launch build/editor", __LINE__ - 1);
    return 2;
  }

  waitpid(e_pid, 0, 0);

  __pid_t a_pid = fork();
  if (a_pid == -1) {
    err("Can't fork process for analizer", __LINE__ - 1);
    return 3;
  }

  if (!a_pid && execl("build/analizer", "build/analizer", s, (char *)NULL)) {
    err("Can't launch build/analizer", __LINE__ - 1);
    return 4;
  }

  waitpid(a_pid, 0, 0);

  return 0;
}
