/*
 * offutil.c
 * author:  Celeste Fowler, Mark Phillips
 * date:  June 12, 1992
 */

#include <stdio.h>
#include <string.h>
#include "geomclass.h"
#include "geom.h"
#include "transform.h"
#include "plutil.h"

main(int argc, char *argv[])
{
  if (strcmp(argv[0], "anytooff") == 0)
    return anytooff_main(argc, argv);
  if (strcmp(argv[0], "offconsol") == 0)
    return offconsol_main(argc, argv);
  if (strcmp(argv[0], "offcombine") == 0)
    return offcombine_main(argc, argv);
  return -1;
}

anytooff_main(int argc, char *argv[]) {
  GeomFSave(AnyToPL(GeomFLoad(stdin, NULL), TM_IDENTITY), stdout, NULL);
}

offconsol_main(int argc, char *argv[]) {
  float prec;
  if (argc > 1) sscanf(argv[1], "%f", &prec);
  GeomFSave(PLConsol(GeomFLoad(stdin, NULL), prec), stdout, NULL);
}

offcombine_main(int argc, char *argv[])
{
  Geom *g1, *g2;

  if (argc != 3) {
    fprintf(stderr, "usage: mergeoff file1 file2\n");
    exit(-1);
  }

  g1 = GeomLoad(argv[1]);
  if (g1 == NULL) exit(-1);
  g2 = GeomLoad(argv[2]);
  if (g2 == NULL) exit(-1);

  GeomFSave(PLCombine(g1, g2), stdout, NULL);
}

