-
Notifications
You must be signed in to change notification settings - Fork 5
/
usounds.c
182 lines (167 loc) · 4.7 KB
/
usounds.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* usounds.c -- sound handling for XBoard (through external player)
*
* Copyright 1991 by Digital Equipment Corporation, Maynard,
* Massachusetts.
*
* Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
* 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free
* Software Foundation, Inc.
*
* The following terms apply to Digital Equipment Corporation's copyright
* interest in XBoard:
* ------------------------------------------------------------------------
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* ------------------------------------------------------------------------
*
* The following terms apply to the enhanced version of XBoard
* distributed by the Free Software Foundation:
* ------------------------------------------------------------------------
*
* GNU XBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* GNU XBoard is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/. *
*
*------------------------------------------------------------------------
** See the file ChangeLog for a revision history. */
#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#else /* not STDC_HEADERS */
extern char *getenv();
# if HAVE_STRING_H
# include <string.h>
# else /* not HAVE_STRING_H */
# include <strings.h>
# endif /* not HAVE_STRING_H */
#endif /* not STDC_HEADERS */
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "common.h"
#include "frontend.h"
int
PlaySoundFile (char *name)
{
if(mute == 1) return 1;
if (*name == NULLCHAR) {
return 0;
} else if (strcmp(name, "$") == 0) {
putc(BELLCHAR, stderr);
} else {
char buf[2048];
char *prefix = "", *sep = "";
if(appData.soundProgram[0] == NULLCHAR) return 1;
if(!strchr(name, '/')) { prefix = appData.soundDirectory; sep = "/"; }
snprintf(buf, sizeof(buf), "%s '%s%s%s' &", appData.soundProgram, prefix, sep, name);
system(buf);
}
return 1;
}
void
RingBell ()
{
PlaySoundFile(appData.soundMove);
}
void
PlayIcsWinSound ()
{
PlaySoundFile(appData.soundIcsWin);
}
void
PlayIcsLossSound ()
{
PlaySoundFile(appData.soundIcsLoss);
}
void
PlayIcsDrawSound ()
{
PlaySoundFile(appData.soundIcsDraw);
}
void
PlayIcsUnfinishedSound ()
{
PlaySoundFile(appData.soundIcsUnfinished);
}
void
PlayAlarmSound ()
{
PlaySoundFile(appData.soundIcsAlarm);
}
void
PlayTellSound ()
{
PlaySoundFile(appData.soundTell);
}
int
Roar ()
{
return PlaySoundFile(appData.soundRoar);
}
void
PlaySoundForColor (ColorClass cc)
{
switch (cc) {
case ColorShout:
PlaySoundFile(appData.soundShout);
break;
case ColorSShout:
PlaySoundFile(appData.soundSShout);
break;
case ColorChannel1:
PlaySoundFile(appData.soundChannel1);
break;
case ColorChannel:
PlaySoundFile(appData.soundChannel);
break;
case ColorKibitz:
PlaySoundFile(appData.soundKibitz);
break;
case ColorTell:
PlaySoundFile(appData.soundTell);
break;
case ColorChallenge:
PlaySoundFile(appData.soundChallenge);
break;
case ColorRequest:
PlaySoundFile(appData.soundRequest);
break;
case ColorSeek:
PlaySoundFile(appData.soundSeek);
break;
case ColorNormal:
case ColorNone:
default:
break;
}
}