[net.sources.bugs] A bug fix for histplot.c in Rogomatic XIV

play@turing.UUCP (02/05/85)

Installing rogomatic & player worked beautifully at our site;
a few hours after installation rogomatic had 5 places in the top ten list.

I had, however, all kinds of minor problems with the auxiliary files
and binaries. These are badly or incorrectly documented, and do not work.

The shell script rfile contains an explicit pathname that should be edited.

The README says that histplot reads the scorefile and produces a histogram.
In fact, histplot reads stdin and produces a core dump.

The file rgmscore5.3 (used by e.g. rfile) is produced only by running
"rogomatic -s". I havent seen this documented.

Anyway, below a few corrections (diff -c) to histplot.c
	(In short: the culprit was a missing & in a call to sscanf;
	this caused the core dump. The arguments to stlmatch were in
	the wrong order; this caused incorrect output. Added a few
	sanity checks.)
Now "rogomatic -s | histplot" works as intended.

*** original/histplot.c	Mon Feb  4 22:58:46 1985
--- histplot.c	Mon Feb  4 23:27:13 1985
***************
*** 65,86
      else       { if ((h = BUCKET(score)) >= NUMBUK) h = NUMBUK-1; }
  
      bucket[h]++;
-     
-     if (stlmatch (killer, "arrow"))			killnum = 1;
-     else if (stlmatch (killer, "black unicorn"))	killnum = 'u'-'a'+2;
-     else if (stlmatch (killer, "bolt"))			killnum = 1;
-     else if (stlmatch (killer, "dart"))			killnum = 1;
-     else if (stlmatch (killer, "fatal error trap"))	killnum = 0;
-     else if (stlmatch (killer, "floating eye"))		killnum = 'e'-'a'+2;
-     else if (stlmatch (killer, "gave"))			killnum = 0;
-     else if (stlmatch (killer, "giant ant"))		killnum = 'a'-'a'+2;
-     else if (stlmatch (killer, "hypothermia"))		killnum = 'i'-'a'+2;
-     else if (stlmatch (killer, "quit"))			killnum = 28;
-     else if (stlmatch (killer, "starvation"))		killnum = 'e'-'a'+2;
-     else if (stlmatch (killer, "user"))			killnum = 0;
-     else if (stlmatch (killer, "venus flytrap"))	killnum = 'f'-'a'+2;
-     else if (stlmatch (killer, "violet fungi"))		killnum = 'f'-'a'+2;
-     else killnum = *killer - 'a' + 2;
  
      killed[h][killnum]++;
          

--- 65,70 -----
      else       { if ((h = BUCKET(score)) >= NUMBUK) h = NUMBUK-1; }
  
      bucket[h]++;
  
      /* switched args to stlmatch below - aeb */
      if (stlmatch ("arrow", killer))			killnum = 1;
***************
*** 82,87
      else if (stlmatch (killer, "violet fungi"))		killnum = 'f'-'a'+2;
      else killnum = *killer - 'a' + 2;
  
      killed[h][killnum]++;
          
      if (bucket[h] > maxfreq) maxfreq = bucket[h];

--- 66,91 -----
  
      bucket[h]++;
  
+     /* switched args to stlmatch below - aeb */
+     if (stlmatch ("arrow", killer))			killnum = 1;
+     else if (stlmatch ("black unicorn", killer))	killnum = 'u'-'a'+2;
+     else if (stlmatch ("bolt", killer))			killnum = 1;
+     else if (stlmatch ("dart", killer))			killnum = 1;
+     else if (stlmatch ("fatal error trap", killer))	killnum = 0;
+     else if (stlmatch ("floating eye", killer))		killnum = 'e'-'a'+2;
+     else if (stlmatch ("gave", killer))			killnum = 0;
+     else if (stlmatch ("giant ant", killer))		killnum = 'a'-'a'+2;
+     else if (stlmatch ("hypothermia", killer))		killnum = 'i'-'a'+2;
+     else if (stlmatch ("quit", killer))			killnum = 28;
+     else if (stlmatch ("starvation", killer))		killnum = 'e'-'a'+2;
+     else if (stlmatch ("user", killer))			killnum = 0;
+     else if (stlmatch ("venus flytrap", killer))	killnum = 'f'-'a'+2;
+     else if (stlmatch ("violet fungi", killer))		killnum = 'f'-'a'+2;
+     else {
+ 	killnum = *killer - 'a' + 2;
+ 	if(killnum < 0 || killnum >= NOMON) killnum = 0;	/* aeb */
+     }
+ 
      killed[h][killnum]++;
          
      if (bucket[h] > maxfreq) maxfreq = bucket[h];
***************
*** 158,164
    while (fgets (line, 128, stdin))
    { dd = yy = *score = 0;
      sscanf (line, "%s %d, %d %10s%d%c%17s",
!             mmstr, &dd, &yy, player, score, cheated, killer);
      if (strlen (line) > LEVELPOS) *level = atoi (line+LEVELPOS);
      if (yy > 0 &&
          (cheated != '*' || cheat) &&

--- 162,168 -----
    while (fgets (line, 128, stdin))
    { dd = yy = *score = 0;
      sscanf (line, "%s %d, %d %10s%d%c%17s",
!             mmstr, &dd, &yy, player, score, &cheated, killer);     /* aeb */
      if (strlen (line) > LEVELPOS) *level = atoi (line+LEVELPOS);
      if (yy > 0 &&
          (cheated != '*' || cheat) &&