home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / game / think / chaos / src / arexxami.c next >
C/C++ Source or Header  |  1994-10-14  |  20KB  |  869 lines

  1. /*  Chaos:            The Chess HAppening Organisation System    V5.3
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: ARexxAmi.c,v $
  20.     $Revision: 3.2 $
  21.     $Date: 1994/10/11 20:44:56 $
  22.  
  23.     This file contains the functions of the ARexx port. I don't expect them
  24.     to be interesting besides the Amiga.
  25.  
  26.     Computer:    Amiga 1200            Compiler:    Dice 2.07.54 (3.0)
  27.  
  28.     Author:    Jochen Wiedmann
  29.         Am Eisteich 9
  30.       72555 Metzingen
  31.         Tel. 07123 / 14881
  32.         Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
  33. */
  34.  
  35.  
  36. #ifndef CHAOS_H
  37. #include "chaos.h"
  38. #endif
  39.  
  40. #include <ctype.h>
  41.  
  42.  
  43.  
  44. #ifdef AMIGA
  45. #ifndef AZTEC_C
  46. SAVEDS ASM static ULONG ARexxCmdFunc(REG(a0) struct Hook *hook,
  47.                      REG(a1) char *args[])
  48.  
  49. { extern void MakeDisplay(void);
  50.   extern int EnableARexx;
  51.   extern int NoWindow;
  52.   ULONG result;
  53.   HOOKFUNC func = hook->h_SubEntry;
  54.   typedef ULONG (*MYHOOKFUNC)(char **);
  55.  
  56.   if (!EnableARexx)
  57.   { return(RETURN_ERROR);
  58.   }
  59.   result = (*((MYHOOKFUNC) func))(args);
  60.   if (!NoWindow)
  61.   { MakeDisplay();
  62.   }
  63.   return(result);
  64. }
  65. #else    /*  AZTEC_C */
  66. extern ULONG ARexxCmdFunc(struct Hook *, char **);
  67. #asm
  68.         xref    _geta4
  69.         xref    _EnableARexx
  70.         xref    _MakeDisplay
  71.         xref    _NoWindow
  72. _ARexxCmdFunc:    move.l    a4,-(sp)
  73.         jsr    _geta4
  74.         move.l    #10,d0
  75.         tst.l    _EnableARexx
  76.         bne    ARexxCmdFuncE
  77.         move.l    a1,-(sp)
  78.         move.l    12(a0),a0
  79.         jsr    (a0)
  80.         add.l    #4,sp
  81.         tst.l    _NoWindow
  82.         bne    ARexxCmdFuncE
  83.         move.l    d0,-(sp)
  84.         jsr    _MakeDisplay
  85.         move.l    (sp)+,d0
  86. ARexxCmdFuncE:    move.l    (sp)+,a4
  87.         rts
  88. #endasm
  89. #endif    /*  AZTEC_C */
  90.  
  91.  
  92.  
  93.  
  94. /*
  95.     NewTrnCmd creates a new tournament.
  96.  
  97.     Inputs: NAME  - the new tournament's name
  98.         FORCE - suppress asking the user for confirmation, if current
  99.             tournament isn't saved
  100. */
  101. ULONG NewTrnCmd(char *args[])
  102.  
  103. {
  104.   if (!(ULONG)args[1]  &&  !TestSaved)
  105.   { return(RETURN_WARN);
  106.   }
  107.  
  108.   DeleteTournament(args[0]);
  109.   return(RETURN_OK);
  110. }
  111. struct Hook NewTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  112.                  (HOOKFUNC) NewTrnCmd};
  113.  
  114.  
  115.  
  116.  
  117. /*
  118.     LoadTrn loads a tournament
  119.  
  120.     Inputs: FILE  - the name of the file to be loaded
  121.         FORCE - suppress asking the user for confirmation, if current
  122.             tournament isn't saved
  123. */
  124. ULONG LoadTrnCmd(char *args[])
  125.  
  126. {
  127.   if (!(ULONG)args[1]  &&  !TestSaved)
  128.   { return(RETURN_WARN);
  129.   }
  130.  
  131.   return((ULONG) LoadTournament(args[0], NULL, NULL));
  132. }
  133. struct Hook LoadTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc, 
  134.                   (HOOKFUNC) LoadTrnCmd};
  135.  
  136.  
  137.  
  138.  
  139. /*
  140.     SaveTrn saves a tournament
  141.  
  142.     Inputs: FILE  - the name of the file to be written
  143.         ICON  - create an icon
  144. */
  145. ULONG SaveTrnCmd(char *args[])
  146.  
  147. { int makeicons = MakeIcons;
  148.   int result;
  149.  
  150.   MakeIcons = (ULONG)args[1];
  151.   result = SaveTournament(args[0]);
  152.   MakeIcons = makeicons;
  153.   return((ULONG) (result ? RETURN_OK : RETURN_ERROR));
  154. }
  155. struct Hook SaveTrnCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  156.                   (HOOKFUNC) SaveTrnCmd};
  157.  
  158.  
  159.  
  160.  
  161. /*
  162.     AddPlrCmd adds a new player
  163.  
  164.     Inputs: NAME    - the players name
  165.         STREET, VILLAGE, CHESSCLUB, BIRTHDAY, PHONE, RATING, ELO
  166.             - the corresponding fields in the player structure
  167.         FLAGS   - a string, that may contain the characters
  168.               s,j,w,a,b,c,d,e corresponding to the flags
  169.               TNFLAGSF_SENIOR, TNFLAGSF_JUNIOR, TNFLAGSF_WOMAN
  170.               and TNFLAGSFJUNIORA, ..., TNFLAGSF_JUNIORE
  171.         NOUSER  - a flag which indicates, that the user should not be
  172.               asked
  173. */
  174. static void getstr(char *dest, char *src, int maxlen, ULONG *result)
  175. { int len;
  176.  
  177.   if (src != NULL)
  178.   { len = strlen(src);
  179.  
  180.     if (len > maxlen)
  181.     { *result = RETURN_WARN;
  182.       strncpy(dest, src, maxlen);
  183.       dest[maxlen] = '\0';
  184.     }
  185.     else
  186.     { strcpy(dest, src);
  187.     }
  188.   }
  189. }
  190. static int getflags(char *flagsstr, ULONG *result)
  191. { int flags = 0;
  192.  
  193.   while (flagsstr != NULL  &&  *flagsstr != '\0')
  194.   { switch(ToLower((int) *flagsstr++))
  195.     { case 's':
  196.     flags |= TNFLAGSF_SENIOR;
  197.     break;
  198.       case 'j':
  199.     flags |= TNFLAGSF_JUNIOR;
  200.     break;
  201.       case 'w':
  202.     flags |= TNFLAGSF_WOMAN;
  203.     break;
  204.       case 'a':
  205.     flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORA;
  206.     break;
  207.       case 'b':
  208.     flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORB;
  209.     break;
  210.       case 'c':
  211.     flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORC;
  212.     break;
  213.       case 'd':
  214.     flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORD;
  215.     break;
  216.       case 'e':
  217.     flags |= TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORE;
  218.     break;
  219.       default:
  220.     *result = RETURN_WARN;
  221.     }
  222.     if ((flags & TNFLAGSF_SENIOR)  &&
  223.     (flags & TNFLAGSF_JUNIOR|TNFLAGSF_JUNIORA|TNFLAGSF_JUNIORB|
  224.          TNFLAGSF_JUNIORC|TNFLAGSF_JUNIORD|TNFLAGSF_JUNIORE))
  225.     { *result = RETURN_WARN;
  226.     }
  227.   }
  228.   return(flags);
  229. }
  230. ULONG AddPlrCmd(char *args[])
  231.  
  232. { struct Player plr;
  233.   ULONG result = 0;
  234.  
  235.   /*
  236.       Check, if we may enter new players.
  237.   */
  238.   if (NumRounds >= 1 &&  RoundRobinTournament)
  239.   { return(RETURN_ERROR);
  240.   }
  241.   if (NumRounds > 1  &&  SwissPairingTournament)
  242.   { return(RETURN_ERROR);
  243.   }
  244.   if (NumRounds > 0)
  245.   { if (!args[9]  &&
  246.     !AskContinue((char *) GetChaosString(MSG_NEW_PLAYER_REQUEST)))
  247.     { return(RETURN_ERROR);
  248.     }
  249.   }
  250.  
  251.  
  252.   memset(&plr, 0, sizeof(plr));
  253.   getstr(plr.Name, args[0], NAMELEN, &result);
  254.   if (result != 0)
  255.   { return(RETURN_ERROR);
  256.   }
  257.   getstr(plr.Street, args[1], NAMELEN, &result);
  258.   getstr(plr.Village, args[2], NAMELEN, &result);
  259.   getstr(plr.ChessClub, args[3], NAMELEN, &result);
  260.   getstr(plr.BirthDay, args[4], NAMELEN, &result);
  261.   getstr(plr.PhoneNr, args[5], PHONENRLEN, &result);
  262.   getstr(plr.DWZ, args[6], DWZLEN, &result);
  263.   if (args[7] != NULL)
  264.   { plr.ELO = *((ULONG *) args[7]);
  265.   }
  266.   plr.Flags = getflags(args[8], &result);
  267.  
  268.   if (!CheckPlayerValid(&plr, !args[9]))
  269.   { return(RETURN_ERROR);
  270.   }
  271.  
  272.   if (!AddPlayer(&plr))
  273.   { return(RETURN_ERROR);
  274.   }
  275.   return(result);
  276. }
  277. struct Hook AddPlrCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  278.                  (HOOKFUNC) AddPlrCmd};
  279.  
  280.  
  281.  
  282.  
  283. /*
  284.     ModifyPlrCmd modifies a new player
  285.  
  286.     Inputs: PLAYER  - the players name
  287.         NAME, STREET, VILLAGE, CHESSCLUB, BIRTHDAY, PHONE, RATING, ELO
  288.             - the corresponding fields in the player structure
  289.         FLAGS   - a string, that may contain the characters
  290.               s,j,w,a,b,c,d,e corresponding to the flags
  291.               TNFLAGSF_SENIOR, TNFLAGSF_JUNIOR, TNFLAGSF_WOMAN
  292.               and TNFLAGSFJUNIORA, ..., TNFLAGSF_JUNIORE
  293.         NOUSER  - a flag which indicates, that the user should not be
  294.               asked
  295.  
  296.     Note, that only those fields are modified, for which an argument is
  297.     supplied
  298. */
  299. static struct Player *getplayer(char *arg)
  300. { struct Player *plr;
  301.  
  302.   if (arg)
  303.   { for (plr = (struct Player *) PlayerList.lh_Head;
  304.      plr->Tn_Node.ln_Succ != NULL;
  305.      plr = (struct Player *) plr->Tn_Node.ln_Succ)
  306.     { if (Stricmp((STRPTR) plr->Name, (STRPTR) arg)  ==  0)
  307.       { return(plr);
  308.       }
  309.     }
  310.   }
  311.   return(NULL);
  312. }
  313. ULONG ModifyPlrCmd(char *args[])
  314.  
  315. { struct Player plr, *plrptr;
  316.   ULONG result = 0;
  317.  
  318.   /*
  319.       Check, if we really may modify players
  320.   */
  321.   if (!args[10]  &&  NumRounds > 0  &&
  322.       !AskContinue((char *) GetChaosString(MSG_MODIFY_PLAYER_REQUEST)))
  323.   { return(RETURN_ERROR);
  324.   }
  325.  
  326.   if (plrptr = getplayer(args[0]))
  327.   { memcpy(&plr, plrptr, sizeof(plr));
  328.     getstr(plr.Name, args[1], NAMELEN, &result);
  329.     getstr(plr.Street, args[2], NAMELEN, &result);
  330.     getstr(plr.Village, args[3], NAMELEN, &result);
  331.     getstr(plr.ChessClub, args[4], NAMELEN, &result);
  332.     getstr(plr.BirthDay, args[5], NAMELEN, &result);
  333.     getstr(plr.PhoneNr, args[6], PHONENRLEN, &result);
  334.     getstr(plr.DWZ, args[7], DWZLEN, &result);
  335.     if (args[7] != NULL)
  336.     { plr.ELO = *((ULONG *) args[8]);
  337.     }
  338.     plr.Flags = getflags(args