Output the Result Lines
Write the results to the output file.
Notes
The write_bytes() routine is used for two different functions.
It's most common use is to generate the output from a sort operation.
It is also (coincidentally?) used when copying bytes during
overwrite protection support.
The failure to include 'putc(eolchar, ofp)' in the
write_bytes routine is due to a curious re-use of the capability.
During overwrite protection, write_bytes is used to create a
copy of each potentially overwritten file.
It means that the putc() call is included in-line
with every call to write_bytes() used for writting results.
It also means that the putc() calls are not error-checked.
(Admittedly, failure on a single character output after a
large line write is exceedingly rare.)
- Define default end of line character (eolchar)
- Constant definition
- Notes
-
While other concerns transform the eolchar to a variable,
the OutputRslt concern knows that it is a constant.
- Segment Source
-
73: /* The character marking end of line. Default to \n. */
74: int eolchar = '\n';
75:
- Output lines in merge
-
Code insertion
- Output generated by merge operation.
Segment Element
-
1359: write_bytes (saved.text, saved.length, ofp);
1360: putc (eolchar, ofp);
Segment Element
-
1391: write_bytes (lines[ord[0]].lines[cur[ord[0]]].text,
1392: lines[ord[0]].lines[cur[ord[0]]].length, ofp);
1393: putc (eolchar, ofp);
Segment Element
-
1445: write_bytes (saved.text, saved.length, ofp);
1446: putc (eolchar, ofp);
- Output lines in sort
-
Code insertion
- Output generated by sort operation.
- Segment Source
-
1598: write_bytes (lines.lines[i].text, lines.lines[i].length, tfp);
1599: putc (eolchar, tfp);
- Manage output file specification
-
Output generated by sort operation.
Segment Element
Variable declaration
- 1723: FILE *ofp;
Segment Element
Code insertion
- 2123: ofp = stdout;
Segment Element
Code insertion
-
2131: /* If we wait for the implicit flush on exit, and the parent process
2132: has closed stdout (e.g., exec >&- in a shell), then the output file
2133: winds up empty. I don't understand why. This is under SunOS,
2134: Solaris, Ultrix, and Irix. This premature fflush makes the output
2135: reappear. --karl@cs.umb.edu */
2136: if (fflush (ofp) < 0)
2137: error (SORT_FAILURE, errno, _("%s: write error"), outfile);
2138:
Segment Element
Code insertion
-
2139: if (have_read_stdin && fclose (stdin) == EOF)
2140: error (SORT_FAILURE, errno, outfile);
2141: if (ferror (stdout) || fclose (stdout) == EOF)
2142: error (SORT_FAILURE, errno, _("%s: write error"), outfile);
2143: