aboutsummaryrefslogtreecommitdiff
path: root/gnu/games/chess/Xchess/message.c
blob: 8b85e9c77f83c969e1414e8e572fd6705518ae29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

/* This file contains code for X-CHESS.
   Copyright (C) 1986 Free Software Foundation, Inc.

This file is part of X-CHESS.

X-CHESS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the X-CHESS General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
X-CHESS, but only under the conditions described in the
X-CHESS General Public License.   A copy of this license is
supposed to have been given to you along with X-CHESS so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  */


/* RCS Info: $Revision: 1.4 $ on $Date: 86/11/26 12:10:22 $
 *           $Source: /users/faustus/xchess/RCS/message.c,v $
 * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
 *	Permission is granted to do anything with this code except sell it
 *	or remove this message.
 *
 * Do stuff with the message window.  Font 0 is the normal font, font 1
 * is large, and font 2 is normal red.
 */

#include "xchess.h"

#define MESSAGE_HEADER	"\n1  XChess Messages0\n"

void
message_init(win)
	windata *win;
{
	TxtGrab(win->display, win->messagewin, "xchess", win->medium, 
			win->textback.pixel, win->textcolor.pixel,
				win->cursorcolor.pixel);
	TxtAddFont(win->display, win->messagewin, 1, win->large, win->textcolor.pixel);
	TxtAddFont(win->display, win->messagewin, 2, win->medium, win->errortext.pixel);
	TxtAddFont(win->display, win->messagewin, 3, win->medium, win->playertext.pixel);

	TxtWriteStr(win->display, win->messagewin, MESSAGE_HEADER);
	return;
}

void
message_add(win, string, err)
	windata *win;
	char *string;
	bool err;
{
	if (err) {
		TxtWriteStr(win->display, win->messagewin, "2");
		TxtWriteStr(win->display, win->messagewin, string);
		TxtWriteStr(win->display, win->messagewin, "0");
		XBell(win->display, 50);
	} else
		TxtWriteStr(win->display, win->messagewin, string);

	XSync(win->display, 0);
	return;
}

void
message_send(win, event)
	windata *win;
	XEvent *event;
{
	XKeyEvent *ev = &event->xkey;
	KeySym keysym;
	windata *ow = (win == win1) ? win2 : win1;
	char buf[BSIZE], *s;
	int i;

	i = XLookupString(ev, buf, sizeof(buf) - 1, &keysym, &s);
	buf[i] = '\0';
	for (s = buf; *s; s++)
		if (*s == '\r')
			*s = '\n';
		else if (*s == '\177')
			*s = '';

	TxtWriteStr(win->display, win->messagewin, "3");
	TxtWriteStr(win->display, win->messagewin, buf);
	TxtWriteStr(win->display, win->messagewin, "0");
	XSync(win->display, 0);
	if (ow) {
		TxtWriteStr(ow->display, ow->messagewin, "3");
		TxtWriteStr(ow->display, ow->messagewin, buf);
		TxtWriteStr(ow->display, ow->messagewin, "0");
		XSync(ow->display, 0);
	}
	return;
}