25 |
|
typedef double DCOLOR[3]; /* double-precision color */ |
26 |
|
|
27 |
|
/* |
28 |
< |
* The modcont structure is used to accumulate ray contributions |
28 |
> |
* The MODCONT structure is used to accumulate ray contributions |
29 |
|
* for a particular modifier, which may be subdivided into bins |
30 |
< |
* if binv is non-NULL. If outspec contains a %s in it, this will |
30 |
> |
* if binv is non-zero. If outspec contains a %s in it, this will |
31 |
|
* be replaced with the modifier name. If outspec contains a %d in it, |
32 |
|
* this will be used to create one output file per bin, otherwise all bins |
33 |
|
* will be written to the same file, in order. If the global outfmt |
46 |
|
|
47 |
|
LUTAB modconttab = LU_SINIT(NULL,mcfree); /* modifier lookup table */ |
48 |
|
|
49 |
< |
/* close output stream */ |
50 |
< |
static void closefile(void *p) { fclose((FILE *)p); } |
49 |
> |
#define CNT_UNKNOWN 0 /* unknown record length */ |
50 |
> |
#define CNT_PIPE (-1) /* output to a pipe */ |
51 |
> |
/* |
52 |
> |
* The STREAMOUT structure holds an open FILE pointer and a count of |
53 |
> |
* the number of RGB triplets per record, or CNT_UNKNOWN (0) if |
54 |
> |
* unknown or CNT_PIPE (-1) if writing to a command. |
55 |
> |
*/ |
56 |
> |
typedef struct { |
57 |
> |
FILE *ofp; /* output file pointer */ |
58 |
> |
int reclen; /* triplets/record */ |
59 |
> |
} STREAMOUT; |
60 |
|
|
61 |
< |
LUTAB ofiletab = LU_SINIT(free,closefile); /* output file table */ |
61 |
> |
/* close output stream and free record */ |
62 |
> |
static void |
63 |
> |
closestream(void *p) |
64 |
> |
{ |
65 |
> |
STREAMOUT *sop = (STREAMOUT *)p; |
66 |
> |
int status; |
67 |
> |
if (sop->reclen == CNT_PIPE) |
68 |
> |
status = pclose(sop->ofp); |
69 |
> |
else |
70 |
> |
status = fclose(sop->ofp); |
71 |
> |
if (status) |
72 |
> |
error(SYSTEM, "error closing output stream"); |
73 |
> |
free(p); |
74 |
> |
} |
75 |
|
|
76 |
+ |
LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ |
77 |
+ |
|
78 |
|
#define OF_MODIFIER 01 |
79 |
|
#define OF_BIN 02 |
80 |
|
|
81 |
< |
FILE *getofile(const char *ospec, const char *mname, int bn); |
81 |
> |
STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int noopen); |
82 |
|
int ofname(char *oname, const char *ospec, const char *mname, int bn); |
83 |
|
void printheader(FILE *fout, const char *info); |
84 |
+ |
void printresolu(FILE *fout); |
85 |
|
|
86 |
|
/* |
87 |
|
* The rcont structure is used to manage i/o with a particular |
139 |
|
|
140 |
|
#define queue_length() (lastray - lastdone) |
141 |
|
|
142 |
< |
MODCONT *addmodifier(char *modn, char *outf, char *binv); |
143 |
< |
void addmodfile(char *fname, char *outf, char *binv); |
142 |
> |
MODCONT *growmodifier(MODCONT *mp, int nb); |
143 |
> |
MODCONT *addmodifier(char *modn, char *outf, char *binv, int bincnt); |
144 |
> |
void addmodfile(char *fname, char *outf, char *binv, int bincnt); |
145 |
|
|
146 |
|
void init(int np); |
147 |
|
int done_rprocs(struct rtproc *rtp); |
211 |
|
int recover = 0; |
212 |
|
char *curout = NULL; |
213 |
|
char *binval = NULL; |
214 |
+ |
int bincnt = 0; |
215 |
|
char fmt[8]; |
216 |
|
int i, j; |
217 |
|
/* need at least one argument */ |
299 |
|
if (argv[i][2] || i >= argc-2) break; |
300 |
|
yres = atoi(argv[++i]); |
301 |
|
continue; |
302 |
< |
case 'b': /* bin expression */ |
303 |
< |
if (argv[i][2] || i >= argc-2) break; |
302 |
> |
case 'b': /* bin expression/count */ |
303 |
> |
if (i >= argc-2) break; |
304 |
> |
if (argv[i][2] == 'n') { |
305 |
> |
bincnt = atoi(argv[++i]); |
306 |
> |
continue; |
307 |
> |
} |
308 |
> |
if (argv[i][2]) break; |
309 |
|
binval = argv[++i]; |
310 |
|
continue; |
311 |
|
case 'm': /* modifier name */ |
312 |
|
if (argv[i][2] || i >= argc-2) break; |
313 |
|
rtargv[rtargc++] = "-ti"; |
314 |
|
rtargv[rtargc++] = argv[++i]; |
315 |
< |
addmodifier(argv[i], curout, binval); |
315 |
> |
addmodifier(argv[i], curout, binval, bincnt); |
316 |
|
continue; |
317 |
|
case 'M': /* modifier file */ |
318 |
|
if (argv[i][2] || i >= argc-2) break; |
319 |
|
rtargv[rtargc++] = "-tI"; |
320 |
|
rtargv[rtargc++] = argv[++i]; |
321 |
< |
addmodfile(argv[i], curout, binval); |
321 |
> |
addmodfile(argv[i], curout, binval, bincnt); |
322 |
|
continue; |
323 |
|
} |
324 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
488 |
|
waitflush = xres; |
489 |
|
} |
490 |
|
|
491 |
+ |
/* grow modifier to accommodate more bins */ |
492 |
+ |
MODCONT * |
493 |
+ |
growmodifier(MODCONT *mp, int nb) |
494 |
+ |
{ |
495 |
+ |
if (nb <= mp->nbins) |
496 |
+ |
return mp; |
497 |
+ |
mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + sizeof(DCOLOR)*(nb-1)); |
498 |
+ |
if (mp == NULL) |
499 |
+ |
error(SYSTEM, "out of memory in growmodifier"); |
500 |
+ |
memset(mp->cbin+mp->nbins, 0, sizeof(DCOLOR)*(nb-mp->nbins)); |
501 |
+ |
mp->nbins = nb; |
502 |
+ |
return mp; |
503 |
+ |
} |
504 |
+ |
|
505 |
|
/* add modifier to our list to track */ |
506 |
|
MODCONT * |
507 |
< |
addmodifier(char *modn, char *outf, char *binv) |
507 |
> |
addmodifier(char *modn, char *outf, char *binv, int bincnt) |
508 |
|
{ |
509 |
|
LUENT *lep = lu_find(&modconttab, modn); |
510 |
|
MODCONT *mp; |
511 |
+ |
int i; |
512 |
|
|
513 |
|
if (lep->data != NULL) { |
514 |
|
sprintf(errmsg, "duplicate modifier '%s'", modn); |
521 |
|
mp = (MODCONT *)malloc(sizeof(MODCONT)); |
522 |
|
if (mp == NULL) |
523 |
|
error(SYSTEM, "out of memory in addmodifier"); |
477 |
– |
lep->data = (char *)mp; |
524 |
|
mp->outspec = outf; /* XXX assumes static string */ |
525 |
|
mp->modname = modn; /* XXX assumes static string */ |
526 |
|
if (binv != NULL) |
529 |
|
mp->binv = eparse("0"); |
530 |
|
mp->nbins = 1; |
531 |
|
setcolor(mp->cbin[0], 0., 0., 0.); |
532 |
+ |
if (mp->binv->type == NUM) /* assume one bin if constant */ |
533 |
+ |
bincnt = 1; |
534 |
+ |
else if (bincnt > 1) |
535 |
+ |
mp = growmodifier(mp, bincnt); |
536 |
+ |
lep->data = (char *)mp; |
537 |
+ |
/* allocate output streams */ |
538 |
+ |
for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i--; ) |
539 |
+ |
getostream(mp->outspec, mp->modname, i, 1); |
540 |
|
return mp; |
541 |
|
} |
542 |
|
|
543 |
|
/* add modifiers from a file list */ |
544 |
|
void |
545 |
< |
addmodfile(char *fname, char *outf, char *binv) |
545 |
> |
addmodfile(char *fname, char *outf, char *binv, int bincnt) |
546 |
|
{ |
547 |
|
char *mname[MAXMODLIST]; |
548 |
|
int i; |
552 |
|
error(SYSTEM, errmsg); |
553 |
|
} |
554 |
|
for (i = 0; mname[i]; i++) /* add each one */ |
555 |
< |
addmodifier(mname[i], outf, binv); |
555 |
> |
addmodifier(mname[i], outf, binv, bincnt); |
556 |
|
} |
557 |
|
|
558 |
|
/* put string to stderr */ |
652 |
|
break; |
653 |
|
} |
654 |
|
fputc('\n', fout); |
655 |
+ |
} |
656 |
+ |
|
657 |
+ |
/* write resolution string to given output stream */ |
658 |
+ |
void |
659 |
+ |
printresolu(FILE *fout) |
660 |
+ |
{ |
661 |
|
if (xres > 0) { |
662 |
|
if (yres > 0) /* resolution string */ |
663 |
|
fprtresolu(xres, yres, fout); |
665 |
|
} |
666 |
|
} |
667 |
|
|
668 |
< |
/* Get output file pointer (open and write header if new) */ |
669 |
< |
FILE * |
670 |
< |
getofile(const char *ospec, const char *mname, int bn) |
668 |
> |
/* Get output stream pointer (open and write header if new and noopen==0) */ |
669 |
> |
STREAMOUT * |
670 |
> |
getostream(const char *ospec, const char *mname, int bn, int noopen) |
671 |
|
{ |
672 |
< |
int ofl; |
673 |
< |
char oname[1024]; |
674 |
< |
LUENT *lep; |
672 |
> |
static STREAMOUT stdos; |
673 |
> |
int ofl; |
674 |
> |
char oname[1024]; |
675 |
> |
LUENT *lep; |
676 |
> |
STREAMOUT *sop; |
677 |
|
|
678 |
|
if (ospec == NULL) { /* use stdout? */ |
679 |
< |
if (!using_stdout) { |
679 |
> |
if (!noopen && !using_stdout) { |
680 |
> |
stdos.reclen = 0; |
681 |
|
if (outfmt != 'a') |
682 |
|
SET_FILE_BINARY(stdout); |
683 |
|
if (header) |
684 |
|
printheader(stdout, NULL); |
685 |
+ |
printresolu(stdout); |
686 |
+ |
using_stdout = 1; |
687 |
|
} |
688 |
< |
using_stdout = 1; |
689 |
< |
return stdout; |
688 |
> |
stdos.ofp = stdout; |
689 |
> |
stdos.reclen += noopen; |
690 |
> |
return &stdos; |
691 |
|
} |
692 |
|
ofl = ofname(oname, ospec, mname, bn); /* get output name */ |
693 |
|
if (ofl < 0) { |
697 |
|
lep = lu_find(&ofiletab, oname); /* look it up */ |
698 |
|
if (lep->key == NULL) /* new entry */ |
699 |
|
lep->key = strcpy((char *)malloc(strlen(oname)+1), oname); |
700 |
< |
if (lep->data == NULL) { /* open output file */ |
701 |
< |
FILE *fp; |
700 |
> |
sop = (STREAMOUT *)lep->data; |
701 |
> |
if (sop == NULL) { /* allocate stream */ |
702 |
> |
sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); |
703 |
> |
if (sop == NULL) |
704 |
> |
error(SYSTEM, "out of memory in getostream"); |
705 |
> |
sop->reclen = oname[0] == '!' ? CNT_PIPE : 0; |
706 |
> |
sop->ofp = NULL; /* open iff noopen==0 */ |
707 |
> |
lep->data = (char *)sop; |
708 |
> |
} |
709 |
> |
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
710 |
|
int i; |
711 |
|
if (oname[0] == '!') /* output to command */ |
712 |
< |
fp = popen(oname+1, "w"); |
712 |
> |
sop->ofp = popen(oname+1, "w"); |
713 |
|
else |
714 |
< |
fp = fopen(oname, "w"); |
715 |
< |
if (fp == NULL) { |
714 |
> |
sop->ofp = fopen(oname, "w"); |
715 |
> |
if (sop->ofp == NULL) { |
716 |
|
sprintf(errmsg, "cannot open '%s' for writing", oname); |
717 |
|
error(SYSTEM, errmsg); |
718 |
|
} |
719 |
|
if (outfmt != 'a') |
720 |
< |
SET_FILE_BINARY(fp); |
720 |
> |
SET_FILE_BINARY(sop->ofp); |
721 |
|
if (header) { |
722 |
|
char info[512]; |
723 |
|
char *cp = info; |
724 |
< |
sprintf(cp, "MODIFIER=%s\n", mname); |
725 |
< |
while (*cp) ++cp; |
724 |
> |
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
725 |
> |
sprintf(cp, "MODIFIER=%s\n", mname); |
726 |
> |
while (*cp) ++cp; |
727 |
> |
} |
728 |
|
if (ofl & OF_BIN) { |
729 |
|
sprintf(cp, "BIN=%d\n", bn); |
730 |
|
while (*cp) ++cp; |
731 |
|
} |
732 |
|
*cp = '\0'; |
733 |
< |
printheader(fp, info); |
733 |
> |
printheader(sop->ofp, info); |
734 |
|
} |
735 |
+ |
printresolu(sop->ofp); |
736 |
|
/* play catch-up */ |
737 |
|
for (i = 0; i < lastdone; i++) { |
738 |
|
static const DCOLOR nocontrib = BLKCOLOR; |
739 |
< |
put_contrib(nocontrib, fp); |
739 |
> |
put_contrib(nocontrib, sop->ofp); |
740 |
|
if (outfmt == 'a') |
741 |
< |
putc('\n', fp); |
741 |
> |
putc('\n', sop->ofp); |
742 |
|
} |
743 |
|
if (xres > 0) |
744 |
< |
fflush(fp); |
668 |
< |
lep->data = (char *)fp; |
744 |
> |
fflush(sop->ofp); |
745 |
|
} |
746 |
< |
return (FILE *)lep->data; /* return open file pointer */ |
746 |
> |
if (sop->reclen != CNT_PIPE) /* add to length if noopen */ |
747 |
> |
sop->reclen += noopen; |
748 |
> |
return sop; /* return open stream */ |
749 |
|
} |
750 |
|
|
751 |
|
/* read input ray into buffer */ |
808 |
|
bn = (int)(evalue(mp->binv) + .5); |
809 |
|
if (bn <= 0) |
810 |
|
bn = 0; |
811 |
< |
else if (bn >= mp->nbins) { /* new bin */ |
812 |
< |
mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + |
735 |
< |
bn*sizeof(DCOLOR)); |
736 |
< |
if (mp == NULL) |
737 |
< |
error(SYSTEM, "out of memory in add_contrib"); |
738 |
< |
memset(mp->cbin+mp->nbins, 0, sizeof(DCOLOR)*(bn+1-mp->nbins)); |
739 |
< |
mp->nbins = bn+1; |
740 |
< |
le->data = (char *)mp; |
741 |
< |
} |
811 |
> |
else if (bn >= mp->nbins) /* new bin */ |
812 |
> |
le->data = (char *)(mp = growmodifier(mp, bn+1)); |
813 |
|
addcolor(mp->cbin[bn], rparams); |
814 |
|
} |
815 |
|
|
817 |
|
static int |
818 |
|
puteol(const LUENT *e, void *p) |
819 |
|
{ |
820 |
< |
FILE *fp = (FILE *)e->data; |
820 |
> |
STREAMOUT *sop = (STREAMOUT *)e->data; |
821 |
|
|
822 |
|
if (outfmt == 'a') |
823 |
< |
putc('\n', fp); |
823 |
> |
putc('\n', sop->ofp); |
824 |
|
if (!waitflush) |
825 |
< |
fflush(fp); |
826 |
< |
if (ferror(fp)) { |
825 |
> |
fflush(sop->ofp); |
826 |
> |
if (ferror(sop->ofp)) { |
827 |
|
sprintf(errmsg, "write error on file '%s'", e->key); |
828 |
|
error(SYSTEM, errmsg); |
829 |
|
} |
863 |
|
void |
864 |
|
done_contrib(void) |
865 |
|
{ |
866 |
< |
int i, j; |
867 |
< |
MODCONT *mp; |
868 |
< |
FILE *fp; |
866 |
> |
int i, j; |
867 |
> |
MODCONT *mp; |
868 |
> |
STREAMOUT *sop; |
869 |
|
/* output modifiers in order */ |
870 |
|
for (i = 0; i < nmods; i++) { |
871 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |
872 |
< |
fp = getofile(mp->outspec, mp->modname, 0); |
873 |
< |
put_contrib(mp->cbin[0], fp); |
872 |
> |
sop = getostream(mp->outspec, mp->modname, 0,0); |
873 |
> |
put_contrib(mp->cbin[0], sop->ofp); |
874 |
|
if (mp->nbins > 3 && /* minor optimization */ |
875 |
< |
fp == getofile(mp->outspec, mp->modname, 1)) |
875 |
> |
sop == getostream(mp->outspec, mp->modname, 1,0)) |
876 |
|
for (j = 1; j < mp->nbins; j++) |
877 |
< |
put_contrib(mp->cbin[j], fp); |
877 |
> |
put_contrib(mp->cbin[j], sop->ofp); |
878 |
|
else |
879 |
|
for (j = 1; j < mp->nbins; j++) |
880 |
|
put_contrib(mp->cbin[j], |
881 |
< |
getofile(mp->outspec, mp->modname, j)); |
881 |
> |
getostream(mp->outspec,mp->modname,j,0)->ofp); |
882 |
|
/* clear for next ray tree */ |
883 |
|
memset(mp->cbin, 0, sizeof(DCOLOR)*mp->nbins); |
884 |
|
} |
1065 |
|
static int |
1066 |
|
myseeko(const LUENT *e, void *p) |
1067 |
|
{ |
1068 |
< |
if (fseeko((FILE *)e->data, *(off_t *)p, SEEK_CUR) < 0) { |
1068 |
> |
STREAMOUT *sop = (STREAMOUT *)e->data; |
1069 |
> |
off_t nbytes = *(off_t *)p; |
1070 |
> |
|
1071 |
> |
if (sop->reclen > 1) |
1072 |
> |
nbytes = nbytes * sop->reclen; |
1073 |
> |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
1074 |
|
sprintf(errmsg, "seek error on file '%s'", e->key); |
1075 |
|
error(SYSTEM, errmsg); |
1076 |
|
} |
1080 |
|
void |
1081 |
|
recover_output(FILE *fin) |
1082 |
|
{ |
1083 |
< |
off_t lastout = -1; |
1084 |
< |
int outvsiz; |
1085 |
< |
char *outvfmt; |
1086 |
< |
int i, j; |
1087 |
< |
MODCONT *mp; |
1088 |
< |
int ofl; |
1089 |
< |
char oname[1024]; |
1090 |
< |
LUENT *ment, *oent; |
1091 |
< |
FILE *fp; |
1092 |
< |
off_t nvals; |
1083 |
> |
off_t lastout = -1; |
1084 |
> |
int outvsiz, recsiz; |
1085 |
> |
char *outvfmt; |
1086 |
> |
int i, j; |
1087 |
> |
MODCONT *mp; |
1088 |
> |
int ofl; |
1089 |
> |
char oname[1024]; |
1090 |
> |
LUENT *ment, *oent; |
1091 |
> |
STREAMOUT sout; |
1092 |
> |
off_t nvals; |
1093 |
> |
int xr, yr; |
1094 |
|
|
1095 |
|
switch (outfmt) { |
1096 |
|
case 'a': |
1118 |
|
mp = (MODCONT *)ment->data; |
1119 |
|
if (mp->outspec == NULL) |
1120 |
|
error(USER, "cannot recover from stdout"); |
1121 |
+ |
if (mp->outspec[0] == '!') |
1122 |
+ |
error(USER, "cannot recover from command"); |
1123 |
|
for (j = 0; ; j++) { /* check each bin's file */ |
1124 |
|
ofl = ofname(oname, mp->outspec, mp->modname, j); |
1125 |
|
if (ofl < 0) |
1126 |
|
error(USER, "bad output file specification"); |
1127 |
|
oent = lu_find(&ofiletab, oname); |
1128 |
< |
if (oent->data != NULL) { /* saw this one already */ |
1128 |
> |
if (oent->data != NULL) { |
1129 |
> |
sout = *(STREAMOUT *)oent->data; |
1130 |
> |
} else { |
1131 |
> |
sout.reclen = 0; |
1132 |
> |
sout.ofp = NULL; |
1133 |
> |
} |
1134 |
> |
if (sout.ofp != NULL) { /* already open? */ |
1135 |
|
if (ofl & OF_BIN) |
1136 |
|
continue; |
1137 |
|
break; |
1138 |
|
} |
1054 |
– |
if (oname[0] == '!') |
1055 |
– |
error(USER, "cannot recover from command"); |
1139 |
|
/* open output */ |
1140 |
< |
fp = fopen(oname, "rb+"); |
1141 |
< |
if (fp == NULL) { |
1140 |
> |
sout.ofp = fopen(oname, "rb+"); |
1141 |
> |
if (sout.ofp == NULL) { |
1142 |
|
if (j) |
1143 |
|
break; /* assume end of modifier */ |
1144 |
|
sprintf(errmsg, "missing recover file '%s'", |
1145 |
|
oname); |
1146 |
|
error(USER, errmsg); |
1147 |
|
} |
1148 |
< |
nvals = lseek(fileno(fp), 0, SEEK_END); |
1148 |
> |
nvals = lseek(fileno(sout.ofp), 0, SEEK_END); |
1149 |
|
if (nvals <= 0) { |
1150 |
|
lastout = 0; /* empty output, quit here */ |
1151 |
< |
fclose(fp); |
1151 |
> |
fclose(sout.ofp); |
1152 |
|
break; |
1153 |
|
} |
1154 |
< |
lseek(fileno(fp), 0, SEEK_SET); |
1155 |
< |
if (header) { |
1073 |
< |
int xr, yr; |
1074 |
< |
if (checkheader(fp, outvfmt, NULL) != 1) { |
1154 |
> |
if (sout.reclen == CNT_UNKNOWN) { |
1155 |
> |
if (!(ofl & OF_BIN)) { |
1156 |
|
sprintf(errmsg, |
1157 |
< |
"format mismatch for '%s'", |
1157 |
> |
"need -bn to recover file '%s'", |
1158 |
|
oname); |
1159 |
|
error(USER, errmsg); |
1160 |
|
} |
1161 |
< |
if (xres > 0 && yres > 0 && |
1162 |
< |
(!fscnresolu(&xr, &yr, fp) || |
1163 |
< |
xr != xres || |
1164 |
< |
yr != yres)) { |
1165 |
< |
sprintf(errmsg, |
1166 |
< |
"resolution mismatch for '%s'", |
1167 |
< |
oname); |
1168 |
< |
error(USER, errmsg); |
1169 |
< |
} |
1161 |
> |
recsiz = outvsiz; |
1162 |
> |
} else |
1163 |
> |
recsiz = outvsiz * sout.reclen; |
1164 |
> |
|
1165 |
> |
lseek(fileno(sout.ofp), 0, SEEK_SET); |
1166 |
> |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
1167 |
> |
sprintf(errmsg, "format mismatch for '%s'", |
1168 |
> |
oname); |
1169 |
> |
error(USER, errmsg); |
1170 |
|
} |
1171 |
< |
nvals = (nvals - (off_t)ftell(fp)) / outvsiz; |
1172 |
< |
if (lastout < 0 || nvals < lastout) |
1171 |
> |
if ((xres > 0) & (yres > 0) && |
1172 |
> |
(!fscnresolu(&xr, &yr, sout.ofp) || |
1173 |
> |
xr != xres || |
1174 |
> |
yr != yres)) { |
1175 |
> |
sprintf(errmsg, "resolution mismatch for '%s'", |
1176 |
> |
oname); |
1177 |
> |
error(USER, errmsg); |
1178 |
> |
} |
1179 |
> |
nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz; |
1180 |
> |
if ((lastout < 0) | (nvals < lastout)) |
1181 |
|
lastout = nvals; |
1182 |
< |
if (oent->key == NULL) /* new entry */ |
1182 |
> |
if (oent->key == NULL) /* new entry */ |
1183 |
|
oent->key = strcpy((char *) |
1184 |
|
malloc(strlen(oname)+1), oname); |
1185 |
< |
oent->data = (char *)fp; |
1185 |
> |
if (oent->data == NULL) |
1186 |
> |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
1187 |
> |
*(STREAMOUT *)oent->data = sout; |
1188 |
|
if (!(ofl & OF_BIN)) |
1189 |
|
break; /* no bin separation */ |
1190 |
|
} |
1193 |
|
lu_done(&ofiletab); /* reclose all outputs */ |
1194 |
|
return; |
1195 |
|
} |
1196 |
< |
if (j > mp->nbins) { /* preallocate modifier bins */ |
1197 |
< |
mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + |
1107 |
< |
(j-1)*sizeof(DCOLOR)); |
1108 |
< |
if (mp == NULL) |
1109 |
< |
error(SYSTEM, "out of memory in recover_output"); |
1110 |
< |
memset(mp->cbin, 0, sizeof(DCOLOR)*mp->nbins); |
1111 |
< |
mp->nbins = j; |
1112 |
< |
ment->data = (char *)mp; |
1113 |
< |
} |
1196 |
> |
if (j > mp->nbins) /* reallocate modifier bins */ |
1197 |
> |
ment->data = (char *)(mp = growmodifier(mp, j)); |
1198 |
|
} |
1199 |
|
if (lastout < 0) { |
1200 |
|
error(WARNING, "no output files to recover"); |