[comp.sources.games.bugs] MS-DOS patches for Scrabble

talvola@cory.Berkeley.EDU (Erik Talvola) (04/12/89)

 It has been brought to my attention that my patches to Scrabble to
allow it to run under MS-DOS were basically worthless.  To get the
diffs, I just ran "diff oldfile.c newfile.c" and piped the output
to files.  The diff program was the diff program supplied with
PiCnix, a collection of Unix utilities for DOS.  However, patch will
not handle the resulting diffs.  So, I moved everything over to Unix,
and used "diff -c" on the files, and combined all the patches into
one nice file.  Here is a new Shar file to replace the one I previously
posted:


------------CUT-HERE------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README.PC
#	Makefile.tcc
#	patch1
#	util.c
# This archive created: Tue Apr 11 20:52:50 1989
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'README.PC'" '(2473 characters)'
if test -f 'README.PC'
then
	echo shar: "will not over-write existing file 'README.PC'"
else
cat << \!Funky!Stuff! > 'README.PC'
FILES:

    README.PC		This file
    Makefile.tcc	A make file for Turbo-C and Opus Make

    patch1		A file for patch(1) to patch various files in
			the distribution Scrabble.

    util.c		Replacement for original util.c



  This is an initial attempt to get Wayne Christopher's Scrabble program
running under MS-DOS.  I initially attempted to use Microsoft C v5.1, but
soon ran into some strange bugs, which prompted me to switch over to Turbo-C.
After a little while, I was able to get the whole thing compiled and running
fine.  

  To compile, you will need Turbo-C, and Bjorn Larsson's PC-Curses package.
Bjorn's address is:

 ...mcvax!enea!infovax!bl 

  from the notes in the PC-Curses source files.  I used version v1.3 of the
code - earlier (or later) versions may also work.

  I have included a Makefile which seems to work fairly well.  I cheated in
creating the compilation command for scrabble.exe though - I use *.obj in
the command line, which will bomb if, for example, plural.obj is lying 
around.  Before you do a make, just delete any spurious obj's like this.
I used OpusMake from Opus Software, an excellent program - other make programs
may or may not work.

  Note that refresh.c from the original distribution is not needed on the
PC.  All the diff files should be applied to the original distributed
sources.  There is a new util.c file needed for MS-DOS, as the diffs to
the original Unix file were larger than the file itself.

  The only problem so far is that I can only get the program to read in a 
dictionary of about 88K or so, which may be sufficient, but I don't have a
good dictionary for DOS.  In testing, I just skipped about 3 out of every 4
words from the one I played with on Unix, and it loaded, but a lot of good
words were obviously deleted by using this random deletion.  Also, the Unix
dictionary has things like roman numerals, words such as "qs" (more than one
q), which aren't good Scrabble words.  If anyone gets a good DOS dictionary,
tell me.  Also, if you can up the limit that the program can read in, please
let me know as well.  I don't have much experience with far pointers, and may
have used them incorrectly.

  Anyway, I hope people can get some use out of this program.  It seems pretty
robust, and plays a decent game of Scrabble (even with the mutant wordlist).
Please let me know if anyone makes any improvements to the MS-DOS port.


	 Erik Talvola

	 talvola@cory.berkeley.edu
	 ...!ucbvax!cory!talvola
!Funky!Stuff!
fi  # end of overwriting check
echo shar: "extracting 'Makefile.tcc'" '(1858 characters)'
if test -f 'Makefile.tcc'
then
	echo shar: "will not over-write existing file 'Makefile.tcc'"
else
cat << \!Funky!Stuff! > 'Makefile.tcc'

# RCS Info: $Revision: 1.2 $ on $Date: 89/03/15 11:16:17 $
#           $Source: /yew3/faustus/src/scrabble/RCS/Makefile,v $
# Copyright (c) 1987 Wayne A. Christopher, U. C. Berkeley CAD Group
#
# Program Makefile
#
# This makefile has the standard options "clean", "require", and "install".
# Also available are "lint", "depend", "tags", "opt", "debug", and "prof".
# "opt" causes the program to be compiled optimized, "debug" with -g, and
# "prof" with -pg.  As an added bonus, the Makefile remembers the last of
# these options given.
#
# Heavily mutated to work with OpusMake, Turbo-C v1.5 (at least), and
# Bjorn Larsson's (...mcvax!enea!infovax!bl) PC-Curses package.
#
#   Erik Talvola
#   talvola@cory.berkeley.edu
#   ...!ucbvax!cory!talvola

