home *** CD-ROM | disk | FTP | other *** search
- /* set_brush_path.c - (re)set the filename path for all brushes (& stencils)
- * - written by Glenn M. Lewis - 1/31/93
- */
-
- static char rcs_id[] = "$Id: set_brush_path.c,v 1.4 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_brush_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';
- }
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- char filename[256], rootname[256], *c1, *c2;
- int i;
- WORLD *world;
- FILE *inp, *out;
-
- 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 brush name changes... */
- if (world->info) {
- for (i=0; i<8; i++) {
- change_name(&world->info->brsh[i][0]);
- change_name(&world->info->stnc[i][0]);
- }
- }
-
- write_TDDD(world, out);
- free_World(world);
- exit(0);
- }
-