75 |
|
#define OF_MODIFIER 01 |
76 |
|
#define OF_BIN 02 |
77 |
|
|
78 |
< |
STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int bincnt); |
78 |
> |
STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int noopen); |
79 |
|
int ofname(char *oname, const char *ospec, const char *mname, int bn); |
80 |
|
void printheader(FILE *fout, const char *info); |
81 |
|
void printresolu(FILE *fout); |
505 |
|
{ |
506 |
|
LUENT *lep = lu_find(&modconttab, modn); |
507 |
|
MODCONT *mp; |
508 |
+ |
int i; |
509 |
|
|
510 |
|
if (lep->data != NULL) { |
511 |
|
sprintf(errmsg, "duplicate modifier '%s'", modn); |
518 |
|
mp = (MODCONT *)malloc(sizeof(MODCONT)); |
519 |
|
if (mp == NULL) |
520 |
|
error(SYSTEM, "out of memory in addmodifier"); |
520 |
– |
lep->data = (char *)mp; |
521 |
|
mp->outspec = outf; /* XXX assumes static string */ |
522 |
|
mp->modname = modn; /* XXX assumes static string */ |
523 |
|
if (binv != NULL) |
530 |
|
bincnt = 1; |
531 |
|
else if (bincnt > 1) |
532 |
|
mp = growmodifier(mp, bincnt); |
533 |
< |
if (bincnt > 0) /* allocate output stream */ |
534 |
< |
getostream(mp->outspec, mp->modname, 0, bincnt); |
533 |
> |
lep->data = (char *)mp; |
534 |
> |
/* allocate output streams */ |
535 |
> |
for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i--; ) |
536 |
> |
getostream(mp->outspec, mp->modname, i, 1); |
537 |
|
return mp; |
538 |
|
} |
539 |
|
|
662 |
|
} |
663 |
|
} |
664 |
|
|
665 |
< |
/* Get output stream pointer (open and write header if new and bincnt==0) */ |
665 |
> |
/* Get output stream pointer (open and write header if new and noopen==0) */ |
666 |
|
STREAMOUT * |
667 |
< |
getostream(const char *ospec, const char *mname, int bn, int bincnt) |
667 |
> |
getostream(const char *ospec, const char *mname, int bn, int noopen) |
668 |
|
{ |
669 |
|
static STREAMOUT stdos; |
670 |
|
int ofl; |
673 |
|
STREAMOUT *sop; |
674 |
|
|
675 |
|
if (ospec == NULL) { /* use stdout? */ |
676 |
< |
if (!bincnt && !using_stdout) { |
676 |
> |
if (!noopen && !using_stdout) { |
677 |
|
stdos.reclen = 0; |
678 |
|
if (outfmt != 'a') |
679 |
|
SET_FILE_BINARY(stdout); |
683 |
|
using_stdout = 1; |
684 |
|
} |
685 |
|
stdos.ofp = stdout; |
686 |
< |
stdos.reclen += bincnt; |
686 |
> |
stdos.reclen += noopen; |
687 |
|
return &stdos; |
688 |
|
} |
689 |
|
ofl = ofname(oname, ospec, mname, bn); /* get output name */ |
696 |
|
lep->key = strcpy((char *)malloc(strlen(oname)+1), oname); |
697 |
|
sop = (STREAMOUT *)lep->data; |
698 |
|
if (sop == NULL) { /* allocate stream */ |
697 |
– |
if (ofl & OF_BIN && bincnt > 1) /* don't overcount bins */ |
698 |
– |
bincnt = 1; |
699 |
|
sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); |
700 |
|
if (sop == NULL) |
701 |
|
error(SYSTEM, "out of memory in getostream"); |
702 |
|
sop->reclen = oname[0] == '!' ? CNT_PIPE : 0; |
703 |
< |
sop->ofp = NULL; /* open iff bincnt==0 */ |
703 |
> |
sop->ofp = NULL; /* open iff noopen==0 */ |
704 |
|
lep->data = (char *)sop; |
705 |
|
} |
706 |
< |
if (!bincnt && sop->ofp == NULL) { /* open output stream */ |
706 |
> |
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
707 |
|
int i; |
708 |
|
if (oname[0] == '!') /* output to command */ |
709 |
|
sop->ofp = popen(oname+1, "w"); |
718 |
|
if (header) { |
719 |
|
char info[512]; |
720 |
|
char *cp = info; |
721 |
< |
if (ofl & OF_MODIFIER) { |
721 |
> |
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
722 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
723 |
|
while (*cp) ++cp; |
724 |
|
} |
740 |
|
if (xres > 0) |
741 |
|
fflush(sop->ofp); |
742 |
|
} |
743 |
< |
if (sop->reclen != CNT_PIPE) /* add bincnt to count */ |
744 |
< |
sop->reclen += bincnt; |
743 |
> |
if (sop->reclen != CNT_PIPE) /* add to length if noopen */ |
744 |
> |
sop->reclen += noopen; |
745 |
|
return sop; /* return open stream */ |
746 |
|
} |
747 |
|
|
1148 |
|
fclose(sout.ofp); |
1149 |
|
break; |
1150 |
|
} |
1151 |
< |
if (!sout.reclen) { /* unspecified record length */ |
1151 |
> |
if (sout.reclen == CNT_UNKNOWN) { |
1152 |
|
if (!(ofl & OF_BIN)) { |
1153 |
|
sprintf(errmsg, |
1154 |
< |
"guessing 1 value per record in '%s'", |
1154 |
> |
"need -bn to recover file '%s'", |
1155 |
|
oname); |
1156 |
< |
error(WARNING, errmsg); |
1156 |
> |
error(USER, errmsg); |
1157 |
|
} |
1158 |
|
recsiz = outvsiz; |
1159 |
|
} else |