[net.sources] Graphics database manipulation programs: code

ken@turtleva.UUCP (Ken Turkowski) (12/17/83)

echo x - data/code
mkdir data/code
echo x - data/code/bb_to_txtr.c
cat >data/code/bb_to_txtr.c <<'!Funky!Stuff!'

/* bb_to_txtr.c - convert a portion of the big frame buffer memory to a
		  texture image file - uses screen ofsets given by bbzoom
		  to select 128X128 area of screen to use  */

#include <stdio.h>

#define TXTR_CODE	0x72747874
#define LINE_LENGTH	81
#define TX_RES		128

static long buffer[TX_RES];
static short texture[TX_RES][TX_RES][5];

main(argc,argv)
int argc;	char **argv;
{   short size,j,i,Xofset,Yofset,zoom,hres,vres;
    double atof();	char instrg[LINE_LENGTH];
    FILE *output;	long array[4],code;

    bbopen();		/* get Big Buffer */

    if (argc < 2)  
    {   printf(" texture image file name: ");
	if ((output = fopen(gets(instrg),"w")) == NULL) error("can't open file");
    } 
    else if ((output = fopen(argv[1],"w")) == NULL)  error("can't open file");

    bbread(1,501,array,3);		/* get zoom and pan */
    zoom = array[0];    hres = 640/zoom;    vres = 484/zoom;
    Xofset = 20 * array[1] + hres/2 - TX_RES/2;
    Yofset = (483 - array[2]) - vres/2 - TX_RES/2;
printf(" zoom %d  xofset %d   yofset %d \n",zoom,Xofset,Yofset);
    for (i=0; i<TX_RES; i++) 
    {   bbread(Xofset,Yofset+i,buffer,TX_RES); /* read buffer */
	for (j=0; j<TX_RES; j++)
	{   texture[i][j][0] = (buffer[j] >> 16) & 255;
	    texture[i][j][1] = (buffer[j] >>  8) & 255;
	    texture[i][j][2] = (buffer[j]      ) & 255;
	    texture[i][j][3] = (buffer[j] >> 24) & 255;
	    texture[i][j][4] = 255;
	}
    }
    code = TXTR_CODE;
    fwrite(&code,4,1,output);
    size = 128;
    fwrite(&size,2,1,output);

    fwrite(texture,2,TX_RES*TX_RES*5,output);
    fclose(output);
}
!Funky!Stuff!
echo x - data/code/bin_tags.c
cat >data/code/bin_tags.c <<'!Funky!Stuff!'
/* add magic number tags to binary files */

#include <stdio.h>

#define DET_CODE	0x20746564
#define PCL_CODE	0x206C6370
#define VCL_CODE	0x206C6376
#define TXC_CODE	0x20637874
#define TXTR_CODE	0x72747874

#define FB_CODE		0x20206266
#define BB_CODE		0x20206262
#define FBL_CODE	0x206C6266
#define BBL_CODE	0x206C6262
#define AED_CODE	0x20646561

