summaryrefslogtreecommitdiffstats
path: root/sail/sync.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1997-10-13 19:42:53 +0000
committerchristos <christos@NetBSD.org>1997-10-13 19:42:53 +0000
commit7e5c0c57606f0f1e9335aa74ef5ea8c8048a9b2c (patch)
treee32f911a4774980914f141c9b101745fb106eefe /sail/sync.c
parentc1a3f2353b38d22d94cbc0101f3115b8e2eefc30 (diff)
downloadbsdgames-darwin-7e5c0c57606f0f1e9335aa74ef5ea8c8048a9b2c.tar.gz
bsdgames-darwin-7e5c0c57606f0f1e9335aa74ef5ea8c8048a9b2c.tar.zst
bsdgames-darwin-7e5c0c57606f0f1e9335aa74ef5ea8c8048a9b2c.zip
Warns fixes:
use varargs properly use unsigned chars where appropriate fix typos eliminate gcc warnings
Diffstat (limited to 'sail/sync.c')
-rw-r--r--sail/sync.c127
1 files changed, 91 insertions, 36 deletions
diff --git a/sail/sync.c b/sail/sync.c
index d3389964..641ab324 100644
--- a/sail/sync.c
+++ b/sail/sync.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sync.c,v 1.5 1997/01/07 12:42:27 tls Exp $ */
+/* $NetBSD: sync.c,v 1.6 1997/10/13 19:45:54 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -33,16 +33,26 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)sync.c 8.2 (Berkeley) 4/28/95";
#else
-static char rcsid[] = "$NetBSD: sync.c,v 1.5 1997/01/07 12:42:27 tls Exp $";
+__RCSID("$NetBSD: sync.c,v 1.6 1997/10/13 19:45:54 christos Exp $");
#endif
#endif /* not lint */
-#include <sys/file.h>
+#include <fcntl.h>
#include <errno.h>
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "extern.h"
#define BUFSIZE 4096
@@ -56,26 +66,65 @@ static FILE *sync_fp;
#define SF "/tmp/#sailsink.%d"
#define LF "/tmp/#saillock.%d"
+void
+fmtship(buf, len, fmt, ship)
+ char *buf;
+ size_t len;
+ const char *fmt;
+ struct ship *ship;
+{
+ while (*fmt) {
+ if (len-- == 0) {
+ *buf = '\0';
+ return;
+ }
+ if (*fmt == '%' && fmt[1] == '$') {
+ size_t l = snprintf(buf, len, "%s (%c%c)",
+ ship->shipname, colours(ship), sterncolour(ship));
+ buf += l;
+ len -= l - 1;
+ fmt += 2;
+ }
+ else
+ *buf++ = *fmt++;
+ }
+
+ if (len > 0)
+ *buf = '\0';
+}
+
+
/*VARARGS3*/
-makesignal(from, fmt, ship, a, b, c)
- struct ship *from;
- char *fmt;
- register struct ship *ship;
- long a, b, c;
+void
+#ifdef __STDC__
+makesignal(struct ship *from, const char *fmt, struct ship *ship, ...)
+#else
+makesignal(va_alias)
+ va_dcl
+#endif
{
- char message[80];
+ char message[BUFSIZ];
+ char format[BUFSIZ];
+ va_list ap;
+#ifndef __STDC__
+ struct ship *from;
+ const char *fmt;
+ struct ship *ship;
- if (ship == 0)
- (void) sprintf(message, fmt, a, b, c);
- else
- (void) sprintf(message, fmt,
- ship->shipname, colours(ship),
- sterncolour(ship), a, b, c);
+ va_start(ap);
+ from = va_arg(ap, struct ship *);
+ fmt = va_arg(ap, const char *);
+ ship = va_arg(ap, struct ship *);
+#else
+ va_start(ap, ship);
+#endif
+ fmtship(format, sizeof(format), fmt, ship);
+ (void) vsprintf(message, format, ap);
+ va_end(ap);
Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
}
-#include <sys/types.h>
-#include <sys/stat.h>
+int
sync_exists(game)
{
char buf[sizeof sync_file];
@@ -95,6 +144,7 @@ sync_exists(game)
return 1;
}
+int
sync_open()
{
if (sync_fp != NULL)
@@ -113,6 +163,7 @@ sync_open()
return 0;
}
+void
sync_close(remove)
char remove;
{
@@ -122,17 +173,19 @@ sync_close(remove)
(void) unlink(sync_file);
}
+void
Write(type, ship, isstr, a, b, c, d)
int type;
struct ship *ship;
- char isstr;
+ int isstr;
long a, b, c, d;
{
+
if (isstr)
(void) sprintf(sync_bp, "%d %d %d %s\n",
- type, ship->file->index, isstr, a);
+ type, ship->file->index, isstr, (char *) a);
else
- (void) sprintf(sync_bp, "%d %d %d %d %d %d %d\n",
+ (void) sprintf(sync_bp, "%d %d %d %ld %ld %ld %ld\n",
type, ship->file->index, isstr, a, b, c, d);
while (*sync_bp++)
;
@@ -142,10 +195,11 @@ Write(type, ship, isstr, a, b, c, d)
(void) sync_update(type, ship, a, b, c, d);
}
+int
Sync()
{
sig_t sighup, sigint;
- register n;
+ int n;
int type, shipnum, isstr;
long a, b, c, d;
char buf[80];
@@ -185,7 +239,7 @@ Sync()
if (isstr != 0 && isstr != 1)
goto bad;
if (isstr) {
- register char *p;
+ char *p;
for (p = buf;;) {
switch (*p++ = getc(sync_fp)) {
case '\n':
@@ -205,7 +259,7 @@ Sync()
a = (long)p;
b = c = d = 0;
} else
- if (fscanf(sync_fp, "%d%d%d%d", &a, &b, &c, &d) != 4)
+ if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d) != 4)
goto bad;
if (sync_update(type, SHIP(shipnum), a, b, c, d) < 0)
goto bad;
@@ -231,28 +285,29 @@ out:
return erred ? -1 : 0;
}
+int
sync_update(type, ship, a, b, c, d)
int type;
- register struct ship *ship;
+ struct ship *ship;
long a, b, c, d;
{
switch (type) {
case W_DBP: {
- register struct BP *p = &ship->file->DBP[a];
+ struct BP *p = &ship->file->DBP[a];
p->turnsent = b;
p->toship = SHIP(c);
p->mensent = d;
break;
}
case W_OBP: {
- register struct BP *p = &ship->file->OBP[a];
+ struct BP *p = &ship->file->OBP[a];
p->turnsent = b;
p->toship = SHIP(c);
p->mensent = d;
break;
}
case W_FOUL: {
- register struct snag *p = &ship->file->foul[a];
+ struct snag *p = &ship->file->foul[a];
if (SHIP(a)->file->dir == 0)
break;
if (p->sn_count++ == 0)
@@ -261,7 +316,7 @@ sync_update(type, ship, a, b, c, d)
break;
}
case W_GRAP: {
- register struct snag *p = &ship->file->grap[a];
+ struct snag *p = &ship->file->grap[a];
if (SHIP(a)->file->dir == 0)
break;
if (p->sn_count++ == 0)
@@ -270,7 +325,7 @@ sync_update(type, ship, a, b, c, d)
break;
}
case W_UNFOUL: {
- register struct snag *p = &ship->file->foul[a];
+ struct snag *p = &ship->file->foul[a];
if (p->sn_count > 0)
if (b) {
ship->file->nfoul -= p->sn_count;
@@ -282,7 +337,7 @@ sync_update(type, ship, a, b, c, d)
break;
}
case W_UNGRAP: {
- register struct snag *p = &ship->file->grap[a];
+ struct snag *p = &ship->file->grap[a];
if (p->sn_count > 0)
if (b) {
ship->file->ngrap -= p->sn_count;
@@ -296,12 +351,12 @@ sync_update(type, ship, a, b, c, d)
case W_SIGNAL:
if (mode == MODE_PLAYER)
if (nobells)
- Signal("%s (%c%c): %s", ship, a);
+ Signal("%$: %s", ship, a);
else
- Signal("\7%s (%c%c): %s", ship, a);
+ Signal("\7%$: %s", ship, a);
break;
case W_CREW: {
- register struct shipspecs *s = ship->specs;
+ struct shipspecs *s = ship->specs;
s->crew1 = a;
s->crew2 = b;
s->crew3 = c;
@@ -332,13 +387,13 @@ sync_update(type, ship, a, b, c, d)
ship->file->FS = a;
break;
case W_GUNL: {
- register struct shipspecs *s = ship->specs;
+ struct shipspecs *s = ship->specs;
s->gunL = a;
s->carL = b;
break;
}
case W_GUNR: {
- register struct shipspecs *s = ship->specs;
+ struct shipspecs *s = ship->specs;
s->gunR = a;
s->carR = b;
break;
@@ -361,7 +416,7 @@ sync_update(type, ship, a, b, c, d)
ship->specs->qual = a;
break;
case W_RIGG: {
- register struct shipspecs *s = ship->specs;
+ struct shipspecs *s = ship->specs;
s->rig1 = a;
s->rig2 = b;
s->rig3 = c;