more rumors processing (trunk only)

This fix should work for both DLB and non-DLB without forcing binary
mode for the latter.  And it should continue to work even if we later
decide to force that mode (which I think we should do...).  Use actual
file positions to calculate the size of the true and false sections,
rather than counting the bytes of each rumor (that counting has been left
in place but it gets overridden now.)  Those two sizes will be bigger on
platforms which use CR+LF line ends and maintain dat/rumors as non-DLB
text file.  But due to the way that nethack uses the sizes, such size
differences don't matter.

     The branch variant shouldn't need any corresponding fix.  It uses
the counting method when the output is binary, where the accumulated
value is accurate, and the check end-of-file shortcut when using text,
which should not be affected by stdio converting CR+LF into \n for text
input and back to CR+LF again for text output.  (The original bug was due
to starting out with the EOF shortcut when input had CR+LF line ends, but
then writing less data due to binary output keeping just LF instead of
putting CR back.)
This commit is contained in:
nethack.rankin
2006-05-07 05:31:27 +00:00
parent 13944ab03b
commit a71d270a21

View File

@@ -392,6 +392,7 @@ do_rumors()
/* copy the true rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0) {
true_rumor_count++;
/*[if we forced binary output, this would be sufficient]*/
true_rumor_size += strlen(in_line); /* includes newline */
(void) fputs(xcrypt(in_line), tfp);
}
@@ -399,6 +400,13 @@ do_rumors()
false_rumor_offset = ftell(tfp);
Fclose(ifp); /* all done with rumors.tru */
/* the calculated value for true_rumor_count assumes that
a single-byte line terminator is in use; for platforms
which use two byte CR+LF, we need to override that value
[it's much simpler to do so unconditionally, rendering
the loop's accumulation above obsolete] */
true_rumor_size = false_rumor_offset - true_rumor_offset;
/* process rumors.fal */
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, ".fal");
@@ -417,6 +425,10 @@ do_rumors()
eof_offset = ftell(tfp);
Fclose(ifp); /* all done with rumors.fal */
/* as with true_rumor_count, override the accumulated value in
case stdio converts \n into two byte CR+LF during output */
false_rumor_size = eof_offset - false_rumor_offset;
/* get ready to transfer the contents of temp file to output file */
Sprintf(in_line, "rewind of \"%s\"", tempfile);
if (rewind(tfp) != 0) {