]> granicus.if.org Git - nethack/commitdiff
Pad rumors to improve distribution of delivered rumors.
authorkeni <keni>
Thu, 12 Oct 2006 00:17:17 +0000 (00:17 +0000)
committerkeni <keni>
Thu, 12 Oct 2006 00:17:17 +0000 (00:17 +0000)
doc/fixes35.0
src/rumors.c
util/makedefs.c

index bc4dac53dd617ce58b705dccd68bea7e4c6afcaf..497058b1fee249690581b9e4a44726d0512599b5 100644 (file)
@@ -163,6 +163,7 @@ bugles affect all monsters to some extent
 nurses are affected if player is polymorphed as a cockatrice
 getting a particular rotten food result can't make attempting to eat a
        corpse of one of the Riders be survivable
+pad rumors to improve distribution of delivered rumors
 
 
 Platform- and/or Interface-Specific Fixes
index 5d37b75d887127eb11d4fc0203831467793494ff..dd47a6e57e0ad7c5a6b942d51df14b79b19b6808 100644 (file)
@@ -149,6 +149,19 @@ boolean exclude_cookie;
                pline("Can't open rumors file!");
                true_rumor_size = -1;   /* don't try to open it again */
        }
+/* this is safe either way, so do it always since we can't get the definition
+ * out of makedefs.c
+ */
+#define PAD_RUMORS_TO
+#ifdef PAD_RUMORS_TO
+       /* remove padding */
+       {
+           char *x = eos(rumor_buf) - 1;
+           while(x > rumor_buf && *x=='_') x--;
+           *++x = '\n';
+           *x = '\0';
+       }
+#endif
        return rumor_buf;
 }
 
index 4afda5f8e732ea4ace67b00335c2b100afe963d2..fd860fb2d5b57408a520e2830a7c014ec71c4ede 100644 (file)
@@ -132,7 +132,7 @@ static char xclear[MAX_ROW][MAX_COL];
 #endif
 /*-end of vision defs-*/
 
-static char    in_line[256], filename[60];
+static char    in_line[256], filename[600];
 
 #ifdef FILE_PREFIX
                /* if defined, a first argument not starting with - is
@@ -344,12 +344,65 @@ const char *str;
        return buf;
 }
 
+#define PAD_RUMORS_TO 60
+/* common code for do_rumors().  Return 0 on error. */
+static long
+read_rumors_file(
+    const char *file_ext,
+    int *rumor_count,
+    long *rumor_size,
+    long old_rumor_offset
+){
+    char infile[600];
+    long rumor_offset;
+    Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
+    Strcat(infile, file_ext);
+    if (!(ifp = fopen(infile, RDTMODE))) {
+       perror(infile);
+       return 0;
+    }
+
+    /* copy the rumors */
+    while (fgets(in_line, sizeof in_line, ifp) != 0) {
+#ifdef PAD_RUMORS_TO
+       int len = strlen(in_line);
+       if(len <= PAD_RUMORS_TO){       /* XXX enforce min len? */
+           char *base = index(in_line, '\n');
+           while(len++<PAD_RUMORS_TO){
+               *base++ = '_';  /* XXX */
+           }
+           *base++ = '\n';
+           *base = '\0';
+       }
+#endif
+               
+               (*rumor_count)++;
+#if 0
+       /*[if we forced binary output, this would be sufficient]*/
+       *rumor_size += strlen(in_line); /* includes newline */
+#endif
+       (void) fputs(xcrypt(in_line), tfp);
+    }
+    /* record the current position; next rumors section will start here */
+    rumor_offset = ftell(tfp);
+    Fclose(ifp);               /* all done with rumors.file_ext */
+
+    /* the calculated value for *_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] */
+
+    *rumor_size = rumor_offset - old_rumor_offset;
+    return rumor_offset;
+}
+
 void
 do_rumors()
 {
        static const char rumors_header[] =
                        "%s%04d,%06ld,%06lx;%04d,%06ld,%06lx;0,0,%06lx\n";
-       char    infile[60], tempfile[60];
+       char    tempfile[600];
        int     true_rumor_count, false_rumor_count;
        long    true_rumor_size, false_rumor_size,
                true_rumor_offset, false_rumor_offset, eof_offset;
@@ -382,52 +435,15 @@ do_rumors()
        /* 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, RDTMODE))) {
-               perror(infile);
-               goto rumors_failure;
-       }
-
-       /* 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);
-       }
-       /* record the current position; false rumors will start here */
-       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");
-       if (!(ifp = fopen(infile, RDTMODE))) {
-               perror(infile);
-               goto rumors_failure;
-       }
-
-       /* copy false rumors */
-       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 */
+       false_rumor_offset = read_rumors_file(
+               ".tru", &true_rumor_count,
+               &true_rumor_size, true_rumor_offset);
+       if(!false_rumor_offset) goto rumors_failure;
 
-       /* 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;
+       eof_offset = read_rumors_file(
+               ".fal", &false_rumor_count,
+               &false_rumor_size, false_rumor_offset);
+       if(!eof_offset) goto rumors_failure;
 
        /* get ready to transfer the contents of temp file to output file */
        Sprintf(in_line, "rewind of \"%s\"", tempfile);