static void combine(void) /* combine pictures */ { EPNODE *coldef[3], *brtdef; COLOR *scanout; double d; register int i, j; /* check defined variables */ for (j = 0; j < 3; j++) { if (vardefined(vcolout[j])) coldef[j] = eparse(vcolout[j]); else coldef[j] = NULL; } if (vardefined(vbrtout)) brtdef = eparse(vbrtout); else brtdef = NULL; /* allocate scanline */ scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); /* set input position */ yscan = ymax+MIDSCN; /* combine files */ for (ypos = yres-1; ypos >= 0; ypos--) { advance(); varset(vypos, '=', (double)ypos); for (xpos = 0; xpos < xres; xpos++) { xscan = (xpos+.5)*xmax/xres; varset(vxpos, '=', (double)xpos); eclock++; if (brtdef != NULL) { d = evalue(brtdef); if (d < 0.0) d = 0.0; setcolor(scanout[xpos], d, d, d); } else { for (j = 0; j < 3; j++) { if (coldef[j] != NULL) { d = evalue(coldef[j]); } else { d = 0.0; for (i = 0; i < nfiles; i++) d += colval(input[i].scan[MIDSCN][xscan],j); } if (d < 0.0) d = 0.0; colval(scanout[xpos],j) = d; } } } if (fwritescan(scanout, xres, stdout) < 0) { perror("write error"); quit(1); } } efree((char *)scanout); }
double eval( /* evaluate an expression string */ char *expr ) { EPNODE *ep; double rval; ep = eparse(expr); rval = evalue(ep); epfree(ep); return(rval); }
static void readfmt( /* read record format */ char *spec, int output ) { int fd; char *inptr; struct field fmt; int res; register struct field *f; /* check for inline format */ for (inptr = spec; *inptr; inptr++) if (*inptr == '$') break; if (*inptr) /* inline */ inptr = spec; else { /* from file */ if ((fd = open(spec, 0)) == -1) { eputs(spec); eputs(": cannot open\n"); quit(1); } res = read(fd, inpbuf+2, INBSIZ-2); if (res <= 0 || res >= INBSIZ-1) { eputs(spec); if (res < 0) eputs(": read error\n"); else if (res == 0) eputs(": empty file\n"); else if (res >= INBSIZ-1) eputs(": format too long\n"); quit(1); } close(fd); (inptr=inpbuf+2)[res] = '\0'; } f = &fmt; /* get fields */ while ((res = readfield(&inptr)) != F_NUL) { f->next = (struct field *)emalloc(sizeof(struct field)); f = f->next; f->type = res; switch (res & F_TYP) { case T_LIT: f->f.sl = savqstr(inpbuf); break; case T_STR: f->f.sv = getsvar(inpbuf); break; case T_NUM: if (output) f->f.ne = eparse(inpbuf); else f->f.nv = savestr(inpbuf); break; } /* add final newline if necessary */ if (!igneol && *inptr == '\0' && inptr[-1] != '\n') inptr = "\n"; } f->next = NULL; if (output) outfmt = fmt.next; else inpfmt = fmt.next; }