Skip to content

Commit

Permalink
Split usounds.c and usystem.c from xboard.c
Browse files Browse the repository at this point in the history
X-independent code was moved to separate files. The nef file usound.c
contains the sound handling, which in XBoard is trivial, because it uses
an external player, but could be replaced by a complex one on platforms
that have to handle the sound themselves.
  The usystem.c file contains all non-X Unix-like stuff, such as fork,
pipe, system, getenv. I also contains some color parsing for the xterm
colors. This stuff could be useful on platforms that support Unix-like
system calls.
  • Loading branch information
HGMuller committed Apr 10, 2012
1 parent dff5f0d commit 14bd89b
Show file tree
Hide file tree
Showing 8 changed files with 1,060 additions and 742 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ xboard_SOURCES = backend.c backend.h backendz.h \
pgntags.c \
uci.c \
xboard.c xboard.h args.h menus.c menus.h \
usounds.c usystem.c usystem.h \
board.c board.h \
xedittags.c xedittags.h \
engineoutput.c engineoutput.h \
Expand Down
2 changes: 0 additions & 2 deletions args.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ void SaveColor(FILE *f, ArgDescriptor *ad);
void SaveBoardSize(FILE *f, char *name, void *addr);
void PrintCommPortSettings(FILE *f, char *name);
void GetWindowCoords();
int MySearchPath(char *installDir, char *name, char *fullname);
int MyGetFullPathName(char *name, char *fullname);
int MainWindowUp();
void PopUpStartupDialog();
typedef char GetFunc(void *getClosure);
Expand Down
3 changes: 3 additions & 0 deletions frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ void PlayIcsDrawSound P((void));
void PlayIcsUnfinishedSound P((void));
void PlayAlarmSound P((void));
void PlayTellSound P((void));
void PlaySound P((char *name));
void PlaySoundByColor P((void));
void EchoOn P((void));
void EchoOff P((void));
void Raw P((void));
Expand Down Expand Up @@ -190,6 +192,7 @@ void EditTagsPopUp P((char *tags, char **dest));
void TagsPopUp P((char *tags, char *msg));
void TagsPopDown P((void));

void ParseIcsTextColors P((void));
void ICSInitScript P((void));
void StartAnalysisClock P((void));
void EngineOutputPopUp P((void));
Expand Down
176 changes: 176 additions & 0 deletions usounds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* 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 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"


void
PlaySound (char *name)
{
if (*name == NULLCHAR) {
return;
} else if (strcmp(name, "$") == 0) {
putc(BELLCHAR, stderr);
} else {
char buf[2048];
char *prefix = "", *sep = "";
if(appData.soundProgram[0] == NULLCHAR) return;
if(!strchr(name, '/')) { prefix = appData.soundDirectory; sep = "/"; }
snprintf(buf, sizeof(buf), "%s '%s%s%s' &", appData.soundProgram, prefix, sep, name);
system(buf);
}
}

void
RingBell ()
{
PlaySound(appData.soundMove);
}

void
PlayIcsWinSound ()
{
PlaySound(appData.soundIcsWin);
}

void
PlayIcsLossSound ()
{
PlaySound(appData.soundIcsLoss);
}

void
PlayIcsDrawSound ()
{
PlaySound(appData.soundIcsDraw);
}

void
PlayIcsUnfinishedSound ()
{
PlaySound(appData.soundIcsUnfinished);
}

void
PlayAlarmSound ()
{
PlaySound(appData.soundIcsAlarm);
}

void
PlayTellSound ()
{
PlaySound(appData.soundTell);
}

void
PlaySoundForColor (ColorClass cc)
{
switch (cc) {
case ColorShout:
PlaySound(appData.soundShout);
break;
case ColorSShout:
PlaySound(appData.soundSShout);
break;
case ColorChannel1:
PlaySound(appData.soundChannel1);
break;
case ColorChannel:
PlaySound(appData.soundChannel);
break;
case ColorKibitz:
PlaySound(appData.soundKibitz);
break;
case ColorTell:
PlaySound(appData.soundTell);
break;
case ColorChallenge:
PlaySound(appData.soundChallenge);
break;
case ColorRequest:
PlaySound(appData.soundRequest);
break;
case ColorSeek:
PlaySound(appData.soundSeek);
break;
case ColorNormal:
case ColorNone:
default:
break;
}
}


Loading

0 comments on commit 14bd89b

Please sign in to comment.