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 |
|
|
123 |
|
int outfmt = 'a'; /* output format */ |
124 |
|
|
125 |
|
int header = 1; /* output header? */ |
126 |
+ |
int force_open = 0; /* truncate existing output? */ |
127 |
|
int xres = 0; /* horiz. output resolution */ |
128 |
|
int yres = 0; /* vert. output resolution */ |
129 |
|
|
267 |
|
continue; |
268 |
|
} |
269 |
|
break; |
270 |
< |
case 'f': /* file or i/o format */ |
270 |
> |
case 'f': /* file or force or format */ |
271 |
|
if (!argv[i][2]) { |
272 |
|
char *fpath; |
273 |
|
if (i >= argc-2) break; |
282 |
|
fcompile(fpath); |
283 |
|
continue; |
284 |
|
} |
285 |
+ |
if (argv[i][2] == 'o') { |
286 |
+ |
force_open++; |
287 |
+ |
continue; |
288 |
+ |
} |
289 |
|
setformat(argv[i]+2); |
290 |
|
continue; |
291 |
|
case 'e': /* expression */ |
707 |
|
sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); |
708 |
|
if (sop == NULL) |
709 |
|
error(SYSTEM, "out of memory in getostream"); |
710 |
< |
sop->reclen = oname[0] == '!' ? CNT_PIPE : 0; |
710 |
> |
sop->reclen = oname[0] == '!' ? CNT_PIPE : CNT_UNKNOWN; |
711 |
|
sop->ofp = NULL; /* open iff noopen==0 */ |
712 |
|
lep->data = (char *)sop; |
713 |
|
} |
714 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
715 |
< |
int i; |
715 |
> |
long i; |
716 |
|
if (oname[0] == '!') /* output to command */ |
717 |
|
sop->ofp = popen(oname+1, "w"); |
718 |
< |
else |
718 |
> |
else if (!force_open && access(oname, F_OK) == 0) |
719 |
> |
errno = EEXIST; /* file exists */ |
720 |
> |
else /* else open it */ |
721 |
|
sop->ofp = fopen(oname, "w"); |
722 |
|
if (sop->ofp == NULL) { |
723 |
|
sprintf(errmsg, "cannot open '%s' for writing", oname); |
741 |
|
} |
742 |
|
printresolu(sop->ofp); |
743 |
|
/* play catch-up */ |
744 |
< |
for (i = 0; i < lastdone; i++) { |
744 |
> |
for (i = sop->reclen > 1 ? sop->reclen*lastdone : lastdone; |
745 |
> |
i--; ) { |
746 |
|
static const DCOLOR nocontrib = BLKCOLOR; |
747 |
|
put_contrib(nocontrib, sop->ofp); |
748 |
|
if (outfmt == 'a') |
1050 |
|
/* loop over input */ |
1051 |
|
while ((iblen = getinp(inpbuf, fin)) > 0) { |
1052 |
|
if (lastray+1 < lastray || /* need reset? */ |
1053 |
< |
queue_length() > 5*nrtprocs()) { |
1053 |
> |
queue_length() > 10*nrtprocs()) { |
1054 |
|
while (wait_rproc() != NULL) |
1055 |
|
process_queue(); |
1056 |
< |
lastdone = lastray = 0; |
1056 |
> |
if (lastray+1 < lastray) |
1057 |
> |
lastdone = lastray = 0; |
1058 |
|
} |
1059 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
1060 |
|
rtp->raynum = ++lastray; /* assign ray to it */ |
1137 |
|
if (oent->data != NULL) { |
1138 |
|
sout = *(STREAMOUT *)oent->data; |
1139 |
|
} else { |
1140 |
< |
sout.reclen = 0; |
1140 |
> |
sout.reclen = CNT_UNKNOWN; |
1141 |
|
sout.ofp = NULL; |
1142 |
|
} |
1143 |
|
if (sout.ofp != NULL) { /* already open? */ |