-/* $NetBSD: execute.c,v 1.18 2008/02/24 02:43:18 dholland Exp $ */
+/* $NetBSD: execute.c,v 1.22 2012/06/19 05:35:32 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
#if 0
static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: execute.c,v 1.18 2008/02/24 02:43:18 dholland Exp $");
+__RCSID("$NetBSD: execute.c,v 1.22 2012/06/19 05:35:32 dholland Exp $");
#endif
#endif /* not lint */
* This routine executes the given command by index number
*/
void
-execute(com_num)
- int com_num;
+execute(int com_num)
{
new_play = FALSE; /* new_play is true if fixing */
(*func[com_num])();
* This routine moves a piece around.
*/
void
-do_move()
+do_move(void)
{
int r1, r2;
bool was_jail;
* This routine moves a normal move
*/
void
-move(rl)
- int rl;
+move(int rl)
{
int old_loc;
* This routine shows the results of a move
*/
static void
-show_move()
+show_move(void)
{
SQUARE *sqp;
* This routine saves the current game for use at a later date
*/
void
-save()
+save(void)
{
char *sp;
FILE *outf;
* This routine restores an old game from a file
*/
void
-restore()
+restore(void)
{
char *sp;
- printf("Which file do you wish to restore from? ");
- fgets(buf, sizeof(buf), stdin);
- if (feof(stdin))
- return;
- sp = strchr(buf, '\n');
- if (sp)
- *sp = '\0';
- rest_f(buf);
+ for (;;) {
+ printf("Which file do you wish to restore from? ");
+ fgets(buf, sizeof(buf), stdin);
+ if (feof(stdin))
+ return;
+ sp = strchr(buf, '\n');
+ if (sp)
+ *sp = '\0';
+ if (rest_f(buf) == 0)
+ break;
+ }
}
/*
- * This does the actual restoring. It returns TRUE if the
- * backup was successful, else false.
+ * This does the actual restoring. It returns zero on success,
+ * and -1 on failure.
*/
int
-rest_f(file)
- const char *file;
+rest_f(const char *file)
{
char *sp;
FILE *inf;
char xbuf[80];
STAT sbuf;
char readbuf[512];
+ int ret = 0;
inf = fopen(file, "r");
if (inf == NULL) {
warn("%s", file);
- return FALSE;
+ return -1;
}
printf("\"%s\" ", file);
if (fstat(fileno(inf), &sbuf) < 0) {
sp = strchr(readbuf, '\n');
if (sp == NULL) {
printf("file is corrupt: long lines.\n");
+ ret = -1;
break;
}
*sp = '\0';
if (restore_parseline(readbuf)) {
+ ret = -1;
break;
}
}
warnx("%s: read error", file);
fclose(inf);
+ if (ret < 0)
+ return -1;
+
name_list[num_play] = "done";
+ if (play == NULL || cur_p == NULL || num_play < 2) {
+ printf("save file is incomplete.\n");
+ return -1;
+ }
+
/*
* We could at this point crosscheck the following:
* - there are only two GOJF cards floating around
continue;
*sp = '\0';
printf("[%s]\n", xbuf);
- return TRUE;
+ return 0;
}
/*
RI_NONE,
RI_PLAYER,
RI_DECK,
- RI_SQUARE,
+ RI_SQUARE
} restore_item;
static int restore_itemnum;
printf("numplayers: multiple settings\n");
return -1;
}
- play = calloc(num_play, sizeof(play[0]));
+ play = calloc((size_t)num_play, sizeof(play[0]));
if (play == NULL) {
err(1, "calloc");
}