Ejemplo n.º 1
0
/* Requires that the string be balanced
   WRT to braces
*/
static char*
commifyr(char* p, Bytebuffer* buf)
{
    int comma = 0;
    int c;
    while((c=*p++)) {
	if(c == ' ') continue;
	if(c == ',') continue;
	else if(c == '}') {
	    break;
	}
	if(comma) bbCat(buf,", "); else comma=1;
	if(c == '{') {
	    bbAppend(buf,'{');
	    p = commifyr(p,buf);
	    bbAppend(buf,'}');
	} else if(c == '\'' || c == '\"') {
	    p = wordstring(p,buf,c);
	} else {
	    bbAppend(buf,c);
	    p=word(p,buf);
	}
    }
    return p;
}
Ejemplo n.º 2
0
static void
runrad(				/* run rad and load variables */
	int	ac,
	char	**av
)
{
	static char	optfile[] = TEMPLATE;
	int	nvn = 0, nvv = 0;
	FILE	*fp;
	register char	*cp;
	char	radcomm[256], buf[128], nam[32];
					/* set rad commmand */
	strcpy(radcomm, "rad -w -v 0        ");	/* look out below! */
	cp = radcomm + 19;
	if (silent) {
		strcpy(cp, "-s ");
		cp += 3;
	}
	while (ac--) {
		strcpy(cp, *av++);
		while (*cp) cp++;
		*cp++ = ' ';
	}
	strcpy(cp, "OPTFILE=");		/* create temporary options file */
	strcpy(cp+8, mktemp(optfile));
	if (system(radcomm))		/* update octree */
		error(USER, "error executing rad command");
					/* replace "-v 0" with "-n -e -s -V" */
	strcpy(radcomm+7, "-n -e -s -V");
	radcomm[18] = ' ';
	if ((fp = popen(radcomm, "r")) == NULL)
		error(SYSTEM, "cannot start rad command");
	buf[0] = '\0';			/* read variables alphabetically */
						/* get exposure */
	if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
		expval = atof(cp);
		if ((*cp == '-') | (*cp == '+'))
			expval = pow(2., expval);
		expval *= 0.5;		/* compensate for local shading */
	}
						/* look for eye separation */
	if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
		eyedist = atof(cp);
						/* look for materials */
	while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* look for octree */
	if ((cp = scan4var(buf, sizeof(buf), "OCTREE", fp)) != NULL)
		octree = savqstr(cp);
						/* look for scene files */
	while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* load view names */
	while ((cp = scan4var(buf, sizeof(buf), "view", fp)) != NULL) {
		if (nvn >= MAXVIEW)
			error(INTERNAL, "too many views in rad file");
		vwl[nvn++].nam = *cp == '-' ? (char *)NULL :
				savqstr(atos(nam, sizeof(nam), cp));
		buf[0] = '\0';
	}
						/* load actual views */
	do
		if (isview(buf)) {
			vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
			*(vwl[nvv].v) = stdview;
			sscanview(vwl[nvv].v, buf);
			if ((cp = setview(vwl[nvv++].v)) != NULL) {
				fprintf(stderr, "%s: bad view %d - %s\n",
						progname, nvv, cp);
				quit(1);
			}
		}
	while (fgets(buf, sizeof(buf), fp) != NULL);
	if (nvv != nvn)
		error(INTERNAL, "view miscount in runrad");
	pclose(fp);
						/* open options file */
	if ((fp = fopen(optfile, "r")) == NULL)
		error(SYSTEM, "cannot open options file");
						/* get relevant options */
	while (fgets(buf, sizeof(buf), fp) != NULL)
		if (!strncmp(buf, "-av ", 4))
			setcolor(ambval, atof(buf+4),
					atof(sskip2(buf+4,1)),
					atof(sskip2(buf+4,2)));
		else if (backvis && !strncmp(buf, "-bv", 3) &&
				(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
			backvis = 0;
	fclose(fp);
	unlink(optfile);			/* delete options file */
}