| 63 |
|
closestream(void *p) |
| 64 |
|
{ |
| 65 |
|
STREAMOUT *sop = (STREAMOUT *)p; |
| 66 |
+ |
int status; |
| 67 |
|
if (sop->reclen == CNT_PIPE) |
| 68 |
< |
pclose(sop->ofp); |
| 68 |
> |
status = pclose(sop->ofp); |
| 69 |
|
else |
| 70 |
< |
fclose(sop->ofp); |
| 70 |
> |
status = fclose(sop->ofp); |
| 71 |
> |
if (status) |
| 72 |
> |
error(SYSTEM, "error closing output stream"); |
| 73 |
|
free(p); |
| 74 |
|
} |
| 75 |
|
|
| 78 |
|
#define OF_MODIFIER 01 |
| 79 |
|
#define OF_BIN 02 |
| 80 |
|
|
| 81 |
< |
STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int bincnt); |
| 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); |
| 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"); |
| 520 |
– |
lep->data = (char *)mp; |
| 524 |
|
mp->outspec = outf; /* XXX assumes static string */ |
| 525 |
|
mp->modname = modn; /* XXX assumes static string */ |
| 526 |
|
if (binv != NULL) |
| 533 |
|
bincnt = 1; |
| 534 |
|
else if (bincnt > 1) |
| 535 |
|
mp = growmodifier(mp, bincnt); |
| 536 |
< |
if (bincnt > 0) /* allocate output stream */ |
| 537 |
< |
getostream(mp->outspec, mp->modname, 0, 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 |
|
|
| 665 |
|
} |
| 666 |
|
} |
| 667 |
|
|
| 668 |
< |
/* Get output stream pointer (open and write header if new and bincnt==0) */ |
| 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 bincnt) |
| 670 |
> |
getostream(const char *ospec, const char *mname, int bn, int noopen) |
| 671 |
|
{ |
| 672 |
|
static STREAMOUT stdos; |
| 673 |
|
int ofl; |
| 676 |
|
STREAMOUT *sop; |
| 677 |
|
|
| 678 |
|
if (ospec == NULL) { /* use stdout? */ |
| 679 |
< |
if (!bincnt && !using_stdout) { |
| 679 |
> |
if (!noopen && !using_stdout) { |
| 680 |
|
stdos.reclen = 0; |
| 681 |
|
if (outfmt != 'a') |
| 682 |
|
SET_FILE_BINARY(stdout); |
| 686 |
|
using_stdout = 1; |
| 687 |
|
} |
| 688 |
|
stdos.ofp = stdout; |
| 689 |
< |
stdos.reclen += bincnt; |
| 689 |
> |
stdos.reclen += noopen; |
| 690 |
|
return &stdos; |
| 691 |
|
} |
| 692 |
|
ofl = ofname(oname, ospec, mname, bn); /* get output name */ |
| 699 |
|
lep->key = strcpy((char *)malloc(strlen(oname)+1), oname); |
| 700 |
|
sop = (STREAMOUT *)lep->data; |
| 701 |
|
if (sop == NULL) { /* allocate stream */ |
| 697 |
– |
if (ofl & OF_BIN && bincnt > 1) /* don't overcount bins */ |
| 698 |
– |
bincnt = 1; |
| 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 bincnt==0 */ |
| 706 |
> |
sop->ofp = NULL; /* open iff noopen==0 */ |
| 707 |
|
lep->data = (char *)sop; |
| 708 |
|
} |
| 709 |
< |
if (!bincnt && sop->ofp == NULL) { /* open output stream */ |
| 709 |
> |
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
| 710 |
|
int i; |
| 711 |
|
if (oname[0] == '!') /* output to command */ |
| 712 |
|
sop->ofp = popen(oname+1, "w"); |
| 721 |
|
if (header) { |
| 722 |
|
char info[512]; |
| 723 |
|
char *cp = info; |
| 724 |
< |
if (ofl & OF_MODIFIER) { |
| 724 |
> |
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
| 725 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
| 726 |
|
while (*cp) ++cp; |
| 727 |
|
} |
| 743 |
|
if (xres > 0) |
| 744 |
|
fflush(sop->ofp); |
| 745 |
|
} |
| 746 |
< |
if (sop->reclen != CNT_PIPE) /* add bincnt to count */ |
| 747 |
< |
sop->reclen += bincnt; |
| 746 |
> |
if (sop->reclen != CNT_PIPE) /* add to length if noopen */ |
| 747 |
> |
sop->reclen += noopen; |
| 748 |
|
return sop; /* return open stream */ |
| 749 |
|
} |
| 750 |
|
|
| 1151 |
|
fclose(sout.ofp); |
| 1152 |
|
break; |
| 1153 |
|
} |
| 1154 |
< |
if (!sout.reclen) { /* unspecified record length */ |
| 1154 |
> |
if (sout.reclen == CNT_UNKNOWN) { |
| 1155 |
|
if (!(ofl & OF_BIN)) { |
| 1156 |
|
sprintf(errmsg, |
| 1157 |
< |
"guessing 1 value per record in '%s'", |
| 1157 |
> |
"need -bn to recover file '%s'", |
| 1158 |
|
oname); |
| 1159 |
< |
error(WARNING, errmsg); |
| 1159 |
> |
error(USER, errmsg); |
| 1160 |
|
} |
| 1161 |
|
recsiz = outvsiz; |
| 1162 |
|
} else |