main(argc,argv)
int argc;   char **argv;
{   FILE *output,*input;  short i,npts,npolys,nvtx,p[10];   long code;
    char filnam[81],savnam[81],string[81],*strptr,*strcat(),*strncpy(),*rindex();

    /* nocore(); prevent core dumps */

    printf("WARNING!!!!!  Do not make a habit of using this program.\n");
    printf("              It will disappear when no longer necessary.\n");

    if (argc < 2) 
    {   printf("file name: ");    gets(filnam);   }  /* get output filename */
    else strcpy(filnam,argv[1]);

    if ((strptr = rindex(filnam,'.')) == 0)
        error("Non standard filename extension - %s\nStandard extensions are .det,.pcl,.vcl,.txc,.txtr,.fb,.bb,.fbl,.bbl,.aed\n",filnam); /*no extension*/
    else
	if      (strcmp(strptr,".det") == 0)   code = DET_CODE;
	else if (strcmp(strptr,".pcl") == 0)  code = PCL_CODE;
	else if (strcmp(strptr,".vcl") == 0)   code = VCL_CODE;
	else if (strcmp(strptr,".txc") == 0)   code = TXC_CODE;
	else if (strcmp(strptr,".txtr") == 0)  code = TXTR_CODE;

	else if (strcmp(strptr,".fb") == 0)   code = FB_CODE;
	else if (strcmp(strptr,".bb") == 0)  code = BB_CODE;
	else if (strcmp(strptr,".fbl") == 0)  code = FBL_CODE;
	else if (strcmp(strptr,".bbl") == 0)  code = BBL_CODE;
	else if (strcmp(strptr,".aed") == 0)  code = AED_CODE;
	else if (strcmp(strptr,".obj") == 0) 
		error("This doesn't fix .obj files.  Just edit out all the '512's to fix them.");
	else	error("Non standard filename extension - %s\nStandard extensions are .det,.pcl,.vcl,.txc,.txtr,.fb,.bb,.fbl,.bbl,.aed\n",filnam); /*no extension*/

    if ((input = fopen(filnam,"r")) == NULL)
        error("unable to open %s\n",filnam);
    else
    {   short word,length;    char tag[5];

	fread(tag,1,4,input);    tag[4] = '\0';
	printf("Tag field now contains \"%s\".  Do you wish to tag this file? ",tag);
	if (strcmp(gets(string),"yes") != 0)
	{   close(input);    error("Since you didn't reply 'yes', I quit!  File not fixed.");  }
	else
	{   close(input);    input = fopen(filnam,"r");   }

	output = fopen("bin_tags.tmp","w");
	fwrite(&code,4,1,output);	/* insert tag */
 
	while (fread(&word,2,1,input) != 0)
	    fwrite(&word,2,1,output);

	close(output);    close(input);

	length = strlen(filnam) - strlen(strptr);
	strncpy(savnam,filnam,length);    strptr = strcat(savnam,".bak");
	system(sprintf(string," mv %s %s",filnam,strptr));
	system(sprintf(string," mv bin_tags.tmp %s",filnam));
	
	printf("%s replaced with tagged file - original file in %s\n",filnam,savnam);
    }
}
!Funky!Stuff!
echo x - data/code/circle_eye.c
cat >data/code/circle_eye.c <<'!Funky!Stuff!'
/* circle_eye.c - makes circular path moves for scn_assmblr  */

#include <stdio.h>

#define pi  3.14159

main()
{   char instrg[81],filename[81];	FILE *output;
    short i,j,k,numfrm,divisions;
    double dx,dy,dz,start[3],middle[3],end[3],sin(),cos(),sqrt(),ceil();

    printf(" output file name : ");    gets(filename);
    output = fopen(filename,"w");

    printf(" start point (rt,out,up) : ");
    sscanf(gets(instrg),"%f %f %f",&start[0],&start[1],&start[2]);

    printf(" no. of frames : ");    sscanf(gets(instrg),"%hd",&numfrm);

    divisions = ceil(numfrm/4.);

    for (k=0; k<numfrm; k++)
    {   double alph,px,py,pz,fac;
	alph = 2.*pi*k/(numfrm-1);
	px = start[0]*cos(alph) - start[1]*sin(alph);
	py = start[0]*sin(alph) + start[1]*cos(alph);
	pz = start[2];

	fprintf(output,"place eyepoint at %g %g %g\n",px,py,pz);
	fprintf(output,"display_on bb 8 %d %d\n",divisions,k);
    }
}

!Funky!Stuff!
echo x - data/code/color_bin.c
cat >data/code/color_bin.c <<'!Funky!Stuff!'
/* color_bin.c - make binary standard color files from ASCII standard files */

#include <stdio.h>

#define PCL_CODE	0x206C6370
#define VCL_CODE	0x206C6376

main()

{   FILE *output;  short i,npts,dum,p[64];    long code;
    float point[4];  char string[512],str2[512];
    
    do  gets(string);		/* read until EOF or "data" keyword */ 
    while ((*string != NULL) && (strncmp(string,"data",4) != 0) && 
				(strncmp(string,"DATA",4) != 0));

    code = PCL_CODE;    fwrite(&code,4,1,stdout);

    sscanf(string,"%s %hd %hd",str2,&npts,&dum);
    fwrite(&npts,2,1,stdout);

    for (i=0; i<npts; i++) 		/* read in and copy out points */
    {   gets(string);
	sscanf(string,"%f %f %f %f",&point[0],&point[1],&point[2],&point[3]);
	if ((point[0] < 0.) || (point[0] > 1.)) error(" value > 1. or < 0.");
	if ((point[1] < 0.) || (point[1] > 1.)) error(" value > 1. or < 0.");
	if ((point[2] < 0.) || (point[2] > 1.)) error(" value > 1. or < 0.");
	if ((point[3] < 0.) || (point[3] > 1.)) error(" value > 1. or < 0.");
	fwrite(point,4,4,stdout);
    }

}
!Funky!Stuff!
echo x - data/code/make_bin.c
cat >data/code/make_bin.c <<'!Funky!Stuff!'
/* make_bin.c - make binary standard polygon data files ASCII standard files */

