home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
game
/
think
/
chaos
/
src
/
arexxami.c
next >
Wrap
C/C++ Source or Header
|
1994-10-14
|
20KB
|
869 lines
/* Chaos: The Chess HAppening Organisation System V5.3
Copyright (C) 1993 Jochen Wiedmann
This program 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 2 of the License, or
(at your option) any later version.
This program 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$RCSfile: ARexxAmi.c,v $
$Revision: 3.2 $
$Date: 1994/10/11 20:44:56 $
This file contains the functions of the ARexx port. I don't expect them
to be interesting besides the Amiga.
Computer: Amiga 1200 Compiler: Dice 2.07.54 (3.0)
Author: Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Tel. 07123 / 14881
Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
*/
#ifndef CHAOS_H
#include "chaos.h"
#endif
#include <ctype.h>
#ifdef AMIGA
#ifndef AZTEC_C
SAVEDS ASM static ULONG ARexxCmdFunc(REG(a0) struct Hook *hook,
REG(a1) char *args[])
{ extern void MakeDisplay(void);
extern int EnableARexx;
extern int NoWindow;
ULONG result;
HOOKFUNC func = hook->h_SubEntry;
typedef ULONG (*MYHOOKFUNC)(char **);
if (!EnableARexx)
{ return(RETURN_ERROR);
}
result = (*((MYHOOKFUNC) func))(args);
if (!NoWindow)
{ MakeDisplay();
}
return(result);
}
#else /* AZTEC_C */
extern ULONG ARexxCmdFunc(struct Hook *, char **);
#asm
xref _geta4
xref _EnableARexx
xref _MakeDisplay
xref _NoWindow
_ARexxCmdFunc: move.l a4,-(sp)
jsr _geta4
move.l #10,d0
tst.l _EnableARexx
bne ARexxCmdFuncE
move.l a1,-(sp)
move.l 12(a0),a0
jsr (a0)
add.l #4,sp
tst.l _NoWindow
bne ARexxCmdFuncE
move.l d0,-(sp)
jsr _MakeDisplay
move.l (sp)+,d0
ARexxCmdFuncE: move.l (sp)+,a4
rts
#endasm
#endif /* AZTEC_C */
/*
NewTrnCmd creates a new tournament.
Inputs: NAME - the new tournament's name
FORCE - suppress asking the user for confirmation, if current
tournament isn't saved
*/
ULONG NewTrnCmd(char *args[])
{
if (!(ULONG)args[1] && !TestSaved)
{ return(RETURN_WARN);
}
DeleteTournament(args[0]);
return(RETURN_OK);
}
struct Hook NewTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
(HOOKFUNC) NewTrnCmd};
/*
LoadTrn loads a tournament
Inputs: FILE - the name of the file to be loaded
FORCE - suppress asking the user for confirmation, if current
tournament isn't saved
*/
ULONG LoadTrnCmd(char *args[])
{
if (!(ULONG)args[1] && !TestSaved)
{ return(RETURN_WARN);
}
return((ULONG) LoadTournament(args[0], NULL, NULL));
}
struct Hook LoadTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
(HOOKFUNC) LoadTrnCmd};
/*
SaveTrn saves a tournament
Inputs: FILE - the name of the file to be written
ICON - create an icon
*/
ULONG SaveTrnCmd(char *args[])
{ int makeicons = MakeIcons;
int result;
MakeIcons = (ULONG)args[1];
result = SaveTournament(args[0]);
MakeIcons = makeicons;
return((ULONG) (result ? RETURN_OK : RETURN_ERROR));
}
struct Hook SaveTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
(HOOKFUNC) SaveTrnCmd};
/*
AddPlrCmd adds a new player
Inputs: NAME - the players name
STREET, VILLAGE, CHESSCLUB, BIRTHDAY, PHONE, RATING, ELO
- the corresponding fields in the player structure
FLAGS - a string, that may contain the characters
s,j,w,a,b,c,d,e corresponding to the flags
TNFLAGSF_SENIOR, TNFLAGSF_JUNIOR, TNFLAGSF_WOMAN
and TNFLAGSFJUNIORA, ..., TNFLAGSF_JUNIORE
NOUSER - a flag which indicates, that the user should not be
asked
*/
static void getstr(char *dest, char *src, int maxlen, ULONG *result)
{ int len;
if (src != NULL)
{ len = strlen(src);
if (len > maxlen)
{ *result = RETURN_WARN;
strncpy(dest, src, maxlen);
dest[maxlen] = '\0';
}
else
{ strcpy(dest, src);
}
}
}
static int getflags(char *flagsstr, ULONG *result)
{ int flags = 0;
while (flagsstr != NULL && *flagsstr != '\0')
{ switch(ToLower((int) *flagsstr++))
{ case 's':
flags |= TNFLAGSF_SENIOR;
break;
case 'j':
flags |= TNFLAGSF_JUNIOR;
break;
case 'w':
flags |= TNFLAGSF_WOMAN;
break;
case 'a':
flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORA;
break;
case 'b':
flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORB;
break;
case 'c':
flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORC;
break;
case 'd':
flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORD;
break;
case 'e':
flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORE;
break;
default:
*result = RETURN_WARN;
}
if ((flags & TNFLAGSF_SENIOR) &&
(flags & TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORA|TNFLAGSF_JUNIORB|
TNFLAGSF_JUNIORC|TNFLAGSF_JUNIORD|TNFLAGSF_JUNIORE))
{ *result = RETURN_WARN;
}
}
return(flags);
}
ULONG AddPlrCmd(char *args[])
{ struct Player plr;
ULONG result = 0;
/*
Check, if we may enter new players.
*/
if (NumRounds >= 1 && RoundRobinTournament)
{ return(RETURN_ERROR);
}
if (NumRounds > 1 && SwissPairingTournament)
{ return(RETURN_ERROR);
}
if (NumRounds > 0)
{ if (!args[9] &&
!AskContinue((char *) GetChaosString(MSG_NEW_PLAYER_REQUEST)))
{ return(RETURN_ERROR);
}
}
memset(&plr, 0, sizeof(plr));
getstr(plr.Name, args[0], NAMELEN, &result);
if (result != 0)
{ return(RETURN_ERROR);
}
getstr(plr.Street, args[1], NAMELEN, &result);
getstr(plr.Village, args[2], NAMELEN, &result);
getstr(plr.ChessClub, args[3], NAMELEN, &result);
getstr(plr.BirthDay, args[4], NAMELEN, &result);
getstr(plr.PhoneNr, args[5], PHONENRLEN, &result);
getstr(plr.DWZ, args[6], DWZLEN, &result);
if (args[7] != NULL)
{ plr.ELO = *((ULONG *) args[7]);
}
plr.Flags = getflags(args[8], &result);
if (!CheckPlayerValid(&plr, !args[9]))
{ return(RETURN_ERROR);
}
if (!AddPlayer(&plr))
{ return(RETURN_ERROR);
}
return(result);
}
struct Hook AddPlrCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
(HOOKFUNC) AddPlrCmd};
/*
ModifyPlrCmd modifies a new player
Inputs: PLAYER - the players name
NAME, STREET, VILLAGE, CHESSCLUB, BIRTHDAY, PHONE, RATING, ELO
- the corresponding fields in the player structure
FLAGS - a string, that may contain the characters
s,j,w,a,b,c,d,e corresponding to the flags
TNFLAGSF_SENIOR, TNFLAGSF_JUNIOR, TNFLAGSF_WOMAN
and TNFLAGSFJUNIORA, ..., TNFLAGSF_JUNIORE
NOUSER - a flag which indicates, that the user should not be
asked
Note, that only those fields are modified, for which an argument is
supplied
*/
static struct Player *getplayer(char *arg)
{ struct Player *plr;
if (arg)
{ for (plr = (struct Player *) PlayerList.lh_Head;
plr->Tn_Node.ln_Succ != NULL;
plr = (struct Player *) plr->Tn_Node.ln_Succ)
{ if (Stricmp((STRPTR) plr->Name, (STRPTR) arg) == 0)
{ return(plr);
}
}
}
return(NULL);
}
ULONG ModifyPlrCmd(char *args[])
{ struct Player plr, *plrptr;
ULONG result = 0;
/*
Check, if we really may modify players
*/
if (!args[10] && NumRounds > 0 &&
!AskContinue((char *) GetChaosString(MSG_MODIFY_PLAYER_REQUEST)))
{ return(RETURN_ERROR);
}
if (plrptr = getplayer(args[0]))
{ memcpy(&plr, plrptr, sizeof(plr));
getstr(plr.Name, args[1], NAMELEN, &result);
getstr(plr.Street, args[2], NAMELEN, &result);
getstr(plr.Village, args[3], NAMELEN, &result);
getstr(plr.ChessClub, args[4], NAMELEN, &result);
getstr(plr.BirthDay, args[5], NAMELEN, &result);
getstr(plr.PhoneNr, args[6], PHONENRLEN, &result);
getstr(plr.DWZ, args[7], DWZLEN, &result);
if (args[7] != NULL)
{ plr.ELO = *((ULONG *) args[8]);
}
plr.Flags = getflags(args