- make sure that the arguments to the printf like functions are correct

- add a makemsg() function to accompany makesignal.
This commit is contained in:
christos 1997-10-13 21:02:57 +00:00
parent 5e411157a1
commit 5175902c09
13 changed files with 103 additions and 81 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: assorted.c,v 1.5 1997/10/13 19:43:05 christos Exp $ */
/* $NetBSD: assorted.c,v 1.6 1997/10/13 21:02:57 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: assorted.c,v 1.5 1997/10/13 19:43:05 christos Exp $");
__RCSID("$NetBSD: assorted.c,v 1.6 1997/10/13 21:02:57 christos Exp $");
#endif
#endif /* not lint */
@ -114,7 +114,7 @@ int rig, shot, hittable, roll;
rigg[3] -= rhits;
}
if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1))
makesignal(on, "dismasted!", (struct ship *)0);
makemsg(on, "dismasted!");
if (portside(from, on, 0)) {
guns = on->specs->gunR;
car = on->specs->carR;
@ -152,19 +152,19 @@ int rig, shot, hittable, roll;
Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
switch (shot) {
case L_ROUND:
message = "firing round shot on %s (%c%c)";
message = "firing round shot on $$";
break;
case L_GRAPE:
message = "firing grape shot on %s (%c%c)";
message = "firing grape shot on $$";
break;
case L_CHAIN:
message = "firing chain shot on %s (%c%c)";
message = "firing chain shot on $$";
break;
case L_DOUBLE:
message = "firing double shot on %s (%c%c)";
message = "firing double shot on $$";
break;
case L_EXPLODE:
message = "exploding shot on %s (%c%c)";
message = "exploding shot on $$";
break;
default:
errx(1, "Unknown shot type %d", shot);
@ -197,7 +197,7 @@ int rig, shot, hittable, roll;
default:
errx(1, "Bad Rhit = %d", Rhit);
}
makesignal(on, message, (struct ship *)0);
makemsg(on, message);
} else if (roll == 6) {
switch (Hhit) {
case 0:
@ -225,17 +225,17 @@ int rig, shot, hittable, roll;
default:
errx(1, "Bad Hhit = %d", Hhit);
}
makesignal(on, message, (struct ship *)0);
makemsg(on, message);
}
/*
if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
on->specs->qual--;
if (on->specs->qual <= 0) {
makesignal(on, "crew mutinying!", (struct ship *)0);
makemsg(on, "crew mutinying!");
on->specs->qual = 5;
Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
} else
makesignal(on, "crew demoralized", (struct ship *)0);
makemsg(on, "crew demoralized");
Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
}
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: dr_1.c,v 1.5 1997/10/13 19:43:14 christos Exp $ */
/* $NetBSD: dr_1.c,v 1.6 1997/10/13 21:03:09 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dr_1.c,v 1.5 1997/10/13 19:43:14 christos Exp $");
__RCSID("$NetBSD: dr_1.c,v 1.6 1997/10/13 21:03:09 christos Exp $");
#endif
#endif /* not lint */
@ -189,7 +189,7 @@ int key;
unboard(to, from, 0);
subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
subtract(to, totalto, crewto, tocap, pcto);
makesignal(from, "boarders from %s repelled", to);
makemsg(from, "boarders from %s repelled", to->shipname);
(void) sprintf(message, "killed in melee: %d. %s: %d",
totalto, from->shipname, totalfrom);
Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: dr_2.c,v 1.5 1997/10/13 19:43:23 christos Exp $ */
/* $NetBSD: dr_2.c,v 1.6 1997/10/13 21:03:18 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dr_2.c,v 1.5 1997/10/13 19:43:23 christos Exp $");
__RCSID("$NetBSD: dr_2.c,v 1.6 1997/10/13 21:03:18 christos Exp $");
#endif
#endif /* not lint */
@ -99,13 +99,13 @@ checkup()
foreachship(sq)
cleansnag(sp, sq, 1);
if (sink != 1) {
makesignal(sp, "exploding!", (struct ship *)0);
makemsg(sp, "exploding!");
foreachship(sq) {
if (sp != sq && sq->file->dir && range(sp, sq) < 4)
table(RIGGING, L_EXPLODE, sp->specs->guns/13, sq, sp, 6);
}
} else
makesignal(sp, "sinking!", (struct ship *)0);
makemsg(sp, "sinking!");
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dr_3.c,v 1.4 1997/10/13 19:43:32 christos Exp $ */
/* $NetBSD: dr_3.c,v 1.5 1997/10/13 21:03:27 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)dr_3.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dr_3.c,v 1.4 1997/10/13 19:43:32 christos Exp $");
__RCSID("$NetBSD: dr_3.c,v 1.5 1997/10/13 21:03:27 christos Exp $");
#endif
#endif /* not lint */
@ -134,12 +134,10 @@ moveall() /* move all comp ships */
if (snagged2(sp, sq) && range(sp, sq) > 1)
snap++;
if (!range(sp, sq) && !fouled2(sp, sq)) {
makesignal(sp,
"collision with %s (%c%c)", sq);
makesignal(sp, "collision with $$", sq);
if (die() < 4) {
makesignal(sp,
"fouled with %s (%c%c)",
sq);
makesignal(sp, "fouled with $$",
sq);
Write(W_FOUL, sp, 0, l, 0, 0, 0);
Write(W_FOUL, sq, 0, n, 0, 0, 0);
}
@ -283,10 +281,9 @@ char isdefense;
Write(isdefense ? W_DBP : W_OBP, from, 0,
n, turn, to->file->index, sections);
if (isdefense)
makesignal(from, "repelling boarders",
(struct ship *)0);
makemsg(from, "repelling boarders");
else
makesignal(from, "boarding the %s (%c%c)", to);
makesignal(from, "boarding the $$", to);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dr_4.c,v 1.5 1997/10/13 19:43:39 christos Exp $ */
/* $NetBSD: dr_4.c,v 1.6 1997/10/13 21:03:37 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)dr_4.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: dr_4.c,v 1.5 1997/10/13 19:43:39 christos Exp $");
__RCSID("$NetBSD: dr_4.c,v 1.6 1997/10/13 21:03:37 christos Exp $");
#endif
#endif /* not lint */
@ -58,7 +58,7 @@ struct ship *from, *to;
while (--k >= 0) {
if (friend || die() < 3) {
cleangrapple(from, to, 0);
makesignal(from, "ungrappling %s (%c%c)", to);
makesignal(from, "ungrappling $$", to);
}
}
}
@ -71,5 +71,5 @@ struct ship *from, *to;
return;
Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
makesignal(from, "grappled with %s (%c%c)", to);
makesignal(from, "grappled with $$", to);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.4 1997/10/13 19:44:01 christos Exp $ */
/* $NetBSD: extern.h,v 1.5 1997/10/13 21:03:49 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -400,8 +400,10 @@ void loadplayer __P((void));
void initscreen __P((void));
void cleanupscreen __P((void));
void newturn __P((int));
void Signal __P((const char *, struct ship *, ...));
void Msg __P((const char *, ...));
void Signal __P((const char *, struct ship *, ...))
__attribute__((__format__(__printf__,1,3)));
void Msg __P((const char *, ...))
__attribute__((__format__(__printf__,1,2)));
void Scroll __P((void));
void prompt __P((char *, struct ship *));
void endprompt __P((int));
@ -426,7 +428,10 @@ void initialize __P((void));
/* sync.c */
void fmtship __P((char *, size_t, const char *, struct ship *));
void makesignal __P((struct ship *, const char *, struct ship *, ...));
void makesignal __P((struct ship *, const char *, struct ship *, ...))
__attribute__((__format__(__printf__,2,4)));
void makemsg __P((struct ship *, const char *, ...))
__attribute__((__format__(__printf__,2,3)));
int sync_exists __P((int));
int sync_open __P((void));
void sync_close __P((int));

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.5 1997/10/13 19:44:30 christos Exp $ */
/* $NetBSD: main.c,v 1.6 1997/10/13 21:03:55 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: main.c,v 1.5 1997/10/13 19:44:30 christos Exp $");
__RCSID("$NetBSD: main.c,v 1.6 1997/10/13 21:03:55 christos Exp $");
#endif
#endif /* not lint */
@ -65,7 +65,7 @@ main(argc, argv)
(void) srand(getpid());
issetuid = getuid() != geteuid();
if ((p = strrchr(*argv, '/')) != '\0')
if ((p = strrchr(*argv, '/')) != NULL)
p++;
else
p = *argv;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl_1.c,v 1.4 1997/10/13 19:44:53 christos Exp $ */
/* $NetBSD: pl_1.c,v 1.5 1997/10/13 21:04:02 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,13 +38,14 @@
#if 0
static char sccsid[] = "@(#)pl_1.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: pl_1.c,v 1.4 1997/10/13 19:44:53 christos Exp $");
__RCSID("$NetBSD: pl_1.c,v 1.5 1997/10/13 21:04:02 christos Exp $");
#endif
#endif /* not lint */
#include "player.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
/*
* If we get here before a ship is chosen, then ms == 0 and
@ -106,13 +107,14 @@ int conditions;
if (ms != 0) {
logger(ms);
if (conditions != LEAVE_SYNC) {
makesignal(ms, "Captain %s relinquishing.",
(struct ship *)0, mf->captain);
makemsg(ms, "Captain %s relinquishing.",
mf->captain);
Write(W_END, ms, 0, 0, 0, 0, 0);
(void) Sync();
}
}
sync_close(!hasdriver);
sleep(5);
cleanupscreen();
exit(0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl_3.c,v 1.4 1997/10/13 19:45:10 christos Exp $ */
/* $NetBSD: pl_3.c,v 1.5 1997/10/13 21:04:09 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pl_3.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: pl_3.c,v 1.4 1997/10/13 19:45:10 christos Exp $");
__RCSID("$NetBSD: pl_3.c,v 1.5 1997/10/13 21:04:09 christos Exp $");
#endif
#endif /* not lint */
@ -99,7 +99,7 @@ acceptcombat()
target = range(ms, closest);
if (target > rangeofshot[load] || (!guns && target >= 3))
goto cant;
Signal("%$ within range of %s broadside.",
Signal("$$ within range of %s broadside.",
closest, r ? "right" : "left");
if (load > L_CHAIN && target < 6) {
switch (sgetch("Aim for hull or rigging? ",
@ -133,9 +133,10 @@ acceptcombat()
sternrake = temp > 4 && temp < 6;
if (rakehim)
if (!sternrake)
Signal("%$ Raking the %s!", closest);
Msg("Raking the %s!", closest->shipname);
else
Signal("%$ Stern Rake! %s splintering!", closest);
Msg("Stern Rake! %s splintering!",
closest->shipname);
index = guns;
if (target < 3)
index += car;
@ -224,7 +225,7 @@ grapungrap()
continue;
if (range(ms, sp) > 1 && !grappled2(ms, sp))
continue;
switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
switch (sgetch("Attempt to grapple or ungrapple $$: ",
sp, 1)) {
case 'g':
if (die() < 3
@ -232,7 +233,7 @@ grapungrap()
Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
Write(W_GRAP, sp, 0, player, 0, 0, 0);
Msg("Attempt succeeds!");
makesignal(ms, "grappled with %s (%c%c)", sp);
makesignal(ms, "grappled with $$", sp);
} else
Msg("Attempt fails.");
break;
@ -243,8 +244,7 @@ grapungrap()
|| die() < 3) {
cleangrapple(ms, sp, 0);
Msg("Attempt succeeds!");
makesignal(ms,
"ungrappling with %s (%c%c)",
makesignal(ms, "ungrappling with $$",
sp);
} else
Msg("Attempt fails.");
@ -263,13 +263,13 @@ unfoulplayer()
foreachship(to) {
if (fouled2(ms, to) == 0)
continue;
if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y')
if (sgetch("Attempt to unfoul with the $$? ", to, 1) != 'y')
continue;
for (i = fouled2(ms, to); --i >= 0;) {
if (die() <= 2) {
cleanfoul(ms, to, 0);
Msg("Attempt succeeds!");
makesignal(ms, "Unfouling %s (%c%c)", to);
makesignal(ms, "Unfouling $$", to);
} else
Msg("Attempt fails.");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl_4.c,v 1.5 1997/10/13 19:45:20 christos Exp $ */
/* $NetBSD: pl_4.c,v 1.6 1997/10/13 21:04:17 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pl_4.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: pl_4.c,v 1.5 1997/10/13 19:45:20 christos Exp $");
__RCSID("$NetBSD: pl_4.c,v 1.6 1997/10/13 21:04:17 christos Exp $");
#endif
#endif /* not lint */
@ -133,7 +133,7 @@ struct ship *ship;
i = portside(ms, ship, 1) - mf->dir;
if (i <= 0)
i += 8;
Signal("%$ %s %s %s.",
Signal("$$ %s %s %s.",
ship, countryname[ship->nationality],
classname[ship->specs->class], directionname[i]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl_5.c,v 1.5 1997/10/13 19:45:26 christos Exp $ */
/* $NetBSD: pl_5.c,v 1.6 1997/10/13 21:04:24 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pl_5.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: pl_5.c,v 1.5 1997/10/13 19:45:26 christos Exp $");
__RCSID("$NetBSD: pl_5.c,v 1.6 1997/10/13 21:04:24 christos Exp $");
#endif
#endif /* not lint */
@ -182,11 +182,11 @@ acceptboard()
if (ms->nationality == capship(sp)->nationality)
continue;
if (meleeing(ms, sp) && crew[2]) {
c = sgetch("How many more to board the %s (%c%c)? ",
c = sgetch("How many more to board the $$? ",
sp, 1);
parties(crew, sp, 0, c);
} else if ((fouled2(ms, sp) || grappled2(ms, sp)) && crew[2]) {
c = sgetch("Crew sections to board the %s (%c%c) (3 max) ?", sp, 1);
c = sgetch("Crew sections to board the $$ (3 max) ?", sp, 1);
parties(crew, sp, 0, c);
}
}
@ -238,8 +238,7 @@ char buf;
else
(void) wmove(slot_w, 2, 1 + k);
(void) mvwaddstr(slot_w, 3, 0, "DBP");
makesignal(ms, "repelling boarders",
(struct ship *)0);
makemsg(ms, "repelling boarders");
} else {
(void) wmove(slot_w, 0, 0);
for (k=0; k < NBP; k++)
@ -248,7 +247,7 @@ char buf;
else
(void) wmove(slot_w, 0, 1 + k);
(void) mvwaddstr(slot_w, 1, 0, "OBP");
makesignal(ms, "boarding the %s (%c%c)", to);
makesignal(ms, "boarding the $$", to);
}
blockalarm();
(void) wrefresh(slot_w);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pl_7.c,v 1.7 1997/10/13 19:45:39 christos Exp $ */
/* $NetBSD: pl_7.c,v 1.8 1997/10/13 21:04:32 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: pl_7.c,v 1.7 1997/10/13 19:45:39 christos Exp $");
__RCSID("$NetBSD: pl_7.c,v 1.8 1997/10/13 21:04:32 christos Exp $");
#endif
#endif /* not lint */
@ -218,17 +218,13 @@ prompt(p, ship)
char *p;
struct ship *ship;
{
static char buf[60];
static char buf[BUFSIZ];
if (ship != 0) {
(void)sprintf(buf, p, ship->shipname, colours(ship),
sterncolour(ship));
p = buf;
}
sc_prompt = p;
fmtship(buf, sizeof(buf), p, ship);
sc_prompt = buf;
sc_buf = "";
sc_hasprompt = 1;
(void) waddstr(scroll_w, p);
(void) waddstr(scroll_w, buf);
}
void
@ -247,7 +243,6 @@ struct ship *ship;
char flag;
{
int c;
prompt(p, ship);
blockalarm();
(void) wrefresh(scroll_w);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sync.c,v 1.6 1997/10/13 19:45:54 christos Exp $ */
/* $NetBSD: sync.c,v 1.7 1997/10/13 21:04:40 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)sync.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: sync.c,v 1.6 1997/10/13 19:45:54 christos Exp $");
__RCSID("$NetBSD: sync.c,v 1.7 1997/10/13 21:04:40 christos Exp $");
#endif
#endif /* not lint */
@ -78,7 +78,7 @@ fmtship(buf, len, fmt, ship)
*buf = '\0';
return;
}
if (*fmt == '%' && fmt[1] == '$') {
if (*fmt == '$' && fmt[1] == '$') {
size_t l = snprintf(buf, len, "%s (%c%c)",
ship->shipname, colours(ship), sterncolour(ship));
buf += l;
@ -124,6 +124,30 @@ makesignal(va_alias)
Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
}
void
#ifdef __STDC__
makemsg(struct ship *from, const char *fmt, ...)
#else
makemsg(va_alias)
va_dcl
#endif
{
char message[BUFSIZ];
va_list ap;
#ifndef __STDC__
struct ship *from;
const char *fmt;
va_start(ap);
from = va_arg(ap, struct ship *);
fmt = va_arg(ap, const char *);
#else
va_start(ap, fmt);
#endif
(void) vsprintf(message, fmt, ap);
va_end(ap);
Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
}
int
sync_exists(game)
{
@ -351,9 +375,9 @@ sync_update(type, ship, a, b, c, d)
case W_SIGNAL:
if (mode == MODE_PLAYER)
if (nobells)
Signal("%$: %s", ship, a);
Signal("$$: %s", ship, (char *) a);
else
Signal("\7%$: %s", ship, a);
Signal("\7$$: %s", ship, (char *) a);
break;
case W_CREW: {
struct shipspecs *s = ship->specs;