#include <stdio.h>

#define DET_CODE	0x20746564

main()

{   FILE *output;    short i,npts,npolys,nvtx,p[64];    long code;
    float point[3];    char string[512],str2[512];

    /* nocore();	prevent core dumps */

    do  gets(string);		/* read until EOF or "data" keyword */ 
    while ((*string != NULL) && (strncmp(string,"data",4) != 0) && 
				(strncmp(string,"DATA",4) != 0));

    code = DET_CODE;		/* put on magic number tag */
    fwrite(&code,4,1,stdout);

    sscanf(string,"%s %hd %hd",str2,&npts,&npolys);
    fwrite(&npts,2,1,stdout);
    fwrite(&npolys,2,1,stdout);

    for (i=0; i<npts; i++) 		/* read in and copy out points */
    {   gets(string);
	sscanf(string,"%f %f %f",&point[0],&point[1],&point[2]);
	fwrite(point,4,3,stdout);
    }

    for (i=0; i<npolys; i++)		/* do polygons */
    {   short j,k;
	gets(string);
	j = 0;    while(string[j] == ' ') j++;	/* ignore blanks */
	nvtx = atoi(&string[j]);		/* get number of vertices */
	for (k=0; k<nvtx; k++)
	{   while(string[j] != ' ') j++;    p[k] = atoi(&string[j]); 
	    while(string[j] == ' ') j++;       /* look for blank, read number */
	}
	fwrite(&nvtx,2,1,stdout);
	for (j=0; j<nvtx; j++) fwrite(&p[j],2,1,stdout); /* write out polygon */
    }
}
!Funky!Stuff!
echo x - data/code/make_obj.c
cat >data/code/make_obj.c <<'!Funky!Stuff!'
/* make object description files */

#include <stdio.h>

#define	MAXPTS		32768
#define DET_CODE	0x20746564

main()

{   FILE *output,*input;  short i,npts,npolys,nvtx,p[10];   long code;
    char filnam[81],string[81],str2[81],*substr;
    struct { float x,y,z; } pts[MAXPTS];

    /* nocore();	prevent core dumps */

    printf("object name: ");	gets(filnam);	       /* get output filename */
    if (index(filnam,'.') != 0)  output = fopen(filnam,"w");
    else  output = fopen(strcat(filnam,".obj"),"w");   /*add ".obj" if no ext.*/

    
    printf("title: ");	gets(string);		/* get title, copy to output */
    fputs("title\t\t",output);  fputs(string,output);  fputs("\n",output);
   
    printf("display routine: ");    gets(string);
    fputs("display\t\t",output);
    fputs(strcat(str2,string),output);    fputs("\n",output);
   
    printf("detail file: ");	gets(string);
    fputs("detail\t\t",output);
    fputs(string,output);  fputs("\n",output);
  
    fputs("type\t\tpolygon\n",output);
 
    if ( (input = fopen(string,"r")) != NULL)
    {   fread(&code,4,1,input);
	if (code != DET_CODE)
	{   fprintf(stderr,"warning!! %s not tagged as detail file\n",string);
	    close(input);   fopen(string,"r");
	}
	fread(&npts,2,1,input);    fread(&npolys,2,1,input);
	if ( npts <= MAXPTS ) for (i=0; i<npts; i++) 
        {   double xmin,xmax,ymin,ymax,zmin,zmax;
	    fread(&pts[i],4,3,input);
            if (i==0)
	    {  xmin=xmax=pts[0].x;  ymin=ymax=pts[0].y;  zmin=zmax=pts[0].z;  }
	    else
	    {   if (pts[i].x < xmin) xmin = pts[i].x;
		    else if (pts[i].x > xmax) xmax = pts[i].x;
	        if (pts[i].y < ymin) ymin = pts[i].y;
		    else if (pts[i].y > ymax) ymax = pts[i].y;
	        if (pts[i].z < zmin) zmin = pts[i].z;
		    else if (pts[i].z > zmax) zmax = pts[i].z;
            }
	    if (i == npts-1) 
	    fprintf(output,"bounding_box\t%g %g %g %g %g %g\n",
					    xmin,xmax,ymin,ymax,zmin,zmax);
 	}
	else printf("Too many vertices. %d is > 32768 \n",npts);	
    }
    else printf("unable to open %s\n",string);
}
!Funky!Stuff!
echo x - data/code/make_texture.c
cat >data/code/make_texture.c <<'!Funky!Stuff!'
/* make_texture.c - build a 5 x 128 x 128 array representing a smoothish
		    image of texture
		  - the 5 parameters are R,G,B,Transmittance & Gloss - all
		    vary from 0 to 255.
*/

