/* tddd2off.c - convert TDDD (or TTDDD) file to OFF file
 *            - written by Glenn M. Lewis - 10/29/91
 */

static char rcs_id[] = "$Id: tddd2off.c,v 1.2 1991/11/08 00:30:31 glewis Exp glewis $";

#include <stdio.h>
#include "ttdddlib.h"

main(argc, argv)
int argc;
char *argv[];
{
	char filename[256], rootname[256], *c1, *c2;
	int i;
	WORLD *world;
	FILE *inp;
	int split = 0, geom_only = 0;

	filename[0] = '\0';
	strcpy(rootname, "model");	/* The default for reading stdin */
	for (i=1; i<argc; i++) {
		if (argv[i][0] == '-') {
			switch(argv[i][1]) {
				case 's':	split = 1; break;
				case 'g':	geom_only = 1; break;
				case 'h':
				default:
		fprintf(stderr, "Usage: %s [-geom_only] [-split] [infile] [outfile]\n",
				argv[0]);
				exit(-1);
			}
		} else if (filename[0]) {
			strcpy(rootname, argv[i]);
		} else {
			strcpy(filename, argv[i]);	/* Make root of filename the default */
			for (c1=rootname,c2=argv[i]; (*c1 = *c2++) && *c1!='.'; c1++) ;
			*c1 = '\0';
		}
	}

	if (!filename[0]) inp = stdin;
	else if (!(inp = fopen(filename, "r"))) {
		fprintf(stderr, "Can't open '%s' for input.\n", filename);
		exit(-1);
	}

	world = read_World(inp);
	write_OFF(world, rootname, split, geom_only);
	exit(0);
}

