/*
 * $Id: main.c,v 1.1 1999/01/14 21:51:10 labovit Exp $
 */

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <regex.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>


/* we should really read configuration file ! */
#define IRR_SUBMIT "/irr/bin/irr_submit"
#define IRR_CONF   "/irr/etc/irrd.conf"

int main(int argc, char *argv[]) {
  char *name = argv[0], *config_fname = "/etc/irrd.conf";
  char line[1024], *tmpfilename;
  int tmp_file, n;
  FILE *fd;
  char tmp[100];

  /* we should really set a timeout alarm */ 

  sprintf (tmp, "/tmp/irrd_submit.XXXXX");
  tmpfilename = mktemp(tmp);
 
  if ((fd = fopen (tmpfilename, "w+")) == NULL) {
    printf ("DCould not open temporary file: %s\n", tmpfilename);
    exit (0);
  }

  while (fgets (line, 1024, stdin) != NULL) {
    fwrite (line, 1, n, fd); 
    if (!strncasecmp (line, "!ue", 3)) 
      break;
  }
  fclose (fd);

  /* we need to delete temporary file -- does irr_submit do this? */

  if (execlp (IRR_SUBMIT, IRR_SUBMIT, "-x", "-f", IRR_CONF, tmp, 0) < 0) { 
    printf ("Submit error: %s\n", strerror (errno));
    exit (0);
  }
}


  
