jcs's openbsd hax
openbsd
1/* $OpenBSD: back.h,v 1.15 2015/12/26 00:26:39 mestre Exp $ */
2
3/*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)back.h 8.1 (Berkeley) 5/31/93
32 */
33
34#include <sys/types.h>
35#include <sys/uio.h>
36
37#include <curses.h>
38#include <fcntl.h>
39#include <signal.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <term.h>
44#include <unistd.h>
45
46#define rnum(r) arc4random_uniform(r)
47#define D0 dice[0]
48#define D1 dice[1]
49#define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
50
51#define CIN_SIZE 40
52
53#ifdef DEBUG
54extern FILE *ftrace;
55#endif
56
57/*
58 *
59 * Some numerical conventions:
60 *
61 * Arrays have white's value in [0], red in [1].
62 * Numeric values which are one color or the other use
63 * -1 for white, 1 for red.
64 * Hence, white will be negative values, red positive one.
65 * This makes a lot of sense since white is going in decending
66 * order around the board, and red is ascending.
67 *
68 */
69
70extern const char EXEC[]; /* object for main program */
71extern const char TEACH[]; /* object for tutorial program */
72
73extern int pnum; /* color of player:
74 -1 = white
75 1 = red
76 0 = both
77 2 = not yet init'ed */
78extern int aflag; /* flag to ask for rules or instructions */
79extern int cflag; /* case conversion flag */
80extern int hflag; /* flag for cleaning screen */
81extern int mflag; /* backgammon flag */
82extern int raflag; /* 'roll again' flag for recovered game */
83extern int rflag; /* recovered game flag */
84extern int dflag; /* disable doubling flag */
85extern int rfl; /* saved value of rflag */
86extern int iroll; /* special flag for inputting rolls */
87extern int board[26]; /* board: negative values are white,
88 positive are red */
89extern int dice[2]; /* value of dice */
90extern int mvlim; /* 'move limit': max. number of moves */
91extern int mvl; /* working copy of mvlim */
92extern int p[5]; /* starting position of moves */
93extern int g[5]; /* ending position of moves (goals) */
94extern int h[4]; /* flag for each move if a man was hit */
95extern int cturn; /* whose turn it currently is:
96 -1 = white
97 1 = red
98 0 = just quit
99 -2 = white just lost
100 2 = red just lost */
101extern int d0; /* flag if dice have been reversed from
102 original position */
103extern int table[6][6]; /* odds table for possible rolls */
104extern int rscore; /* red's score */
105extern int wscore; /* white's score */
106extern int gvalue; /* value of game (64 max.) */
107extern int dlast; /* who doubled last (0 = neither) */
108extern int bar; /* position of bar for current player */
109extern int home; /* position of home for current player */
110extern int off[2]; /* number of men off board */
111extern int *offptr; /* pointer to off for current player */
112extern int *offopp; /* pointer to off for opponent */
113extern int in[2]; /* number of men in inner table */
114extern int *inptr; /* pointer to in for current player */
115extern int *inopp; /* pointer to in for opponent */
116
117extern int ncin; /* number of characters in cin */
118extern char cin[CIN_SIZE]; /* input line of current move
119 (used for reconstructing input after
120 a backspace) */
121
122extern const char *const color[]; /* colors as strings */
123extern const char *const *colorptr; /* color of current player */
124extern const char *const *Colorptr; /* color of current player,
125 * capitalized */
126extern int colen; /* length of color of current player */
127
128extern int begscr; /* 'beginning' of screen
129 (not including board) */
130
131int addbuf(int);
132void backone(int);
133void bsect(int, int, int, int);
134int canhit(int, int);
135int checkd(int);
136int checkmove(int);
137int count(void);
138int dotable(char, int);
139void errexit(const char *);
140void fboard(void);
141void fixcol(int, int, int, int, int);
142void fixpos(int, int, int, int, int);
143void getarg(int, char **);
144void getmove(void);
145__dead void getout(int); /* function to exit backgammon cleanly */
146void gwrite(void);
147void init(void);
148void initcurses(void);
149int last(void);
150int makmove(int);
151int movallow(void);
152void movback(int);
153void moveplayers(void);
154void moverr(int);
155int movokay(int);
156void nexturn(void);
157void norec(const char *);
158void odds(int, int, int);
159void proll(void);
160int quit(void);
161int readc(void);
162void recover(const char *);
163void roll(void);
164int rsetbrd(void);
165void save(int);
166int text(const char *const *);
167void wrboard(void);
168void wrhit(int);
169void wrscore(void);
170int yorn(char);