home *** CD-ROM | disk | FTP | other *** search
- /* readwrite.c - written by Glenn M. Lewis - 10/91
- * convert external Turbo Silver objects into "internal" Imagine objects
- * with optional "merge" feature
- */
-
- static char rcs_id[] = "$Id: readwrite.c,v 1.7 1993/01/31 17:22:21 glewis Exp $";
-
- #include <stdio.h>
- #include <ctype.h>
- #include "t3dlib.h"
- #ifdef __STDC__
- #include <stdlib.h>
- #include <strings.h>
- #include "readwrite_protos.h"
- #endif
-
- WORLD *world;
- extern int verbose_flag;
- char infile[128], outfile[128];
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int i, merge_flag, tddd_flag, frame;
- FILE *inp, *out, *fopen();
-
- merge_flag = 0;
- verbose_flag = 0;
- tddd_flag = 0;
- infile[0] = outfile[0] = '\0';
- inp = stdin;
- out = stdout;
- frame = -1;
- for (i=1; i<argc; i++) {
- if (argv[i][0] == '-') {
- switch(argv[i][1]) {
- case 'f':
- if (argv[i][2] && isdigit(argv[i][2])) { frame = atoi(&argv[i][2]); break; }
- if (i+1 >= argc) goto USAGE;
- frame=atoi(argv[++i]);
- break;
- case 'm': merge_flag = 1; break;
- case 'v': verbose_flag = 1; break;
- case 'V': verbose_flag = 2; break;
- case 't': tddd_flag = 1; break;
- default:
- case 'h':
- USAGE:
- fprintf(stderr,"Usage: %s [-tddd] [-merge] [-frame #] [-v|-V] [obj_in] [obj_out]\n",
- argv[0]);
- exit(-1);
- }
- } else if (!infile[0]) {
- strcpy(infile, argv[i]);
- if (!(inp = fopen(infile, "r"))) {
- fprintf(stderr, "Can't open '%s' for input.\n", infile);
- exit(-1);
- }
- } else if (!outfile[0]) {
- strcpy(outfile, argv[i]);
- } else goto USAGE;
- }
- if (!(world = read_World(inp))) {
- fprintf(stderr, "No object to process.\n");
- exit(-1);
- }
- if (merge_flag) merge_World(world);
-
- if (world && world->istg && frame>0)
- load_staging_frame_objects(world, frame);
-
- if (outfile[0] && (world->info || world->object || !tddd_flag)) {
- if (!(out = fopen(outfile, "w"))) {
- fprintf(stderr, "Can't open '%s' for output.\n", outfile);
- exit(-1);
- }
- }
-
- /* If frame was requested, don't write staging file. */
- if (frame>0) world->istg = 0; /* Yeah, I should free the memory */
-
- if (tddd_flag)
- write_TDDD(world, out);
- else
- write_TTDDD(world, out);
- free_World(world);
- exit(0);
- }
-
-