what: all

#---- Tool specific stuff ----

PROGRAM = scrabble.exe

SRC	=		\
	board.c		\
	dict.c		\
	move.c		\
	player.c	\
	savegame.c	\
	scrabble.c	\
	tty.c		\
	user.c		\
	util.c 

OBJ	= board.obj dict.obj move.obj player.obj savegame.obj \
	scrabble.obj tty.obj user.obj util.obj 

HDR	=		\
	scrabble.h	\
	util.h

SUPPORT		=	plural

CC = tcc
MODEL = c
CFLAGS = -m$(MODEL) -I\turboc\include -G -O -Z -DMSDOS
LIBDIR = \turboc\lib

LIBS = $(LIBDIR)\$(MODEL)curses.lib
LDFLAGS = -L$(LIBDIR) -m$(MODEL)

#---- Generic stuff ----

# EXTDEFINES are things that come from a higher-level Makefile

all: date.h $(PROGRAM) $(SUPPORT).exe
	@echo "All done."

# the next rule isn't very good - before making scrabble.exe, delete
# plural.obj (and any others) if they exist.  I didn't bother writing
# a file to give to LINK, and the command line is too long to handle all
# the obj's directly.

$(PROGRAM): $(OBJ)
	$(CC) -e$(PROGRAM) $(LDFLAGS) *.obj $(LIBS)

$(SUPPORT).exe: $(SUPPORT).obj
	$(CC) -e$(SUPPORT) $(LDFLAGS) $(SUPPORT).obj $(LIBS)

!Funky!Stuff!
fi  # end of overwriting check
echo shar: "extracting 'patch1'" '(6289 characters)'
if test -f 'patch1'
then
	echo shar: "will not over-write existing file 'patch1'"
