]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - sail/pl_main.c
Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
[bsdgames-darwin.git] / sail / pl_main.c
index c4b7cad11b8962ca7d3efe17ba3ad5aa34e74200..85fd88eae543318c940799936345bc7401986daf 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: pl_main.c,v 1.15 2001/02/05 01:10:11 christos Exp $    */
+
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 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
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-/*static char sccsid[] = "from: @(#)pl_main.c  5.5 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: pl_main.c,v 1.3 1994/01/13 19:22:29 glass Exp $";
+#if 0
+static char sccsid[] = "@(#)pl_main.c  8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: pl_main.c,v 1.15 2001/02/05 01:10:11 christos Exp $");
+#endif
 #endif /* not lint */
 
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "extern.h"
 #include "player.h"
-#include <sys/types.h>
-#include <sys/wait.h>
+#include "restart.h"
 
-void choke(), child();
+static void    initialize(void);
 
 /*ARGSUSED*/
-pl_main()
+int
+pl_main(void)
 {
 
-       if (!SCREENTEST()) {
-               printf("Can't sail on this terminal.\n");
-               exit(1);
-       }
        initialize();
-       Signal("Aye aye, Sir", (struct ship *)0);
+       Msg("Aye aye, Sir");
        play();
        return 0;                       /* for lint,  play() never returns */
 }
 
-initialize()
+static void
+initialize(void)
 {
-       register struct File *fp;
-       register struct ship *sp;
+       struct File *fp;
+       struct ship *sp;
        char captain[80];
        char message[60];
        int load;
-       register int n;
+       int n;
        char *nameptr;
        int nat[NNATION];
 
        if (game < 0) {
-               (void) puts("Choose a scenario:\n");
-               (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
+               puts("Choose a scenario:\n");
+               puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
                for (n = 0; n < NSCENE; n++) {
                        /* ( */
                        printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels,
@@ -78,13 +88,13 @@ initialize()
                }
 reprint:
                printf("\nScenario number? ");
-               (void) fflush(stdout);
-               (void) scanf("%d", &game);
+               fflush(stdout);
+               scanf("%d", &game);
                while (getchar() != '\n')
                        ;
        }
        if (game < 0 || game >= NSCENE) {
-               (void) puts("Very funny.");
+               puts("Very funny.");
                exit(1);
        }
        cc = &scene[game];
@@ -95,7 +105,7 @@ reprint:
        foreachship(sp) {
                if (sp->file == NULL &&
                    (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) {
-                       (void) puts("OUT OF MEMORY");
+                       puts("OUT OF MEMORY");
                        exit(1);
                }
                sp->file->index = sp - SHIP(0);
@@ -107,8 +117,8 @@ reprint:
        windspeed = cc->windspeed;
        winddir = cc->winddir;
 
-       (void) signal(SIGHUP, choke);
-       (void) signal(SIGINT, choke);
+       signal(SIGHUP, choke);
+       signal(SIGINT, choke);
 
        hasdriver = sync_exists(game);
        if (sync_open() < 0) {
@@ -117,8 +127,8 @@ reprint:
        }
 
        if (hasdriver) {
-               (void) puts("Synchronizing with the other players...");
-               (void) fflush(stdout);
+               puts("Synchronizing with the other players...");
+               fflush(stdout);
                if (Sync() < 0)
                        leave(LEAVE_SYNC);
        }
@@ -128,7 +138,7 @@ reprint:
                            && sp->file->captured == 0)
                                break;
                if (sp >= ls) {
-                       (void) puts("All ships taken in that scenario.");
+                       puts("All ships taken in that scenario.");
                        foreachship(sp)
                                free((char *)sp->file);
                        sync_close(0);
@@ -147,12 +157,12 @@ reprint:
                                        sp->specs->pts,
                                        saywhat(sp, 1));
                        printf("\nWhich ship (0-%d)? ", cc->vessels-1);
-                       (void) fflush(stdout);
+                       fflush(stdout);
                        if (scanf("%d", &player) != 1 || player < 0
                            || player >= cc->vessels) {
                                while (getchar() != '\n')
                                        ;
-                               (void) puts("Say what?");
+                               puts("Say what?");
                                player = -1;
                        } else
                                while (getchar() != '\n')
@@ -164,7 +174,7 @@ reprint:
                        leave(LEAVE_SYNC);
                fp = SHIP(player)->file;
                if (fp->captain[0] || fp->struck || fp->captured != 0)
-                       (void) puts("That ship is taken.");
+                       puts("That ship is taken.");
                else
                        break;
        }
@@ -173,11 +183,11 @@ reprint:
        mf = ms->file;
        mc = ms->specs;
 
-       Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
+       Write(W_BEGIN, ms, 0, 0, 0, 0);
        if (Sync() < 0)
                leave(LEAVE_SYNC);
 
-       (void) signal(SIGCHLD, child);
+       signal(SIGCHLD, child);
        if (!hasdriver)
                switch (fork()) {
                case 0:
@@ -195,25 +205,25 @@ reprint:
                ms->shipname, mc->guns, classname[mc->class],
                qualname[mc->qual]);
        if ((nameptr = (char *) getenv("SAILNAME")) && *nameptr)
-               (void) strncpy(captain, nameptr, sizeof captain);
+               strncpy(captain, nameptr, sizeof captain);
        else {
-               (void) printf("Your name, Captain? ");
-               (void) fflush(stdout);
-               (void) fgets(captain, sizeof captain, stdin);
+               printf("Your name, Captain? ");
+               fflush(stdout);
+               fgets(captain, sizeof captain, stdin);
                if (!*captain)
-                       (void) strcpy(captain, "no name");
+                       strcpy(captain, "no name");
                else
                    captain[strlen(captain) - 1] = '\0';
        }
        captain[sizeof captain - 1] = '\0';
-       Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0);
+       Writestr(W_CAPTAIN, ms, captain);
        for (n = 0; n < 2; n++) {
                char buf[10];
 
                printf("\nInitial broadside %s (grape, chain, round, double): ",
                        n ? "right" : "left");
-               (void) fflush(stdout);
-               (void) scanf("%s", buf);
+               fflush(stdout);
+               scanf("%s", buf);
                switch (*buf) {
                case 'g':
                        load = L_GRAPE;
@@ -241,7 +251,8 @@ reprint:
 
        initscreen();
        draw_board();
-       (void) sprintf(message, "Captain %s assuming command", captain);
-       Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0);
-       newturn();
+       snprintf(message, sizeof message, "Captain %s assuming command",
+                       captain);
+       Writestr(W_SIGNAL, ms, message);
+       newturn(0);
 }