more thorough rumor processing (trunk only)

To fix the gibberish rumor observed by at least a couple of players on
Windows (where if rumors.tru had <cr><lf> line ends and DLB was defined,
makedefs built a file that caused nethack to end up in the wrong place when
it reached EOF and tried to jump back to the first false rumor), change
the way that makedefs builds the rumors file.  It now will collect more
information about the true and false rumors.  Instead of one hex value on
the second line, there are nine values (three groups of three).

1,2,3;4,5,6;7,8,9

1 = number of true rumors; not previously collected and not currently used
2 = size in bytes for all true rumors (in decimal, as is #1)
3 = offset to first true rumor (in hexadecimal; not previously collected)
4,5,6 = same as 1,2,3 but for the false rumors section
7,8 = always 0 (imaginary third section has no entries, no size)
9 = offset to end-of-file (could be used for sanity checks; currently isn't)

Adding #2 with #3 yields #6; adding #5 with #6 yields #9.  The old format's
lone entry was the same as the new format's #6.  #2, #3, and #5 are values
which nethack was previously calculating on the fly after opening the file.

     This also extends rumor_check() a little bit (displays the last rumor
for both sections in addition to the first), but I think it can probably
now be demoted to ``#if 0'' and removed from the extended commands list.
This commit is contained in:
nethack.rankin
2006-05-06 04:55:57 +00:00
parent 43690db0bc
commit 85865eb106
2 changed files with 128 additions and 69 deletions
+80 -54
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)makedefs.c 3.5 2005/01/04 */
/* SCCS Id: @(#)makedefs.c 3.5 2006/05/05 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* Copyright (c) M. Stephenson, 1990, 1991. */
/* Copyright (c) Dean Luick, 1990. */
@@ -347,84 +347,110 @@ const char *str;
void
do_rumors()
{
char infile[60];
long true_rumor_size;
static const char rumors_header[] =
"%s%04d,%06ld,%06lx;%04d,%06ld,%06lx;0,0,%06lx\n";
char infile[60], tempfile[60];
int true_rumor_count, false_rumor_count;
long true_rumor_size, false_rumor_size,
true_rumor_offset, false_rumor_offset, eof_offset;
Sprintf(tempfile, DATA_TEMPLATE, "rumors.tmp");
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename,file_prefix);
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, RUMOR_FILE);
if (!(ofp = fopen(filename,
#ifdef WIN32
WRBMODE
#else
WRTMODE
#endif
))) {
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,Dont_Edit_Data);
if (!(tfp = fopen(tempfile, WRTMODE))) {
perror(tempfile);
Fclose(ofp);
exit(EXIT_FAILURE);
}
true_rumor_count = false_rumor_count = 0;
true_rumor_size = false_rumor_size = 0L;
true_rumor_offset = false_rumor_offset = eof_offset = 0L;
/* output a dummy header record; we'll replace it in final output */
Fprintf(tfp, rumors_header, Dont_Edit_Data,
true_rumor_count, true_rumor_size, true_rumor_offset,
false_rumor_count, false_rumor_size, false_rumor_offset,
eof_offset);
/* record the current position; true rumors will start here */
true_rumor_offset = ftell(tfp);
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, ".tru");
if (!(ifp = fopen(infile,
#ifdef WIN32
RDBMODE
#else
RDTMODE
#endif
))) {
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
Fclose(ofp);
Unlink(filename); /* kill empty output file */
exit(EXIT_FAILURE);
goto rumors_failure;
}
/* get size of true rumors file */
#ifndef VMS
(void) fseek(ifp, 0L, SEEK_END);
true_rumor_size = ftell(ifp);
#else
/* seek+tell is only valid for stream format files; since rumors.%%%
might be in record format, count the actual data bytes instead.
*/
true_rumor_size = 0;
while (fgets(in_line, sizeof in_line, ifp) != 0)
/* copy the true rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0) {
true_rumor_count++;
true_rumor_size += strlen(in_line); /* includes newline */
#endif /* VMS */
Fprintf(ofp,"%06lx\n", true_rumor_size);
(void) fseek(ifp, 0L, SEEK_SET);
/* copy true rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0)
(void) fputs(xcrypt(in_line), ofp);
Fclose(ifp);
(void) fputs(xcrypt(in_line), tfp);
}
/* record the current position; false rumors will start here */
false_rumor_offset = ftell(tfp);
Fclose(ifp); /* all done with rumors.tru */
/* process rumors.fal */
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, ".fal");
if (!(ifp = fopen(infile,
#ifdef WIN32
RDBMODE
#else
RDTMODE
#endif
))) {
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
Fclose(ofp);
Unlink(filename); /* kill incomplete output file */
exit(EXIT_FAILURE);
goto rumors_failure;
}
/* copy false rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0)
(void) fputs(xcrypt(in_line), ofp);
while (fgets(in_line, sizeof in_line, ifp) != 0) {
false_rumor_count++;
false_rumor_size += strlen(in_line); /* includes newline */
(void) fputs(xcrypt(in_line), tfp);
}
/* record the current position; EOF available for sanity check */
eof_offset = ftell(tfp);
Fclose(ifp); /* all done with rumors.fal */
Fclose(ifp);
/* get ready to transfer the contents of temp file to output file */
Sprintf(in_line, "rewind of \"%s\"", tempfile);
if (rewind(tfp) != 0) {
perror(in_line);
goto rumors_failure;
}
/* output the header record */
Fprintf(ofp, rumors_header, Dont_Edit_Data,
true_rumor_count, true_rumor_size, true_rumor_offset,
false_rumor_count, false_rumor_size, false_rumor_offset,
eof_offset);
/* skip the temp file's dummy header */
if (!fgets(in_line, sizeof in_line, tfp) || /* "Don't Edit" */
!fgets(in_line, sizeof in_line, tfp)) { /* count,size,offset */
perror(tempfile);
goto rumors_failure;
}
/* copy the rest of the temp file into the final output file */
while (fgets(in_line, sizeof in_line, tfp) != 0) {
(void) fputs(in_line, ofp);
}
/* all done; delete temp file */
Fclose(tfp);
Unlink(tempfile);
Fclose(ofp);
return;
rumors_failure:
Fclose(ofp);
Unlink(filename); /* kill empty or incomplete output file */
Fclose(tfp);
Unlink(tempfile); /* and temporary file */
exit(EXIT_FAILURE);
}
/*