#include <stdio.h>

#define TXTR_CODE	0x72747874
#define sqr(x)    ((x)*(x))

static short texture[128][128][5];

main()
{   short size,i,j;    long code;    FILE *output;   double sin(),pow();

    code = TXTR_CODE;    size = 128;

 /* output = fopen("spots.txtr","w");
    for (i=0; i<128; i++)   for (j=0; j<128; j++)
    {   texture[i][j][0] = texture[i][j][1] = texture[i][j][2] =
		 	   texture[i][j][3] = texture[i][j][4] = 
			   128. + 128. * sin(i*3.1416/16.) * sin(j*3.1416/16.);
    }
    fwrite(&code,4,1,output);    fwrite(&size,2,1,output);
    fwrite(texture,2,128*128*5,output);
    fclose(output); */

 /* output = fopen("stripes.txtr","w");
    for (i=0; i<128; i++)   for (j=0; j<128; j++)
    {   double temp;
	texture[i][j][0] = texture[i][j][4] = 255;
	temp = sin(((i+j)%256) * 3.1416/32.);
	temp = (temp > 0.)?  255. * (1. - pow(temp,.5)) : 255.;
	texture[i][j][1] = texture[i][j][2]  = texture[i][j][3] = temp;
    }
    fwrite(&code,4,1,output);    fwrite(&size,2,1,output);
    fwrite(texture,2,128*128*5,output);
    fclose(output); */

    output = fopen("hatching.txtr","w");
    for (i=0; i<128; i++)   for (j=0; j<128; j++)
    {   double temp,temp2;
	temp = sin(i*3.1416/8.);    temp2 = sin(j*3.1416/8.);
	temp  = (temp  > 0.)?  1. : 0.;
	temp2 = (temp2 > 0.)?  1. : 0.;		/* pow(temp2,2.) */
	if (temp2 > temp) temp = temp2;
	texture[i][j][0] = texture[i][j][1] = texture[i][j][2] = 255. * temp;
	texture[i][j][3] = texture[i][j][4] = 255. * (1. - temp);
    }

    fwrite(&code,4,1,output);    fwrite(&size,2,1,output);
    fwrite(texture,2,128*128*5,output);
    fclose(output);
}
!Funky!Stuff!
echo x - data/code/makefile
cat >data/code/makefile <<'!Funky!Stuff!'
CFLAGS		= -O

make_obj:	make_obj.o
	cc make_obj.o -lm -o make_obj
	rm make_obj
	rm make_obj.o

make_bin:	make_bin.o
	cc make_bin.o -lm -o make_bin
	rm make_bin
	rm make_bin.o

dg_bin:		dg_bin.o
	cc dg_bin.o -lm -o dg_bin
	rm dg_bin
	rm dg_bin.o

color_bin:	color_bin.o
	cc color_bin.o -lm -o color_bin
	rm color_bin
	rm color_bin.o

txtr_bin:	txtr_bin.o
	cc txtr_bin.o -lm -o txtr_bin
	rm txtr_bin
	rm txtr_bin.o


mk_txcoords:	mk_txcoords.o
	cc mk_txcoords.o -lm -o mk_txcoords
	rm mk_txcoords
	rm mk_txcoords.o

bb_to_txtr:	bb_to_txtr.o
	cc bb_to_txtr.o -lm -lbb -o bb_to_txtr
	rm bb_to_txtr
	rm bb_to_txtr.o

make_texture:	make_texture.o
	cc make_texture.o -lm -o make_texture

bin_tags:	bin_tags.o
	cc bin_tags.o -o bin_tags
	rm bin_tags
	rm bin_tags.o

!Funky!Stuff!
echo x - data/code/mk_txcoords.c
cat >data/code/mk_txcoords.c <<'!Funky!Stuff!'
/* mk_txcoords.c - make binary standard polygon texture coordinate files to
		   map onto surfaces which are described by a rectangular  
		   array of vertices (eg. terrains and surfaces of revolution)

	Polygon array is characterized by the number of polygons in a strip
	and the number of strips.  Texture coordinates are given for the
	beginning and end of the first and last strips respectively.
*/


#include <stdio.h>

#define TXC_CODE	0x20637874

main(argc,argv)
int argc;    char **argv;

