# include "basic.h"

static FILE *outfile;

int output (int argc, char **argv) {
  
  if (argc != 2) {
    fprintf (stderr, "USAGE: output <filename>\n");
    return (FALSE);
  }

  fflush (outfile);
  if (outfile != stdout) fclose (outfile);
  
  /* we only use stdout, but let stderr be a synonym */
  outfile = stdout;
  if (strcmp (argv[1], "stdout") && strcmp (argv[1], "stderr")) {
    outfile = fopen (argv[1], "a");
  }

  if (outfile == NULL) {
    fprintf (stderr, "cannot open file %s\n", argv[1]);
    outfile = stdout;
  }
  return (TRUE);
}

FILE *GetOutfile () {
  return (outfile);
}

void InitOutfile () {
  outfile = stdout;
}
