1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Pledge for backgammon and teachgammon.

Both are straightforward "stdio rpath tty" programs; teachgammon
exec's backgammon at the end, so give it "exec" in addition.

While there, ANSIfy
This commit is contained in:
tb 2015-11-30 08:19:25 +00:00
parent a75265e181
commit 87f25a4abf
17 changed files with 85 additions and 121 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extra.c,v 1.7 2015/05/20 20:26:00 millert Exp $ */
/* $OpenBSD: extra.c,v 1.8 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
*/
void
dble()
dble(void)
{
int resp; /* response to y/n */
@ -96,7 +96,7 @@ dble()
*/
int
dblgood()
dblgood(void)
{
int n; /* accumulated judgment */
int OFFC = *offptr; /* no. of computer's men off */
@ -171,8 +171,7 @@ dblgood()
}
int
freemen(b)
int b;
freemen(int b)
{
int i, inc, lim;
@ -190,8 +189,7 @@ freemen(b)
}
int
trapped(n, inc)
int n, inc;
trapped(int n, int inc)
{
int i, j, k;
int c, l, ct;
@ -217,7 +215,7 @@ trapped(n, inc)
}
int
eval()
eval(void)
{
int i, j;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.18 2015/06/26 19:18:03 otto Exp $ */
/* $OpenBSD: main.c,v 1.19 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -81,13 +81,14 @@ static const char again[] = ".\nWould you like to play again?";
static const char svpromt[] = "Would you like to save this game?";
int
main (argc,argv)
int argc;
char **argv;
main (int argc, char **argv)
{
int i,l; /* non-descript indices */
char c; /* non-descript character storage */
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
signal(SIGINT, getout); /* trap interrupts */
/* check user count */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: move.c,v 1.12 2015/08/22 14:47:41 deraadt Exp $ */
/* $OpenBSD: move.c,v 1.13 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -62,8 +62,7 @@ static void pickmove(void);
void
domove(okay)
int okay; /* zero if first move */
domove(int okay)
{
int i; /* index */
int l = 0; /* last man */
@ -137,9 +136,7 @@ domove(okay)
}
void
trymove(mvnum, swapped)
int mvnum; /* number of move (rel zero) */
int swapped; /* see if swapped also tested */
trymove(int mvnum, int swapped)
{
int pos; /* position on board */
int rval; /* value of roll */
@ -189,7 +186,7 @@ trymove(mvnum, swapped)
}
static struct BOARD *
bsave()
bsave(void)
{
int i; /* index */
struct BOARD *now; /* current position */
@ -211,8 +208,7 @@ bsave()
}
static void
binsert(new)
struct BOARD *new; /* item to insert */
binsert(struct BOARD *new)
{
struct BOARD *p = checkq; /* queue pointer */
int result; /* comparison result */
@ -253,9 +249,7 @@ binsert(new)
}
static int
bcomp(a, b)
struct BOARD *a;
struct BOARD *b;
bcomp(struct BOARD *a, struct BOARD *b)
{
int *aloc = a->b_board; /* pointer to board a */
int *bloc = b->b_board; /* pointer to board b */
@ -271,9 +265,7 @@ bcomp(a, b)
}
static void
mvcheck(incumbent, candidate)
struct BOARD *incumbent;
struct BOARD *candidate;
mvcheck(struct BOARD *incumbent, struct BOARD *candidate)
{
int i, result;
@ -293,15 +285,14 @@ mvcheck(incumbent, candidate)
}
static void
makefree(dead)
struct BOARD *dead; /* dead position */
makefree(struct BOARD *dead)
{
dead->b_next = freeq; /* add to freeq */
freeq = dead;
}
static struct BOARD *
nextfree()
nextfree(void)
{
struct BOARD *new;
@ -321,7 +312,7 @@ nextfree()
}
static void
pickmove()
pickmove(void)
{
/* current game position */
struct BOARD *now = bsave();
@ -345,8 +336,7 @@ pickmove()
}
static void
boardcopy(s)
struct BOARD *s; /* game situation */
boardcopy(struct BOARD *s)
{
int i; /* index */
@ -363,7 +353,7 @@ boardcopy(s)
}
static void
movcmp()
movcmp(void)
{
int i;
float f;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pubeval.c,v 1.2 2009/10/28 23:22:45 schwarze Exp $ */
/* $OpenBSD: pubeval.c,v 1.3 2015/11/30 08:19:25 tb Exp $ */
/* Public domain, Gerry Tesauro. */
/* Backgammon move-selection evaluation function for benchmark comparisons.
@ -102,7 +102,7 @@ pubeval(int race)
/* sets input vector x[] given board position pos[] */
void
setx()
setx(void)
{
int i, j, jm1, n;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: text.c,v 1.8 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: text.c,v 1.9 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -93,8 +93,7 @@ const char *const instruct[] = {
0};
int
text(t)
const char *const *t;
text(const char *const *t)
{
int i;
const char *s, *a;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: allow.c,v 1.5 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: allow.c,v 1.6 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -32,7 +32,7 @@
#include "back.h"
int
movallow()
movallow(void)
{
int i, m, iold, r;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: board.c,v 1.9 2014/04/25 20:23:37 schwarze Exp $ */
/* $OpenBSD: board.c,v 1.10 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -32,7 +32,7 @@
#include "back.h"
void
wrboard()
wrboard(void)
{
clear();
fboard();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: check.c,v 1.6 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: check.c,v 1.7 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -32,7 +32,7 @@
#include "back.h"
void
getmove()
getmove(void)
{
int i, c;
@ -77,8 +77,7 @@ getmove()
}
int
movokay(mv)
int mv;
movokay(int mv)
{
int i, m;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: fancy.c,v 1.12 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: fancy.c,v 1.13 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -36,7 +36,7 @@ int oldb[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int oldr, oldw;
void
fboard()
fboard(void)
{
int i, j, k, l;
@ -118,11 +118,7 @@ fboard()
* differently.
*/
void
bsect(b, rpos, cpos, cnext)
int b; /* contents of position */
int rpos; /* row of position */
int cpos; /* column of position */
int cnext; /* direction of position */
bsect(int b, int rpos, int cpos, int cnext)
{
int j; /* index */
int n; /* number of men on position */
@ -176,7 +172,7 @@ bsect(b, rpos, cpos, cnext)
}
void
moveplayers()
moveplayers(void)
{
int i, r, c;
@ -225,8 +221,7 @@ moveplayers()
void
fixpos(old, new, r, c, inc)
int old, new, r, c, inc;
fixpos(int old, int new, int r, int c, int inc)
{
int o, n, nv;
int ov, nc;
@ -296,8 +291,7 @@ fixpos(old, new, r, c, inc)
}
void
fixcol(r, c, l, ch, inc)
int r, c, l, ch, inc;
fixcol(int r, int c, int l, int ch, int inc)
{
int i;
@ -310,7 +304,7 @@ fixcol(r, c, l, ch, inc)
void
initcurses()
initcurses(void)
{
initscr();
cbreak();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: odds.c,v 1.5 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: odds.c,v 1.6 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -32,8 +32,7 @@
#include "back.h"
void
odds(r1, r2, val)
int r1, r2, val;
odds(int r1, int r2, int val)
{
int i, j;
@ -69,8 +68,7 @@ count()
}
int
canhit(i, c)
int i, c;
canhit(int i, int c)
{
int j, k, b;
int a, diff, place, addon, menstuck;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: one.c,v 1.6 2015/07/20 23:04:17 schwarze Exp $ */
/* $OpenBSD: one.c,v 1.7 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -32,8 +32,7 @@
#include "back.h"
int
makmove(i)
int i;
makmove(int i)
{
int n, d;
int max;
@ -83,8 +82,7 @@ makmove(i)
}
void
moverr(i)
int i;
moverr(int i)
{
int j;
@ -99,8 +97,7 @@ moverr(i)
}
int
checkd(d)
int d;
checkd(int d)
{
if (d0 != d)
swap;
@ -108,7 +105,7 @@ checkd(d)
}
int
last()
last(void)
{
int i;
@ -119,8 +116,7 @@ last()
}
void
movback(i)
int i;
movback(int i)
{
int j;
@ -129,8 +125,7 @@ movback(i)
}
void
backone(i)
int i;
backone(int i)
{
board[p[i]] += cturn;
if (g[i] != home) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: save.c,v 1.13 2015/11/11 01:12:10 deraadt Exp $ */
/* $OpenBSD: save.c,v 1.14 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -46,8 +46,7 @@ static const char rec[] = "\" to recover your game.\n\n";
static const char cantrec[] = "Can't recover file: ";
void
save(n)
int n;
save(int n)
{
int fdesc;
char *fs;
@ -131,8 +130,7 @@ save(n)
}
void
recover(s)
const char *s;
recover(const char *s)
{
int fdesc;
@ -155,8 +153,7 @@ recover(s)
}
void
norec(s)
const char *s;
norec(const char *s)
{
const char *c;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: subs.c,v 1.20 2015/06/26 19:18:03 otto Exp $ */
/* $OpenBSD: subs.c,v 1.21 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -41,8 +41,7 @@ static const char plwhite[] = "Player is white, computer is red.";
static const char nocomp[] = "(No computer play.)";
void
errexit(s)
const char *s;
errexit(const char *s)
{
write(STDERR_FILENO, "\n", 1);
perror(s);
@ -50,7 +49,7 @@ errexit(s)
}
int
readc()
readc(void)
{
int c;
@ -71,7 +70,7 @@ readc()
}
void
proll()
proll(void)
{
if (d0)
swap;
@ -84,7 +83,7 @@ proll()
}
void
gwrite()
gwrite(void)
{
int r, c;
@ -120,7 +119,7 @@ gwrite()
}
int
quit()
quit(void)
{
move(20, 0);
clrtobot();
@ -138,8 +137,7 @@ quit()
}
int
yorn(special)
char special; /* special response */
yorn(char special)
{
char c;
int i;
@ -166,14 +164,13 @@ yorn(special)
}
void
wrhit(i)
int i;
wrhit(int i)
{
printw("Blot hit on %d.\n", i);
}
void
nexturn()
nexturn(void)
{
int c;
@ -190,9 +187,7 @@ nexturn()
}
void
getarg(argc,argv)
int argc;
char **argv;
getarg(int argc, char **argv)
{
int ch;
@ -252,7 +247,7 @@ usage(void)
}
void
init()
init(void)
{
int i;
@ -271,15 +266,14 @@ init()
}
void
wrscore()
wrscore(void)
{
printw("Score: %s %d, %s %d", color[1], rscore, color[0], wscore);
}
void
getout(dummy)
int dummy;
getout(int dummy)
{
/* go to bottom of screen */
move(23, 0);
@ -290,7 +284,7 @@ getout(dummy)
}
void
roll()
roll(void)
{
char c;
int row;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: table.c,v 1.8 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: table.c,v 1.9 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -70,8 +70,7 @@ static const struct state atmata[] = {
};
int
checkmove(ist)
int ist;
checkmove(int ist)
{
int curr, curc;
int j, n;
@ -154,9 +153,7 @@ dochar:
}
int
dotable(c, i)
char c;
int i;
dotable(char c, int i)
{
int a;
int test;
@ -236,7 +233,7 @@ dotable(c, i)
}
int
rsetbrd()
rsetbrd(void)
{
int i, j, n;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: teach.c,v 1.14 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: teach.c,v 1.15 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -30,6 +30,8 @@
*/
#include <err.h>
#include <unistd.h>
#include "back.h"
#include "tutor.h"
@ -47,12 +49,13 @@ const char *const contin[] = {
};
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int i;
if (pledge("stdio rpath tty exec", NULL) == -1)
err(1, "pledge");
signal(SIGINT, getout);
initcurses();
text(hello);
@ -111,7 +114,7 @@ main(argc, argv)
}
void
leave()
leave(void)
{
clear();
endwin();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ttext2.c,v 1.7 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: ttext2.c,v 1.8 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -114,8 +114,7 @@ const char *const lastch[] = {
0};
int
text(txt)
const char *const *txt;
text(const char *const *txt)
{
const char *const *begin;
const char *a;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tutor.c,v 1.6 2009/10/27 23:59:23 deraadt Exp $ */
/* $OpenBSD: tutor.c,v 1.7 2015/11/30 08:19:25 tb Exp $ */
/*
* Copyright (c) 1980, 1993
@ -35,7 +35,7 @@
static const char better[] = "That is a legal move, but there is a better one.\n";
void
tutor()
tutor(void)
{
int i, j, k;
int wrongans;