else
cat << \!Funky!Stuff! > 'patch1'
*** board.c	Fri Apr  7 16:26:08 1989
--- ../board.c	Tue Apr 11 21:45:36 1989
***************
*** 8,13 ****
--- 8,17 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #include <stdlib.h>
+ #endif
  #include "scrabble.h"
  
  static char *bonus_map[] = {
***************
*** 63,69 ****
--- 67,77 ----
  		}
  
  	for (i = POOL_SIZE - 1; i >= 0; i--) {
+ #ifdef MSDOS
+ 		j = rand() % (i + 1);
+ #else
  		j = random() % (i + 1);
+ #endif				
  		for (k = 0; j >= 0; j -= distrib[k++])
  			;
  		k--;
*** dict.c	Fri Apr  7 16:22:16 1989
--- ../dict.c	Tue Apr 11 21:45:54 1989
***************
*** 8,13 ****
--- 8,16 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #endif
  #include "scrabble.h"
  
  static int dicthash(char *word, int tabsize);
***************
*** 14,20 ****
--- 17,27 ----
  static void getem(word_t **wordp, char *lbuf, int place, char *opt,
  		int numopt, int len);
  
+ #ifdef MSDOS
+ static dict_t far *dictionary;
+ #else
  static dict_t *dictionary;
+ #endif
  
  void
  readdict(char *file)
***************
*** 31,37 ****
--- 38,48 ----
  	fprintf(stderr, "Reading \"%s\" ", file);
  	fflush(stderr);
  
+ #ifdef MSDOS
+ 	dictionary = (dict_t far *) util_farmalloc(sizeof (dict_t));
+ #else	
  	dictionary = (dict_t *) util_malloc(sizeof (dict_t));
+ #endif	
  	for (i = 0; i < MAX_LENGTH; i++)
  		for (j = 0; j < HASH_SIZE; j++)
  			dictionary->buckets[i][j] = NULL;
*** move.c	Fri Apr  7 16:22:26 1989
--- ../move.c	Tue Apr 11 21:46:01 1989
***************
*** 8,13 ****
--- 8,16 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #endif
  #include "scrabble.h"
  
  static void dopos(board_t *board, player_t *player, int x, int y,
*** player.c	Fri Apr  7 16:26:12 1989
--- ../player.c	Tue Apr 11 21:46:06 1989
***************
*** 8,13 ****
--- 8,16 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #endif
  #include "scrabble.h"
  
  player_t *
*** savegame.c	Fri Apr  7 16:26:28 1989
--- ../savegame.c	Tue Apr 11 21:46:09 1989
***************
*** 8,13 ****
--- 8,16 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #endif
  #include "scrabble.h"
  
  board_t *
*** scrabble.c	Fri Apr  7 16:25:52 1989
--- ../scrabble.c	Tue Apr 11 21:46:14 1989
***************
*** 8,13 ****
--- 8,17 ----
   *
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #include <stdlib.h>
+ #endif
  #include "scrabble.h"
  #include "date.h"
  #include <signal.h>
***************
*** 19,25 ****
--- 23,33 ----
  static bool domove(board_t *board, player_t **players, int which);
  static void sighandler();
  
+ #ifdef MSDOS
+ static char *dictfile = "dictionary";
+ #else
  static char *dictfile = DICT_FILE;
+ #endif
  
  int
  main(int ac, char **av)
***************
*** 40,46 ****
--- 48,58 ----
  	printf("Compiled %s by %s@%s\n\n", DATE, USER, HOST);
  	*/
  
+ #ifdef MSDOS
+ 	srand((unsigned int) time(0));
+ #else
  	srandom(time(0));
+ #endif		
  
  	for (i = 0; i < MAX_PLAYERS; i++)
  		machine[i] = false;
***************
*** 115,121 ****
--- 127,135 ----
  
  	user_init(DEV_TTY, board, players, numplayers);
  
+ #ifndef MSDOS
  	signal(SIGINT, sighandler);
+ #endif	
  
  	/* Now take turns. */
  	for (;;) {
*** scrabble.h	Fri Apr  7 16:25:56 1989
--- ../scrabble.h	Tue Apr 11 21:46:18 1989
***************
*** 25,31 ****
--- 25,35 ----
  #define DICT_FILE	"/usr/dict/words"
  #endif
  
+ #ifdef MSDOS
+ #define HASH_SIZE	1003
+ #else
  #define HASH_SIZE	5003
+ #endif
  #define MAX_LENGTH	15
  #define WILD		'*'
  #define ZIP		' '
*** tty.c	Fri Apr  7 16:26:00 1989
--- ../tty.c	Tue Apr 11 21:46:22 1989
***************
*** 8,16 ****
--- 8,21 ----
   *
   */
  
+ #ifdef MSDOS
+ #include <curses.h>
  #include "scrabble.h"
+ #else
+ #include "scrabble.h"
  #include <curses.h>
  #undef bool
+ #endif
  
  static WINDOW *boardwin, *scores, *summary, *dialog;
  #ifdef notdef
***************
*** 128,137 ****
  	messline = (messline + 1) % MESS_SIZE;
  	if (messline < MESS_SIZE - 1) {
  		wmove(dialog, messline + 1, 0);
! 		wclrtoeol(dialog);
  	}
  	wmove(dialog, messline, 0);
! 	wclrtoeol(dialog);
  	wprintw(dialog, "%s", message);
  
  	wrefresh(dialog);
--- 133,142 ----
  	messline = (messline + 1) % MESS_SIZE;
  	if (messline < MESS_SIZE - 1) {
  		wmove(dialog, messline + 1, 0);
! 		wclrtoeol(dialog); 
  	}
  	wmove(dialog, messline, 0);
! 	wclrtoeol(dialog); 
  	wprintw(dialog, "%s", message);
  
  	wrefresh(dialog);
***************
*** 310,316 ****
  			player->score);
  	for (i = 0; i < player->numworking; i++)
  		wprintw(scores, " %c", player->working[i]);
! 	wclrtoeol(scores);
  	wmove(scores, pos + 5, 0);
  	wrefresh(scores);
  
--- 315,321 ----
  			player->score);
  	for (i = 0; i < player->numworking; i++)
  		wprintw(scores, " %c", player->working[i]);
! 	wclrtoeol(scores); 
  	wmove(scores, pos + 5, 0);
  	wrefresh(scores);
  
*** user.c	Fri Apr  7 16:26:34 1989
--- ../user.c	Tue Apr 11 21:46:26 1989
***************
*** 10,15 ****
--- 10,18 ----
   * added to this file.
   */
  
+ #ifdef MSDOS
+ typedef char bool;
+ #endif
  #include "scrabble.h"
  
  struct device {
*** util.h	Fri Apr  7 16:26:50 1989
--- ../util.h	Tue Apr 11 21:46:29 1989
***************
*** 6,12 ****
   * Standard definitions.
   */
  
! #define UNIX
  #define BSD
  
  /* vcc has problems with math.h */
--- 6,13 ----
   * Standard definitions.
   */
  
! /* #define UNIX */
! #define MSDOS
  #define BSD
  
  /* vcc has problems with math.h */
***************
*** 40,46 ****
--- 41,49 ----
  		abort();\
  	}}
  
