| 116 |
|
fputs("NCOMP=3\n", fout); /* always RGB */ |
| 117 |
|
if (info != NULL) /* add extra info if given */ |
| 118 |
|
fputs(info, fout); |
| 119 |
+ |
if ((outfmt == 'f') | (outfmt == 'd')) |
| 120 |
+ |
fputendian(fout); |
| 121 |
|
fputformat(formstr(outfmt), fout); |
| 122 |
|
fputc('\n', fout); /* empty line ends header */ |
| 123 |
|
} |
| 143 |
|
LUENT *lep; |
| 144 |
|
STREAMOUT *sop; |
| 145 |
|
char *cp; |
| 146 |
< |
|
| 146 |
> |
|
| 147 |
> |
info[0] = '\0'; |
| 148 |
|
if (ospec == NULL) { /* use stdout? */ |
| 149 |
|
if (!noopen & !using_stdout) { |
| 150 |
|
if (outfmt != 'a') |
| 151 |
|
SET_FILE_BINARY(stdout); |
| 152 |
+ |
#ifdef getc_unlocked |
| 153 |
+ |
flockfile(stdout); /* avoid lock/unlock overhead */ |
| 154 |
+ |
#endif |
| 155 |
|
if (header) { |
| 156 |
|
cp = info; |
| 157 |
|
if (yres > 0) { |
| 168 |
|
if (waitflush > 0) |
| 169 |
|
fflush(stdout); |
| 170 |
|
stdos.xr = xres; stdos.yr = yres; |
| 165 |
– |
#ifdef getc_unlocked |
| 166 |
– |
flockfile(stdout); /* avoid lock/unlock overhead */ |
| 167 |
– |
#endif |
| 171 |
|
using_stdout = 1; |
| 172 |
|
} |
| 173 |
|
stdos.ofp = stdout; |
| 448 |
|
char *outvfmt; |
| 449 |
|
LUENT *oent; |
| 450 |
|
int xr, yr; |
| 451 |
< |
STREAMOUT sout; |
| 451 |
> |
STREAMOUT *sop; |
| 452 |
|
DCOLOR rgbv; |
| 453 |
|
|
| 454 |
|
if (outfmt == 'a') |
| 461 |
|
error(USER, "cannot reload from stdout"); |
| 462 |
|
if (mp->outspec[0] == '!') |
| 463 |
|
error(USER, "cannot reload from command"); |
| 464 |
< |
for (j = 0; ; j++) { /* load each modifier bin */ |
| 465 |
< |
ofl = ofname(oname, mp->outspec, mp->modname, j); |
| 464 |
> |
for (j = 0; j < mp->nbins; j++) { /* load each modifier bin */ |
| 465 |
> |
ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j); |
| 466 |
|
if (ofl < 0) |
| 467 |
|
error(USER, "bad output file specification"); |
| 468 |
|
oent = lu_find(&ofiletab, oname); |
| 469 |
< |
if (oent->data != NULL) { |
| 470 |
< |
sout = *(STREAMOUT *)oent->data; |
| 471 |
< |
} else { |
| 472 |
< |
sout.reclen = 0; |
| 473 |
< |
sout.outpipe = 0; |
| 474 |
< |
sout.xr = xres; sout.yr = yres; |
| 472 |
< |
sout.ofp = NULL; |
| 473 |
< |
} |
| 474 |
< |
if (sout.ofp == NULL) { /* open output as input */ |
| 475 |
< |
sout.ofp = fopen(oname, fmode); |
| 476 |
< |
if (sout.ofp == NULL) { |
| 477 |
< |
if (j == mp->nbins) |
| 478 |
< |
break; /* assume end of modifier */ |
| 469 |
> |
if (oent->data == NULL) |
| 470 |
> |
error(INTERNAL, "unallocated stream in reload_output()"); |
| 471 |
> |
sop = (STREAMOUT *)oent->data; |
| 472 |
> |
if (sop->ofp == NULL) { /* open output as input */ |
| 473 |
> |
sop->ofp = fopen(oname, fmode); |
| 474 |
> |
if (sop->ofp == NULL) { |
| 475 |
|
sprintf(errmsg, "missing reload file '%s'", |
| 476 |
|
oname); |
| 477 |
|
error(WARNING, errmsg); |
| 478 |
|
break; |
| 479 |
|
} |
| 480 |
|
#ifdef getc_unlocked |
| 481 |
< |
flockfile(sout.ofp); |
| 481 |
> |
flockfile(sop->ofp); |
| 482 |
|
#endif |
| 483 |
< |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
| 483 |
> |
if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) { |
| 484 |
|
sprintf(errmsg, "format mismatch for '%s'", |
| 485 |
|
oname); |
| 486 |
|
error(USER, errmsg); |
| 487 |
|
} |
| 488 |
< |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
| 489 |
< |
(!fscnresolu(&xr, &yr, sout.ofp) || |
| 490 |
< |
(xr != sout.xr) | |
| 491 |
< |
(yr != sout.yr))) { |
| 488 |
> |
if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) && |
| 489 |
> |
(!fscnresolu(&xr, &yr, sop->ofp) || |
| 490 |
> |
(xr != sop->xr) | |
| 491 |
> |
(yr != sop->yr))) { |
| 492 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
| 493 |
|
oname); |
| 494 |
|
error(USER, errmsg); |
| 495 |
|
} |
| 496 |
|
} |
| 497 |
|
/* read in RGB value */ |
| 498 |
< |
if (!get_contrib(rgbv, sout.ofp)) { |
| 498 |
> |
if (!get_contrib(rgbv, sop->ofp)) { |
| 499 |
|
if (!j) { |
| 500 |
< |
fclose(sout.ofp); |
| 500 |
> |
fclose(sop->ofp); |
| 501 |
|
break; /* ignore empty file */ |
| 502 |
|
} |
| 503 |
|
if (j < mp->nbins) { |
| 506 |
|
error(USER, errmsg); |
| 507 |
|
} |
| 508 |
|
break; |
| 509 |
< |
} |
| 514 |
< |
if (j >= mp->nbins) { /* check modifier size */ |
| 515 |
< |
sprintf(errmsg, |
| 516 |
< |
"mismatched -bn setting for reloading '%s'", |
| 517 |
< |
modname[i]); |
| 518 |
< |
error(USER, errmsg); |
| 519 |
< |
} |
| 520 |
< |
|
| 509 |
> |
} |
| 510 |
|
copycolor(mp->cbin[j], rgbv); |
| 522 |
– |
if (oent->key == NULL) /* new file entry */ |
| 523 |
– |
oent->key = strcpy((char *) |
| 524 |
– |
malloc(strlen(oname)+1), oname); |
| 525 |
– |
if (oent->data == NULL) |
| 526 |
– |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
| 527 |
– |
*(STREAMOUT *)oent->data = sout; |
| 511 |
|
} |
| 512 |
|
} |
| 513 |
|
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
| 522 |
|
off_t nbytes = *(off_t *)p; |
| 523 |
|
|
| 524 |
|
if (sop->reclen > 1) |
| 525 |
< |
nbytes = nbytes * sop->reclen; |
| 525 |
> |
nbytes *= (off_t)sop->reclen; |
| 526 |
|
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
| 527 |
|
sprintf(errmsg, "seek error on file '%s'", e->key); |
| 528 |
|
error(SYSTEM, errmsg); |
| 543 |
|
int ofl; |
| 544 |
|
char oname[1024]; |
| 545 |
|
LUENT *oent; |
| 546 |
< |
STREAMOUT sout; |
| 546 |
> |
STREAMOUT *sop; |
| 547 |
|
off_t nvals; |
| 548 |
|
int xr, yr; |
| 549 |
|
|
| 572 |
|
error(USER, "cannot recover from stdout"); |
| 573 |
|
if (mp->outspec[0] == '!') |
| 574 |
|
error(USER, "cannot recover from command"); |
| 575 |
< |
for (j = 0; ; j++) { /* check each bin's file */ |
| 576 |
< |
ofl = ofname(oname, mp->outspec, mp->modname, j); |
| 575 |
> |
for (j = 0; j < mp->nbins; j++) { /* check each bin's file */ |
| 576 |
> |
ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j); |
| 577 |
|
if (ofl < 0) |
| 578 |
|
error(USER, "bad output file specification"); |
| 579 |
|
oent = lu_find(&ofiletab, oname); |
| 580 |
< |
if (oent->data != NULL) { |
| 581 |
< |
sout = *(STREAMOUT *)oent->data; |
| 582 |
< |
} else { |
| 583 |
< |
sout.reclen = 0; |
| 601 |
< |
sout.outpipe = 0; |
| 602 |
< |
sout.xr = xres; |
| 603 |
< |
sout.yr = yres; |
| 604 |
< |
sout.ofp = NULL; |
| 605 |
< |
} |
| 606 |
< |
if (sout.ofp != NULL) { /* already open? */ |
| 580 |
> |
if (oent->data == NULL) |
| 581 |
> |
error(INTERNAL, "unallocated stream in recover_output()"); |
| 582 |
> |
sop = (STREAMOUT *)oent->data; |
| 583 |
> |
if (sop->ofp != NULL) { /* already open? */ |
| 584 |
|
if (ofl & OF_BIN) |
| 585 |
|
continue; |
| 586 |
|
break; |
| 587 |
|
} |
| 588 |
|
/* open output */ |
| 589 |
< |
sout.ofp = fopen(oname, "rb+"); |
| 590 |
< |
if (sout.ofp == NULL) { |
| 614 |
< |
if (j == mp->nbins) |
| 615 |
< |
break; /* assume end of modifier */ |
| 589 |
> |
sop->ofp = fopen(oname, "rb+"); |
| 590 |
> |
if (sop->ofp == NULL) { |
| 591 |
|
sprintf(errmsg, "missing recover file '%s'", |
| 592 |
|
oname); |
| 593 |
|
error(WARNING, errmsg); |
| 594 |
+ |
lastout = 0; |
| 595 |
|
break; |
| 596 |
|
} |
| 597 |
< |
nvals = lseek(fileno(sout.ofp), 0, SEEK_END); |
| 597 |
> |
nvals = lseek(fileno(sop->ofp), 0, SEEK_END); |
| 598 |
|
if (nvals <= 0) { |
| 599 |
|
lastout = 0; /* empty output, quit here */ |
| 600 |
< |
fclose(sout.ofp); |
| 600 |
> |
fclose(sop->ofp); |
| 601 |
|
break; |
| 602 |
|
} |
| 603 |
< |
if (!sout.reclen) { |
| 628 |
< |
if (!(ofl & OF_BIN)) { |
| 629 |
< |
sprintf(errmsg, |
| 630 |
< |
"need -bn to recover file '%s'", |
| 631 |
< |
oname); |
| 632 |
< |
error(USER, errmsg); |
| 633 |
< |
} |
| 634 |
< |
recsiz = outvsiz; |
| 635 |
< |
} else |
| 636 |
< |
recsiz = outvsiz * sout.reclen; |
| 603 |
> |
recsiz = outvsiz * sop->reclen; |
| 604 |
|
|
| 605 |
< |
lseek(fileno(sout.ofp), 0, SEEK_SET); |
| 606 |
< |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
| 605 |
> |
lseek(fileno(sop->ofp), 0, SEEK_SET); |
| 606 |
> |
if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) { |
| 607 |
|
sprintf(errmsg, "format mismatch for '%s'", |
| 608 |
|
oname); |
| 609 |
|
error(USER, errmsg); |
| 610 |
|
} |
| 611 |
< |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
| 612 |
< |
(!fscnresolu(&xr, &yr, sout.ofp) || |
| 613 |
< |
(xr != sout.xr) | |
| 614 |
< |
(yr != sout.yr))) { |
| 611 |
> |
if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) && |
| 612 |
> |
(!fscnresolu(&xr, &yr, sop->ofp) || |
| 613 |
> |
(xr != sop->xr) | |
| 614 |
> |
(yr != sop->yr))) { |
| 615 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
| 616 |
|
oname); |
| 617 |
|
error(USER, errmsg); |
| 618 |
|
} |
| 619 |
< |
nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz; |
| 619 |
> |
nvals = (nvals - (off_t)ftell(sop->ofp)) / recsiz; |
| 620 |
|
if ((lastout < 0) | (nvals < lastout)) |
| 621 |
|
lastout = nvals; |
| 655 |
– |
if (oent->key == NULL) /* new entry */ |
| 656 |
– |
oent->key = strcpy((char *) |
| 657 |
– |
malloc(strlen(oname)+1), oname); |
| 658 |
– |
if (oent->data == NULL) |
| 659 |
– |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
| 660 |
– |
*(STREAMOUT *)oent->data = sout; |
| 622 |
|
if (!(ofl & OF_BIN)) |
| 623 |
|
break; /* no bin separation */ |
| 624 |
|
} |
| 625 |
|
if (!lastout) { /* empty output */ |
| 626 |
|
error(WARNING, "no previous data to recover"); |
| 627 |
< |
lu_done(&ofiletab); /* reclose all outputs */ |
| 627 |
> |
/* reclose all outputs */ |
| 628 |
> |
lu_doall(&ofiletab, &myclose, NULL); |
| 629 |
|
return; |
| 668 |
– |
} |
| 669 |
– |
if (j > mp->nbins) { /* check modifier size */ |
| 670 |
– |
sprintf(errmsg, |
| 671 |
– |
"mismatched -bn setting for recovering '%s'", |
| 672 |
– |
modname[i]); |
| 673 |
– |
error(USER, errmsg); |
| 630 |
|
} |
| 631 |
|
} |
| 632 |
|
if (lastout < 0) { |