[comp.sources.games] v06i071: connect4 - connect four opponent

games@tekred.CNA.TEK.COM (05/02/89)

Submitted-by: Tim Ramsey <tar@ksuvax1.cis.ksu.edu>
Posting-number: Volume 6, Issue 71
Archive-name: connect4.pch1

[[Here's the patches for Connect 4 to get it to compile under SysV Rel3.1.
If you find any bugs in the patches please let me know.
	Tim]]

#! /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:  c4.c.diff screen.c.diff
# Wrapped by tar@ksuvax1.cis.ksu.edu on Thu Apr 27 23:09:45 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f c4.c.diff -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"c4.c.diff\"
else
echo shar: Extracting \"c4.c.diff\" \(4222 characters\)
sed "s/^X//" >c4.c.diff <<'END_OF_c4.c.diff'
X*** Orig/c4.c	Thu Apr 27 07:35:24 1989
X--- c4.c	Thu Apr 27 07:37:56 1989
X***************
X*** 11,16 ****
X--- 11,18 ----
X   *     BITNET:                  tcjones@WATER.bitnet
X   *     Canadian domain:         tcjones@dragon.uwaterloo.ca
X   *
X+  * Patched for SysV Rel3.1 by Tim Ramsey on 27 April 89.
X+  *   ..!rutgers!ksuvax1!tar, tar@ksuvax1.cis.ksu.edu
X   */
X  
X  #include <stdio.h>
X***************
X*** 17,25 ****
X  #include <sys/types.h>
X  #include <ctype.h>
X  #include <pwd.h>
X! #include <sys/time.h>
X! #include <sys/file.h>
X! #include <sys/param.h>
X  #include "c4.h"
X  #include "types.h"
X  #include "tables.h"
X--- 19,44 ----
X  #include <sys/types.h>
X  #include <ctype.h>
X  #include <pwd.h>
X! 
X! #define SYSV  /* TAR: could do this in Makefile but screen.c would complain */
X! 
X! #ifdef SYSV  /* TAR */
X! # include <unistd.h>  /* For lockf() */
X! # include <sys/utsname.h>  /* For uname() */
X! 
X! # define index strchr
X! # define u_char unchar
X! # define u_short ushort
X! 
X! struct passwd *getpwuid(), *getpwnam();
X! 
X! #else  /* !SYSV */
X! 
X! # include <sys/time.h>
X! # include <sys/file.h>
X! # include <sys/param.h>
X! #endif  /* SYSV */
X! 
X  #include "c4.h"
X  #include "types.h"
X  #include "tables.h"
X***************
X*** 43,49 ****
X  char *release_date = "8pm, January 1st, 1988";
X  int turn = GAME_OVER;
X  int first;
X! char *wizard = "tcjones";
X  
X  main(argc, argv, envp)
X  int argc;
X--- 62,68 ----
X  char *release_date = "8pm, January 1st, 1988";
X  int turn = GAME_OVER;
X  int first;
X! char wizard[] = "tcjones";  /* TAR: added "[]" */
X  
X  main(argc, argv, envp)
X  int argc;
X***************
X*** 259,264 ****
X--- 278,287 ----
X      char *win_str = "won";
X      extern char *date();
X  
X+ #ifdef SYSV  /* TAR */
X+     struct utsname sysname;
X+ #endif
X+ 
X      bell();
X      switch (winner){
X          case OURS:{
X***************
X*** 285,296 ****
X--- 308,330 ----
X          }
X      }
X  
X+ #ifdef SYSV  /* TAR */
X+     if (uname(&sysname) != -1){
X+ 	strcpy(host, sysname.nodename);
X+     }
X+     else{
X+ #else
X      if (gethostname(host, sizeof(host)) == -1){
X+ #endif
X          host[0] = '\0';
X          strcat(host, "Unknown");
X      }
X  
X+ #ifdef SYSV  /* TAR */
X+     if (lockf(fileno(scorefile), F_LOCK, 0) == -1){
X+ #else
X      if (flock(fileno(scorefile), LOCK_EX) == -1){
X+ #endif
X          fprintf(stderr, "Could not lock scorefile!\n");
X          return;
X      }
X***************
X*** 297,303 ****
X--- 331,341 ----
X  
X  	if (fseek(scorefile, 0L, 2) == -1){
X  		fprintf(stderr, "Could not unlock scorefile!\n");
X+ #ifdef SYSV  /* TAR */
X+ 		if (lockf(fileno(scorefile), F_ULOCK, 0) == -1){
X+ #else
X  		if (flock(fileno(scorefile), LOCK_UN) == -1){
X+ #endif
X  			fprintf(stderr, "Could not unlock scorefile!\n");
X  		}
X  		return;
X***************
X*** 320,326 ****
X--- 358,368 ----
X      }
X      fprintf(scorefile, "\n\n");
X  
X+ #ifdef SYSV  /* TAR */
X+     if (lockf(fileno(scorefile), F_ULOCK, 0) == -1){
X+ #else
X      if (flock(fileno(scorefile), LOCK_UN) == -1){
X+ #endif
X          fprintf(stderr, "Could not unlock scorefile!\n");
X          return;
X      }
X***************
X*** 683,703 ****
X      /* return pointer to NULL terminated date string */
X  
X      extern char *index();
X!     static char time[26];
X      struct timeval v;
X      struct timezone z;
X-     char *nl;
X  
X      gettimeofday(&v, &z);
X!     sprintf(time,"%s", ctime(&v.tv_sec));
X  
X!     if ((nl = index(time, '\n')) == NULL){
X          fprintf(stderr,"date: ctime returned non-newline terminated string.\n");
X          exit(1);
X      }
X  
X      *nl = '\0';
X!     return time;
X  }
X  
X  void
X--- 725,753 ----
X      /* return pointer to NULL terminated date string */
X  
X      extern char *index();
X!     static char timestr[26];  /* TAR */
X!     char *nl;
X! 
X! #ifdef SYSV  /* TAR */
X!     long secs;
X! 
X!     secs = time((long *) 0);
X!     sprintf(timestr,"%s", ctime(&secs));
X! #else
X      struct timeval v;
X      struct timezone z;
X  
X      gettimeofday(&v, &z);
X!     sprintf(timestr,"%s", ctime(&v.tv_sec));
X! #endif
X  
X!     if ((nl = index(timestr, '\n')) == NULL){
X          fprintf(stderr,"date: ctime returned non-newline terminated string.\n");
X          exit(1);
X      }
X  
X      *nl = '\0';
X!     return timestr;
X  }
X  
X  void
END_OF_c4.c.diff
if test 4222 -ne `wc -c <c4.c.diff`; then
    echo shar: \"c4.c.diff\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f screen.c.diff -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"screen.c.diff\"
else
echo shar: Extracting \"screen.c.diff\" \(217 characters\)
sed "s/^X//" >screen.c.diff <<'END_OF_screen.c.diff'
X*** Orig/screen.c	Thu Apr 27 07:35:27 1989
X--- screen.c	Thu Apr 27 07:37:09 1989
X***************
X*** 116,121 ****
X--- 116,122 ----
X      refresh();
X      nocrmode();
X      echo();
X+     endwin();  /* TAR */
X  }
X  
X  
END_OF_screen.c.diff
if test 217 -ne `wc -c <screen.c.diff`; then
    echo shar: \"screen.c.diff\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0