[comp.sources.games.bugs] patches to shuffle

jik@athena.mit.edu (Jonathan I. Kamens) (11/27/89)

  The following patches to the files game.c and main.c in the sources
to shuffle (v08i071) recently posted to comp.sources.games fix three
problems, one quite minor, the other two a bit less minor:

1. In game.c, there was an unnecessary variable and assignment, which
   was making my compiler complain (we have a very picky compiler :-),
   although it would not affect the operation of the program.  By
   itself, I wouldn't bother to post this patch, but since I've
   already got other bugs that needs to be patched, there's no harm to
   including this patch with them.

2. In game.c and in main.c, the terminal is not reset correctly before
   exiting.  I've created a new Exit function which resets the
   terminal and then exits, and I've changed everything that used to
   exit with exit() (or just by falling through the end of main()) to
   use Exit() instead.  BTW, it's probably a bad idea to use exit()
   without an exit value -- it'll just try to pull the value off of
   the stack, and god knows what value it'll end up with.

3. In main.c, the return value of getopt() is treated as a char, and
   then compared to EOF.  It is NOT a char, it is an int, and some
   systems do NOT have signed chars, so this would fail.  On my
   particular system, the tip-off was when my compiler reported
   "result of comparison never varies" on the line with the getopt
   call.  The fix is to make the variable an int rather than a char.

  The shar file below should be unshar'd to get a file called
"shuffle.patch", and then applied to the sources to shuffle using the
"patch" program.

  NOTE: This is NOT an official patch, it's just a few small fixes
that I found necessary.  I have forwarded a copy of this message to
the author (of course), and if he chooses to make it an official
patch, he can do so, or he can explain why my fixes are wrong :-)

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

		      *************************

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  shuffle.patch
# Wrapped by jik@pit-manager on Sun Nov 26 16:31:09 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'shuffle.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shuffle.patch'\"
else
echo shar: Extracting \"'shuffle.patch'\" \(2497 characters\)
sed "s/^X//" >'shuffle.patch' <<'END_OF_FILE'
X*** /tmp/,RCSt1003241	Sun Nov 26 16:27:41 1989
X--- game.c	Sun Nov 26 16:21:19 1989
X***************
X*** 92,99 ****
X  end_game(cntr,lvl)	/* gives a next level if you did it ok, and     */
X  int cntr,lvl;		/* stops it if you did it in to many turns	*/
X  {
X-   char x;
X- 
X    move(20,2);
X    if(cntr<=test_level(lvl))
X    {
X--- 92,97 ----
X***************
X*** 103,109 ****
X      refresh();
X      move(20,2);
X      clrtoeol();
X!     while((x=getch()) !=' ');
X    }
X    else
X    {
X--- 101,107 ----
X      refresh();
X      move(20,2);
X      clrtoeol();
X!     while(getch() !=' ');
X    }
X    else
X    {
X***************
X*** 110,115 ****
X      printw("You did it in %d switches and",cntr);
X      printw(" it could be done in %d switches.\n\n",lvl*FAC1);    
X      refresh();
X!     exit();
X    }
X  }
X--- 108,113 ----
X      printw("You did it in %d switches and",cntr);
X      printw(" it could be done in %d switches.\n\n",lvl*FAC1);    
X      refresh();
X!     Exit(0);
X    }
X  }
X*** /tmp/,RCSt1003241	Sun Nov 26 16:27:43 1989
X--- main.c	Sun Nov 26 16:21:10 1989
X***************
X*** 24,30 ****
X  char **argv,*optstring;
X  {
X   int row[9], t, level;
X!  char c;
X  extern char *optarg;
X  extern int optind,opterr;
X  
X--- 24,30 ----
X  char **argv,*optstring;
X  {
X   int row[9], t, level;
X!  int c;
X  extern char *optarg;
X  extern int optind,opterr;
X  
X***************
X*** 44,50 ****
X      fprintf(stderr, "Usage: %s [-] [-L level]\n", argv[0]);
X      fprintf(stderr, "\t- - give this summary of usage\n");
X      fprintf(stderr, "\tL [level] - start at [level] of difficulty\n");
X!     exit(0);
X    }
X  
X  	/* process the arguments to the program */
X--- 44,50 ----
X      fprintf(stderr, "Usage: %s [-] [-L level]\n", argv[0]);
X      fprintf(stderr, "\t- - give this summary of usage\n");
X      fprintf(stderr, "\tL [level] - start at [level] of difficulty\n");
X!     Exit(0);
X    }
X  
X  	/* process the arguments to the program */
X***************
X*** 61,73 ****
X      default:
X       fprintf(stderr, "Unknown flag or improper usage:\n");
X       fprintf(stderr, "\tuse '%s -' for usage\n", argv[0]);
X!     exit(1);
X      }
X    }
X  
X    game(row,level);
X!   resetty();
X!   endwin();
X  }
X  
X  
X--- 61,82 ----
X      default:
X       fprintf(stderr, "Unknown flag or improper usage:\n");
X       fprintf(stderr, "\tuse '%s -' for usage\n", argv[0]);
X!     Exit(1);
X      }
X    }
X  
X    game(row,level);
X! 
X!   Exit(0);
X! }
X! 
X! 
X! int Exit(val)
X! int val;
X! {
X!      resetty();
X!      endwin();
X!      exit(val);
X  }
X  
X  
END_OF_FILE
if test 2497 -ne `wc -c <'shuffle.patch'`; then
    echo shar: \"'shuffle.patch'\" unpacked with wrong size!
fi
# end of 'shuffle.patch'
fi
echo shar: End of shell archive.
exit 0