{   FILE *output;  short i,npolys,nvtx,pols_in_strip,num_strips;    long code;
    struct { float x,y; }  p[4],beg_fstrp,end_fstrp,beg_lstrp,end_lstrp;
    double atof(),x_beg_inc,y_beg_inc,x_end_inc,y_end_inc,
		  x_beg,    y_beg,    x_end,    y_end    ;
    char filename[80];

    if (argc != 12)  error(" Usage: filename #_per_strip  #_strips  4 corner_coords");
  
    output = fopen(argv[1],"w");
    pols_in_strip = atoi(argv[2]);	num_strips = atoi(argv[3]);
    beg_fstrp.x = atof(argv[4]);	beg_fstrp.y = atof(argv[5]);
    end_fstrp.x = atof(argv[6]);	end_fstrp.y = atof(argv[7]);
    beg_lstrp.x = atof(argv[8]);	beg_lstrp.y = atof(argv[9]);
    end_lstrp.x = atof(argv[10]);	end_lstrp.y = atof(argv[11]);

    code = TXC_CODE;
    fwrite(&code,4,1,output);

    npolys = pols_in_strip * num_strips; 
    fwrite(&npolys,2,1,output);

    nvtx = 4;
    x_beg_inc = (beg_lstrp.x - beg_fstrp.x) / num_strips;
    y_beg_inc = (beg_lstrp.y - beg_fstrp.y) / num_strips;
    x_end_inc = (end_lstrp.x - end_fstrp.x) / num_strips;
    y_end_inc = (end_lstrp.y - end_fstrp.y) / num_strips;

    y_beg = beg_fstrp.y;	y_end = end_fstrp.y;
    x_beg = beg_fstrp.x;	x_end = end_fstrp.x;

    for (i=0; i<num_strips; i++)		/* do polygons */
    {   short j,k;   double xfst,xlst,yfst,ylst,xfinc,yfinc,xlinc,ylinc;
	xfst = x_beg;		    xfinc = (x_end - x_beg) / (pols_in_strip);
	yfst = y_beg;	   	    yfinc = (y_end - y_beg) / (pols_in_strip);
	xlst = x_beg + x_beg_inc;   
	xlinc = ((x_end + x_end_inc) - (x_beg + x_beg_inc)) / (pols_in_strip);
	ylst = y_beg + y_beg_inc;
	ylinc = ((y_end + y_end_inc) - (y_beg + y_beg_inc)) / (pols_in_strip);

	for (j=0; j<pols_in_strip; j++)
	{   fwrite(&nvtx,2,1,output);

	    p[0].x = xfst;		p[0].y = yfst;
	    p[3].x = xlst;		p[3].y = ylst;
	    p[2].x = xlst + xlinc;	p[2].y = ylst + ylinc;
	    p[1].x = xfst + xfinc;	p[1].y = yfst + yfinc;

	    fwrite(p,4,nvtx*2,output); /* write out polygon */

	    xfst += xfinc;		xlst += xlinc;
	    yfst += yfinc;		ylst += ylinc;
	}
	x_beg += x_beg_inc;		y_beg += y_beg_inc;
	x_end += x_end_inc;		y_end += y_end_inc;
    }
}
!Funky!Stuff!
echo x - data/code/move_eye.c
cat >data/code/move_eye.c <<'!Funky!Stuff!'
/* move_eye.c - makes path moves for scn_assmblr  */

#include <stdio.h>

#define pi  3.14159

main()
{   char instrg[81],filename[81];	FILE *output;
    short i,j,k,numfrm,divisions;
    double dx,dy,dz,start[3],middle[3],end[3],sin(),cos(),sqrt(),ceil();

    printf(" output file name : ");    gets(filename);
    output = fopen(filename,"w");

    printf(" start point (rt,out,up) : ");
    sscanf(gets(instrg),"%f %f %f",&start[0],&start[1],&start[2]);
    printf(" middle point : ");
    sscanf(gets(instrg),"%f %f %f",&middle[0],&middle[1],&middle[2]);
    printf(" end point : ");
    sscanf(gets(instrg),"%f %f %f",&end[0],&end[1],&end[2]);

    printf(" no. of frames : ");    sscanf(gets(instrg),"%hd",&numfrm);

    divisions = ceil(numfrm/4.);

    dx = middle[0] - (end[0]+start[0])/2.;
    dy = middle[1] - (end[1]+start[1])/2.;
    dz = middle[2] - (end[2]+start[2])/2.;

    for (k=0; k<numfrm; k++)
    {   double alph,px,py,pz,fac;
	alph = pi*k/(numfrm-1);
	fac = .5*(1. - cos(alph)); /* ranges 0 to 1 */
	px = start[0]*(1.-fac) + end[0]*fac;
	py = start[1]*(1.-fac) + end[1]*fac;
	pz = start[2]*(1.-fac) + end[2]*fac;

	fac = sin(alph);
	px = px + dx*fac;
	py = py + dy*fac;
	pz = pz + dz*fac;

	fprintf(output,"place eyepoint at %g %g %g\n",px,py,pz);
	fprintf(output,"display_on bb 8 %d %d\n",divisions,k);
    }
}

