home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Encyclopedia of Graphics File Formats Companion
/
GFF_CD.ISO
/
formats
/
ttddd
/
code
/
set_text.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-20
|
3KB
|
135 lines
/* set_texture_path.c - (re)set the filename path for all textures
* - written by Glenn M. Lewis - 1/31/93
*/
static char rcs_id[] = "$Id: set_texture_path.c,v 1.3 1993/02/14 17:44:16 glewis Exp glewis $";
#include <stdio.h>
#include <ctype.h>
#include "t3dlib.h"
#ifdef __STDC__
#include <stdlib.h>
#include <strings.h>
#include "set_texture_path_protos.h"
#endif
char newpath[128];
int newlen;
char strin[160];
void change_name(s)
char *s;
{
register int i;
register char *p;
if (!*s || !isalpha(*s)) return;
/* First, search for colon in path name */
for (p=s,i=0; *p && *p!=':' && i<80; i++,p++) ;
strcpy(strin, newpath);
if (*p==':') {
/* Strip off previous path and use new path */
strncpy(&strin[newlen], &p[1], 80);
} else {
/* Simply add new path to beginning of string */
strncpy(&strin[newlen], s, 80);
}
strncpy(s, strin, 80);
s[80] = '\0';
}
void change_obj(obj)
register OBJECT *obj;
{
OBJECT *child;
DESC *d;
int i;
if (!obj) return;
if (!obj->desc && !obj->child) return; /* Not an object */
if (d=obj->desc) {
for (i=0; i<4; i++)
if (d->txt2[i])
change_name(&d->txt2[i]->Name[0]);
}
for (child=obj->child; child; child=child->next)
change_obj(child);
}
main(argc, argv)
int argc;
char *argv[];
{
char filename[256], rootname[256], *c1, *c2;
int i;
WORLD *world;
FILE *inp, *out;
OBJECT *p;
newpath[0] = '\0';
rootname[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 'h':
default:
USAGE:
fprintf(stderr, "Usage: %s <newpath:> [infile] [outfile]\n", argv[0]);
exit(-1);
}
} else if (!newpath[0]) {
strcpy(newpath, argv[i]);
newlen = strlen(newpath);
if (newpath[newlen-1]!=':' && newpath[newlen-1]!='/') {
/* Add either a slash or a colon to end of newpath... */
for (c1=newpath; *c1; c1++) {
if (*c1==':') {
/* Add slash to end */
newpath[newlen++] = '/';
break;
}
}
if (newpath[newlen-1]!='/') newpath[newlen++] = ':';
}
} else if (filename[0]) {
strcpy(rootname, argv[i]);
} else if (!rootname[0]) {
strcpy(filename, argv[i]); /* Make root of filename the default */
for (c1=rootname,c2=argv[i]; (*c1 = *c2++) && *c1!='.'; c1++) ;
*c1 = '\0';
strcat(rootname, ".newiob");
} else goto USAGE;
}
if (!filename[0]) inp = stdin;
else if (!(inp = fopen(filename, "r"))) {
fprintf(stderr, "Can't open '%s' for input.\n", filename);
exit(-1);
}
if (!rootname[0]) out = stdout;
else if (!(out = fopen(rootname, "w"))) {
fprintf(stderr, "Can't open '%s' for output.\n", rootname);
exit(-1);
}
world = read_World(inp); /* Parse it all */
/* Now perform all the texture name changes... */
/* Handle old stuff first (TS & pre-Imagine2.0) */
if (world->info) {
for (i=0; i<8; i++)
change_name(&world->info->txtr[i][0]);
}
/* Now take care of Imagine 2.0... */
for (p=world->object; p; p=p->next)
change_obj(p);
write_TDDD(world, out);
free_World(world);
exit(0);
}