+ #ifdef UNIX
  typedef int bool;
+ #endif
  
  #define false 0
  #define true 1
***************
*** 71,79 ****
--- 74,87 ----
  extern char *strstr();
  extern char *util_datestring();
  extern char *util_malloc();
+ #ifdef MSDOS
+ extern char far *util_farmalloc();
+ #endif
  extern char *util_realloc();
  extern int util_seconds();
+ #ifdef UNIX
  extern char *util_tildexpand();
+ #endif
  
  /* Externs from libc */
  
***************
*** 82,93 ****
--- 90,105 ----
  extern int errno;
  extern char *sys_errlist[];
  extern double atof();
+ #ifdef UNIX
  extern long random();
  extern void srandom();
+ #endif
  extern long time();
  extern void exit();
  extern void bcopy();
+ #ifdef UNIX
  extern char *sbrk();
+ #endif
  extern char *getlogin();
  extern void free();
  extern void perror();
!Funky!Stuff!
fi  # end of overwriting check
echo shar: "extracting 'util.c'" '(1651 characters)'
if test -f 'util.c'
then
	echo shar: "will not over-write existing file 'util.c'"
else
cat << \!Funky!Stuff! > 'util.c'

/* RCS Info: $Revision: 1.1 $ on $Date: 89/03/10 10:11:10 $
 *           $Source: /yew3/faustus/src/scrabble/RCS/util.c,v $
 * Copyright (c) 1988 Wayne A. Christopher, U. C. Berkeley CAD Group 
 *	 faustus@cad.berkeley.edu, ucbvax!faustus
 * Permission is granted to modify and re-distribute this code in any manner
 * as long as this notice is preserved.  All standard disclaimers apply.
 *
 */

#include "util.h"
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <alloc.h>

char *
strsav(str)
	char *str;
{
	char *p;
	
	p = malloc(strlen(str) + 1);
	if (p)
		strcpy(p, str);
	return (p);
}

char *
util_datestring()
{
	time_t t;
	struct tm *tp;
	static char tbuf[40];
	char *ap;
	int i;
	
	t = time((time_t *) NULL);
	tp = localtime(&t);
	ap = asctime(tp);
	sprintf(tbuf, "%.20s", ap);
	strcat(tbuf, ap + 19);
	i = strlen(tbuf);
	tbuf[i - 1] = '\0';
	return (tbuf);
}

char *
util_malloc(num)
	int num;
{
	char *s;

	s = malloc((unsigned) num);
	if (!s) {
		fprintf(stderr, "malloc: can't allocate %d bytes", num);
		exit(1);
	}
	(void) memset(s, 0, num);
	return (s);
}

char far *
util_farmalloc(num)
	unsigned long num;
{
	char far *s;
	char far *t;

	s = (char far *) farmalloc(num);
	if (!s) {
		fprintf(stderr, "malloc: can't allocate %d bytes", num);
		exit(1);
	}
	for (t = s; t < s + num; t++) {
	  *t = 0;
	}
	return (s);
}

char *
util_realloc(ptr, num)
	char *ptr;
	int num;
{
	char *s;

	s = realloc(ptr, (unsigned) num);
	if (!s) {
		fprintf(stderr, "realloc: can't allocate %d bytes", num);
		exit(1);
	}
	return (s);
}

!Funky!Stuff!
fi  # end of overwriting check
exit 0
#	End of shell archive
--
Erik Talvola               | "It's just what we need... a colossal negative 
talvola@cory.berkeley.edu  | space wedgie of great power coming right at us
..!ucbvax!cory!talvola    | at warp speed." -- Star Drek