!Funky!Stuff!
echo x - data/code/rescale_bin.c
cat >data/code/rescale_bin.c <<'!Funky!Stuff!'
/* bbox_bin.c - make binary standard polygon data files from Wayne's output
		and scale to unit length in z (-.5 to .5)  */

#include <stdio.h>

main()

{   FILE *output;  short i,npts,npolys,nvtx,p[64];  
    float point[3];  char string[512],str2[512];
    double x1,x2,y1,y2,z1,z2,zscale;
 
    do  
    {   gets(string);		/* read until EOF or "data" keyword */ 
	if (strncmp(string,"BOUNDING BOX",12) == 0)
	    sscanf(string,"%s %s %f %f %f %f %f %f",str2,str2,&x1,&x2,&z1,&z2,&y1,&y2);
    }
    while ((*string != NULL) && (strncmp(string,"data",4) != 0) && 
				(strncmp(string,"DATA",4) != 0));
    
    sscanf(string,"%s %hd %hd",str2,&npts,&npolys);
    fwrite(&npts,2,1,stdout);
    fwrite(&npolys,2,1,stdout);

    zscale = 1. / (z2 - z1);    z1 = (z2 - z1)/2. + z1;

    for (i=0; i<npts; i++) 		/* read in and copy out points */
    {   gets(string);
	sscanf(string,"%f %f %f",&point[0],&point[2],&point[1]);
	point[2] = zscale * (point[2] - z1);
	point[2] = -point[2];
	fwrite(point,4,3,stdout);
    }

    for (i=0; i<npolys; i++)		/* do polygons */
    {   short j,k;
	gets(string);
	j = 0;    while(string[j] == ' ') j++;	/* ignore blanks */
	nvtx = atoi(&string[j]);		/* get number of vertices */
	for (k=0; k<nvtx; k++)
	{   while(string[j] != ' ') j++;    p[k] = atoi(&string[j]); 
	    while(string[j] == ' ') j++;       /* look for blank, read number */
	}
	fwrite(&nvtx,2,1,stdout);
	for (j=0; j<nvtx; j++) fwrite(&p[j],2,1,stdout); /* write out polygon */
    }
}
!Funky!Stuff!
echo x - data/code/txtr_bin.c
cat >data/code/txtr_bin.c <<'!Funky!Stuff!'
/* txtr_bin.c - make binary standard polygon texture coordinate files from
		ASCII files of the same format  */

#include <stdio.h>

#define TXC_CODE	0x20637874

main()

{   FILE *output;  short i,npolys,nvtx;   long code;
    struct { float x,y; }  p[64];  
    char string[512],str2[512];
    
    do  gets(string);		/* read until EOF or "data" keyword */ 
    while ((*string != NULL) && (strncmp(string,"data",4) != 0) && 
				(strncmp(string,"DATA",4) != 0));

    code = TXC_CODE;    fwrite(&code,4,1,stdout);
 
    sscanf(string,"%s %hd",str2,&npolys);
    fwrite(&npolys,2,1,stdout);

    for (i=0; i<npolys; i++)		/* do polygons */
    {   short j,k;    double atof();
	gets(string);
	j = 0;    while(string[j] == ' ') j++;	/* ignore blanks */
	nvtx = atoi(&string[j]);		/* get number of vertices */
	for (k=0; k<nvtx; k++)
	{   while(string[j] != ' ') j++;    p[k].x = atof(&string[j]);
	    while(string[j] == ' ') j++;	/* ignore blanks */
	    while(string[j] != ' ') j++;    p[k].y = atof(&string[j]);
	    while(string[j] == ' ') j++;	/* ignore blanks */
	                                       /* look for blank, read number */
	}
	fwrite(&nvtx,2,1,stdout);
	fwrite(p,4,nvtx*2,stdout); /* write out polygon */
    }
}
!Funky!Stuff!