+/* $NetBSD: execute.c,v 1.14 2008/02/19 09:45:02 dholland Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)execute.c 5.5 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: execute.c,v 1.2 1993/08/01 18:53:43 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: execute.c,v 1.14 2008/02/19 09:45:02 dholland Exp $");
+#endif
#endif /* not lint */
-# include "monop.ext"
-# include <sys/types.h>
-# include <sys/stat.h>
-# include <sys/time.h>
+#include "monop.ext"
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <time.h>
-# define SEGSIZE 8192
+#define SEGSIZE 8192
typedef struct stat STAT;
typedef struct tm TIME;
-extern char etext[], /* end of text space */
- rub();
-
-static char buf[257],
- *yn_only[] = { "yes", "no"};
+static char buf[257];
static bool new_play; /* set if move on to new player */
+extern void *heapstart;
+
+static void show_move(void);
/*
* This routine executes the given command by index number
*/
+void
execute(com_num)
-reg int com_num; {
-
+ int com_num;
+{
new_play = FALSE; /* new_play is true if fixing */
(*func[com_num])();
notify();
else if (num_doub)
printf("%s rolled doubles. Goes again\n", cur_p->name);
}
+
/*
* This routine moves a piece around.
*/
-do_move() {
-
- reg int r1, r2;
- reg bool was_jail;
+void
+do_move()
+{
+ int r1, r2;
+ bool was_jail;
new_play = was_jail = FALSE;
printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6));
ret:
return;
}
+
/*
* This routine moves a normal move
*/
+void
move(rl)
-reg int rl; {
-
- reg int old_loc;
+ int rl;
+{
+ int old_loc;
old_loc = cur_p->loc;
cur_p->loc = (cur_p->loc + rl) % N_SQRS;
}
show_move();
}
+
/*
* This routine shows the results of a move
*/
-show_move() {
-
- reg SQUARE *sqp;
+static void
+show_move()
+{
+ SQUARE *sqp;
sqp = &board[cur_p->loc];
printf("That puts you on %s\n", sqp->name);
printf("That is a safe place\n");
break;
case CC:
- cc(); break;
+ cc();
+ break;
case CHANCE:
- chance(); break;
+ chance();
+ break;
case INC_TAX:
- inc_tax(); break;
+ inc_tax();
+ break;
case GOTO_J:
- goto_jail(); break;
+ goto_jail();
+ break;
case LUX_TAX:
- lux_tax(); break;
+ lux_tax();
+ break;
case PRPTY:
case RR:
case UTIL:
cur_p->money -= sqp->cost;
}
else if (num_play > 2)
- bid(sqp);
+ bid();
}
else if (sqp->owner == player)
printf("You own it.\n");
rent(sqp);
}
}
+
/*
* This routine saves the current game for use at a later date
*/
-save() {
-
- reg char *sp;
- reg int outf, num;
- time_t t;
- int *dat_end;
- struct stat sb;
- unsgn start, end;
+void
+save()
+{
+ char *sp;
+ int outf, num;
+ time_t t;
+ struct stat sb;
+ char *start, *end;
printf("Which file do you wish to save it in? ");
sp = buf;
- while ((*sp++=getchar()) != '\n')
+ while ((*sp++ = getchar()) != '\n')
continue;
*--sp = '\0';
*/
if (stat(buf, &sb) > -1
- && getyn("File exists. Do you wish to overwrite? ", yn_only) > 0)
+ && getyn("File exists. Do you wish to overwrite? ") > 0)
return;
- if ((outf=creat(buf, 0644)) < 0) {
- perror(buf);
+ if ((outf = creat(buf, 0644)) < 0) {
+ warn("%s", buf);
return;
}
printf("\"%s\" ", buf);
for (sp = buf; *sp != '\n'; sp++)
continue;
*sp = '\0';
-# if 0
- start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
-# else
- start = 0;
-# endif
+ start = heapstart;
end = sbrk(0);
while (start < end) { /* write out entire data space */
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
close(outf);
printf("[%s]\n", buf);
}
+
/*
* This routine restores an old game from a file
*/
-restore() {
-
- reg char *sp;
+void
+restore()
+{
+ char *sp;
printf("Which file do you wish to restore from? ");
- for (sp = buf; (*sp=getchar()) != '\n'; sp++)
+ for (sp = buf; (*sp = getchar()) != '\n'; sp++)
continue;
*sp = '\0';
rest_f(buf);
}
+
/*
* This does the actual restoring. It returns TRUE if the
* backup was successful, else false.
*/
+int
rest_f(file)
-reg char *file; {
-
- reg char *sp;
- reg int inf, num;
- char buf[80];
- unsgn start, end;
- STAT sbuf;
+ const char *file;
+{
+ char *sp;
+ int inf, num;
+ char xbuf[80];
+ char *start, *end;
+ STAT sbuf;
- if ((inf=open(file, 0)) < 0) {
- perror(file);
+ if ((inf = open(file, O_RDONLY)) < 0) {
+ warn("%s", file);
return FALSE;
}
printf("\"%s\" ", file);
if (fstat(inf, &sbuf) < 0) { /* get file stats */
- perror(file);
- exit(1);
+ err(1, "%s: fstat", file);
}
-# if 0
- start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
-# else
- start = 0;
-# endif
+ start = heapstart;
brk(end = start + sbuf.st_size);
while (start < end) { /* write out entire data space */
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
start += num;
}
close(inf);
- strcpy(buf, ctime(&sbuf.st_mtime));
- for (sp = buf; *sp != '\n'; sp++)
+ strcpy(xbuf, ctime(&sbuf.st_mtime));
+ for (sp = xbuf; *sp != '\n'; sp++)
continue;
*sp = '\0';
- printf("[%s]\n", buf);
+ printf("[%s]\n", xbuf);
return TRUE;
}