home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / ttddd / code / set_brus.c < prev    next >
C/C++ Source or Header  |  1994-06-20  |  3KB  |  112 lines

  1. /* set_brush_path.c - (re)set the filename path for all brushes (& stencils)
  2.  *                  - written by Glenn M. Lewis - 1/31/93
  3.  */
  4.  
  5. static char rcs_id[] = "$Id: set_brush_path.c,v 1.4 1993/02/14 17:44:16 glewis Exp glewis $";
  6.  
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include "t3dlib.h"
  10. #ifdef __STDC__
  11. #include <stdlib.h>
  12. #include <strings.h>
  13. #include "set_brush_path_protos.h"
  14. #endif
  15.  
  16. char newpath[128];
  17. int newlen;
  18. char strin[160];
  19.  
  20. void change_name(s)
  21. char *s;
  22. {
  23.     register int i;
  24.     register char *p;
  25.  
  26.     if (!*s || !isalpha(*s)) return;
  27.  
  28.     /* First, search for colon in path name */
  29.     for (p=s,i=0; *p && *p!=':' && i<80; i++,p++) ;
  30.     strcpy(strin, newpath);
  31.     if (*p==':') {
  32.         /* Strip off previous path and use new path */
  33.         strncpy(&strin[newlen], &p[1], 80);
  34.     } else {
  35.         /* Simply add new path to beginning of string */
  36.         strncpy(&strin[newlen], s, 80);
  37.     }
  38.     strncpy(s, strin, 80);
  39.     s[80] = '\0';
  40. }
  41.  
  42. main(argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.     char filename[256], rootname[256], *c1, *c2;
  47.     int i;
  48.     WORLD *world;
  49.     FILE *inp, *out;
  50.  
  51.     newpath[0] = '\0';
  52.     rootname[0] = filename[0] = '\0';
  53. /*    strcpy(rootname, "model");    ** The default for reading stdin */
  54.     for (i=1; i<argc; i++) {
  55.         if (argv[i][0] == '-') {
  56.             switch(argv[i][1]) {
  57.                 case 'h':
  58.                 default:
  59. USAGE:
  60.                     fprintf(stderr, "Usage: %s <newpath:> [infile] [outfile]\n", argv[0]);
  61.                     exit(-1);
  62.             }
  63.         } else if (!newpath[0]) {
  64.             strcpy(newpath, argv[i]);
  65.             newlen = strlen(newpath);
  66.             if (newpath[newlen-1]!=':' && newpath[newlen-1]!='/') {
  67.                 /* Add either a slash or a colon to end of newpath... */
  68.                 for (c1=newpath; *c1; c1++) {
  69.                     if (*c1==':') {
  70.                         /* Add slash to end */
  71.                         newpath[newlen++] = '/';
  72.                         break;
  73.                     }
  74.                 }
  75.                 if (newpath[newlen-1]!='/') newpath[newlen++] = ':';
  76.             }
  77.         } else if (filename[0]) {
  78.             strcpy(rootname, argv[i]);
  79.         } else if (!rootname[0]) {
  80.             strcpy(filename, argv[i]);    /* Make root of filename the default */
  81.             for (c1=rootname,c2=argv[i]; (*c1 = *c2++) && *c1!='.'; c1++) ;
  82.             *c1 = '\0';
  83.             strcat(rootname, ".newiob");
  84.         } else goto USAGE;
  85.     }
  86.  
  87.     if (!filename[0]) inp = stdin;
  88.     else if (!(inp = fopen(filename, "r"))) {
  89.         fprintf(stderr, "Can't open '%s' for input.\n", filename);
  90.         exit(-1);
  91.     }
  92.     if (!rootname[0]) out = stdout;
  93.     else if (!(out = fopen(rootname, "w"))) {
  94.         fprintf(stderr, "Can't open '%s' for output.\n", rootname);
  95.         exit(-1);
  96.     }
  97.  
  98.     world = read_World(inp);    /* Parse it all */
  99.  
  100.     /* Now perform all the brush name changes... */
  101.     if (world->info) {
  102.         for (i=0; i<8; i++) {
  103.             change_name(&world->info->brsh[i][0]);
  104.             change_name(&world->info->stnc[i][0]);
  105.         }
  106.     }
  107.  
  108.     write_TDDD(world, out);
  109.     free_World(world);
  110.     exit(0);
  111. }
  112.