home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / szachy / chaos / src / arexxami.c next >
C/C++ Source or Header  |  1995-05-09  |  21KB  |  879 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: jochen.wiedmann@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 *) 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 *) 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[9], &result);
  339.  
  340.     { int result;
  341.  
  342.       Remove((struct Node *) plrptr);
  343.       result = CheckPlayerValid(&plr, !args[10]);
  344.       Insert(&PlayerList, (struct Node *) plrptr,
  345.          (struct Node *) plrptr->Tn_Node.ln_Pred);
  346.       if (!result)
  347.       { return(RETURN_ERROR);
  348.       }
  349.     }
  350.  
  351.     ModifyPlayer(plrptr, &plr);
  352.     return(result);
  353.   }
  354.   return(RETURN_ERROR);
  355. }
  356. struct Hook ModifyPlrCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  357.                 (HOOKFUNC) ModifyPlrCmd};
  358.  
  359.  
  360.  
  361.  
  362. /*
  363.     DelPlrCmd deletes a player
  364.  
  365.     Inputs: PLAYER - the players name
  366.         FORCE  - suppresses asking the user for confirmation
  367. */
  368. ULONG DelPlrCmd(char *args[])
  369.  
  370. { struct Player *plrptr;
  371.  
  372.   if ((NumRounds > 0  &&  RoundRobinTournament)  ||
  373.       (NumGamesMissing > 0  &&  SwissPairingTournament))
  374.   { return(RETURN_ERROR);
  375.   }
  376.  
  377.   if (plrptr = getplayer(args[0]))
  378.   { if ((plrptr->Flags & TNFLAGSF_WITHDRAWN)  ||
  379.     (!(ULONG)args[1]  &&
  380.      !AskContinue((char *) (NumRounds == 0)  ?
  381.                     MSG_DELETE_THIS_PLAYER_REQUEST  :
  382.                     MSG_THIS_PLAYER_GONE_REQUEST,
  383.               plrptr->Name)))
  384.     { return(RETURN_WARN);
  385.     }
  386.     DeletePlayer(plrptr);
  387.   }
  388.   return(RETURN_ERROR);
  389. }
  390. struct Hook DelPlrCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  391.                  (HOOKFUNC) DelPlrCmd};
  392.  
  393.  
  394.  
  395.  
  396. /*
  397.     SetPlrCmd sets a player
  398.  
  399.     Inputs: PLAYER   - the player, that should be set
  400.         INIT     - discard set players
  401.         FORCE    - suppresses asking the user for confirmation, if
  402.                players should be paired, that had the same color
  403.                in the last two rounds
  404.         SETCOLOR - colors are determined by the order of entering the
  405.                players
  406. */
  407. static ULONG SetPlrCmd(char **args)
  408.  
  409. { struct Player *plr;
  410.  
  411.   if (args[1]  &&  !InitSetGames())
  412.     { return(RETURN_ERROR);
  413.     }
  414.   if (!args[0])
  415.   { return ((ULONG) (args[1] ? RETURN_OK : RETURN_ERROR));
  416.   }
  417.   if (!(plr = getplayer(args[0])))
  418.   { return(RETURN_ERROR);
  419.   }
  420.   return((ULONG) (SetPlayer(plr, (int) args[2], (int) args[3])  ?
  421.             RETURN_OK  :  RETURN_ERROR));
  422. }
  423. struct Hook SetPlrCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  424.                  (HOOKFUNC) SetPlrCmd};
  425.  
  426.  
  427.  
  428.  
  429. /*
  430.     DoPairingsCmd creates a new round
  431.  
  432.     Inputs: SWISSPAIRING    - create a swiss pairing tournament
  433.         ROUNDROBIN      - create a round robin tournament (FIDE system)
  434.         ROUNDROBINSHIFT - create a round robin tournament (shift system)
  435.         NOUSER          - suppresses setting games by the user
  436. */
  437. static ULONG DoPairingsCmd(char *args[])
  438.  
  439. { int mode = TrnMode;
  440.  
  441.   if (args[0])
  442.   { if (RoundRobinTournament  ||  args[1]  ||  args[2])
  443.     { return(RETURN_ERROR);
  444.     }
  445.     else
  446.     { mode = TNMODEF_SWISS_PAIRING;
  447.     }
  448.   }
  449.  
  450.   if (args[1])
  451.   { if ((TrnMode & (TNMODEF_SWISS_PAIRING|TNMODEF_SHIFT_SYSTEM))  ||
  452.     args[2])
  453.     { return(RETURN_ERROR);
  454.     }
  455.     else
  456.     { mode = TNMODEF_ROUND_ROBIN;
  457.     }
  458.   }
  459.  
  460.   if (args[2])
  461.   { if (SwissPairingTournament  ||
  462.     (TrnMode & (TNMODEF_ROUND_ROBIN|TNMODEF_SHIFT_SYSTEM)
  463.             == TNMODEF_ROUND_ROBIN))
  464.     { return(RETURN_ERROR);
  465.     }
  466.     else
  467.     { mode = TNMODEF_ROUND_ROBIN|TNMODEF_SHIFT_SYSTEM;
  468.     }
  469.   }
  470.  
  471.   if (mode == 0)
  472.   { return(RETURN_ERROR);
  473.   }
  474.  
  475.   return((ULONG) (DoPairings(mode, FALSE, !(int) args[3]) ? 0 : RETURN_ERROR));
  476. }
  477. struct Hook DoPairingsCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  478.                  (HOOKFUNC) DoPairingsCmd};
  479.  
  480.  
  481.  
  482.  
  483. /*
  484.     RsltCmd allows to enter a result
  485.  
  486.     Inputs: WHITE     - the white players name
  487.         BLACK     - the black players name
  488.         RESULT    - the result (-1 = result missing, 0 = black wins,
  489.             1 = draw, 2 = white wins)
  490.         NOTPLAYED - indicates, that the game wasn't really played
  491. */
  492. ULONG RsltCmd(char *args[])
  493.  
  494. { struct Game *gm;
  495.   struct GameNode gn;
  496.   int round;
  497.  
  498.   if (NumRounds == 0  ||  (ULONG)args[2] < -1  ||  (ULONG)args[2] > 2)
  499.   { return(RETURN_ERROR);
  500.   }
  501.  
  502.   for(gn.White = (struct Player *) PlayerList.lh_Head;
  503.       gn.White->Tn_Node.ln_Succ != NULL;
  504.       gn.White = (struct Player *) gn.White->Tn_Node.ln_Succ)
  505.   { if (Stricmp((STRPTR) gn.White->Name, (STRPTR) args[0])  ==  0)
  506.     { for (gm = gn.White->First_Game, round = 1;  gm != NULL;
  507.        gm = gm->Next, round++)
  508.       { if (Stricmp((STRPTR) gm->Opponent->Name, (STRPTR) args[1])  ==  0)
  509.     { gn.Result = *(ULONG *)args[2];
  510.       gn.Flags = (ULONG)args[3] ? GMFLAGSF_NOFIGHT : 0;
  511.       gn.Black = gm->Opponent;
  512.       EnterResult(&gn, round);
  513.     }
  514.       }
  515.       break;
  516.     }
  517.   }
  518.   return(RETURN_ERROR);
  519. }
  520. struct Hook RsltCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  521.                (HOOKFUNC) RsltCmd};
  522.  
  523.  
  524.  
  525.  
  526. /*
  527.     PlrLstCmd prints the list of players
  528.  
  529.     Inputs: FILE  - the file, which should receive the output
  530.         SHORT - makes the output short
  531. */
  532. static int getdevice(char *devicestr)
  533. { int device = DEVICE_FileAscii;
  534.  
  535.   if (Stricmp((STRPTR) devicestr, (STRPTR) "prt:")  ==  0)
  536.   { device = DEVICE_PrinterDraft;
  537.   }
  538.   else if (Stricmp((STRPTR) devicestr, (STRPTR) "prt:LQ")  ==  0)
  539.   { device = DEVICE_PrinterLQ;
  540.   }
  541.   return(device);
  542. }
  543. ULONG PlrLstCmd(char *args[])
  544.  
  545. { extern int OutputReturnCode;
  546.  
  547.   if (NumPlayers == 0)
  548.   { return(RETURN_ERROR);
  549.   }
  550.  
  551.   OutPlayerList(args[0], getdevice(args[0]), !(ULONG)args[1]);
  552.   return((ULONG) OutputReturnCode);
  553. }
  554. struct Hook PlrLstCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  555.                  (HOOKFUNC) PlrLstCmd};
  556.  
  557.  
  558.  
  559.  
  560. /*
  561.     IntRatCmd prints the internal rankings.
  562.  
  563.     Inputs: FILE  - the file, which should receive the output
  564. */
  565. ULONG IntRatCmd(char *args[])
  566.  
  567. { extern int OutputReturnCode;
  568.  
  569.   if (NumPlayers == 0)
  570.   { return(RETURN_ERROR);
  571.   }
  572.  
  573.   OutInternalRankings(args[0], getdevice(args[0]));
  574.   return((ULONG) OutputReturnCode);
  575. }
  576. struct Hook IntRatCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  577.                  (HOOKFUNC) IntRatCmd};
  578.  
  579.  
  580.  
  581.  
  582. /*
  583.     TblCmd prints the table.
  584.  
  585.     Inputs: FILE    - the file, which should receive the output
  586.         TABMODE - the table's sorting mode (0 = simple, 1 = Buchholz,
  587.               2 = Extended Buchholz, 3 = Sonneborn-Berger)
  588.               default is simple
  589.         PLRMODE - the code, which players should be included into the
  590.               table (0 = all, 1 = seniors, 2 = juniors, 3 = women,
  591.               4 = juniors (A), 5 = juniors (B), 6 = juniors (C),
  592.               7 = juniors (D), 8 = juniors (E))
  593.               default is all players
  594. */
  595. int gettabmode(ULONG *mode)
  596. { int tabmode = 0;
  597.  
  598.   if (mode != NULL)
  599.   { switch(*mode)
  600.     { case 0:
  601.     break;
  602.       case 1:
  603.     if (RoundRobinTournament)
  604.     { return(-1);
  605.     }
  606.     tabmode = TNMODEF_BUCHHOLZ;
  607.     break;
  608.       case 2:
  609.     if (RoundRobinTournament)
  610.     { return(-1);
  611.     }
  612.     tabmode = TNMODEF_EXT_BUCHHOLZ;
  613.     break;
  614.       case 3:
  615.     if (!SwissPairingTournament)
  616.     { tabmode = TNMODEF_SONNEBORN_BERGER;
  617.       break;
  618.     }
  619.       default:
  620.     return(-1);
  621.     }
  622.   }
  623.   return(tabmode);
  624. }
  625. ULONG TblCmd(char *args[])
  626.  
  627. { extern int OutputReturnCode;
  628.   int plrmode = 0;
  629.   int tabmode;
  630.  
  631.   if (NumRounds == 0)
  632.   { return(RETURN_ERROR);
  633.   }
  634.  
  635.   if ((tabmode = gettabmode((ULONG *) args[1]))  == -1)
  636.   { return(RETURN_ERROR);
  637.   }
  638.  
  639.   if (args[2])
  640.   { switch(*(ULONG *)args[2])
  641.     { case 0:
  642.     break;
  643.       case 1:
  644.     plrmode = TNFLAGSF_SENIOR;
  645.     break;
  646.       case 2:
  647.     plrmode = TNFLAGSF_JUNIOR;
  648.     break;
  649.       case 3:
  650.     plrmode = TNFLAGSF_WOMAN;
  651.     break;
  652.       case 4:
  653.     plrmode = TNFLAGSF_JUNIORA;
  654.     break;
  655.       case 5:
  656.     plrmode = TNFLAGSF_JUNIORB;
  657.     break;
  658.       case 6:
  659.     plrmode = TNFLAGSF_JUNIORC;
  660.     break;
  661.       case 7:
  662.     plrmode = TNFLAGSF_JUNIORD;
  663.     break;
  664.       case 8:
  665.     plrmode = TNFLAGSF_JUNIORE;
  666.     break;
  667.       default:
  668.     return(RETURN_ERROR);
  669.     }
  670.   }
  671.  
  672.   OutTable(args[0], getdevice(args[0]), plrmode, tabmode);
  673.   return((ULONG) OutputReturnCode);
  674. }
  675. struct Hook TblCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  676.               (HOOKFUNC) TblCmd};
  677.  
  678.  
  679.  
  680.  
  681. /*
  682.     RndCmd prints the results of one round
  683.  
  684.     Inputs: FILE  - the file, which should receive the output
  685.         ROUND - the number of the round (default is the last round)
  686. */
  687. ULONG RndCmd(char *args[])
  688.  
  689. { extern int OutputReturnCode;
  690.   int round;
  691.  
  692.  
  693.   if ((round = NumRounds) == 0)
  694.   { return(RETURN_ERROR);
  695.   }
  696.  
  697.   if (args[1]  &&
  698.       ((round = *(ULONG *)args[1]) <= 0  ||  round > NumRounds))
  699.   { return(RETURN_ERROR);
  700.   }
  701.  
  702.   OutRound(args[0], getdevice(args[0]), round);
  703.   return((ULONG) OutputReturnCode);
  704. }
  705. struct Hook RndCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  706.               (HOOKFUNC) RndCmd};
  707.  
  708.  
  709.  
  710.  
  711. /*
  712.     TblPrgrssCmd prints the table of progress
  713.  
  714.     Inputs: FILE    - the file, which should receive the output
  715.         TABMODE - the table's sorting mode (see TblCmd)
  716. */
  717. ULONG TblPrgrssCmd(char *args[])
  718.  
  719. { extern int OutputReturnCode;
  720.   int tabmode = 0;
  721.  
  722.   if (NumRounds == 0)
  723.   { return(RETURN_ERROR);
  724.   }
  725.  
  726.   if ((tabmode = gettabmode((ULONG *) args[1]))  == -1)
  727.   { return(RETURN_ERROR);
  728.   }
  729.  
  730.   OutTableProgress(args[0], getdevice(args[0]), tabmode);
  731.   return((ULONG) OutputReturnCode);
  732. }
  733. struct Hook TblPrgrssCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  734.                 (HOOKFUNC) TblPrgrssCmd};
  735.  
  736.  
  737.  
  738.  
  739. /*
  740.     CrossTableCmd prints a crosstable
  741.  
  742.     Inputs: FILE - the file, which should receive the output
  743.         TEX  - creates tex source
  744. */
  745. ULONG CrssTblCmd(char *args[])
  746.  
  747. { int device = getdevice(args[0]);
  748.  
  749.   if (!RoundRobinTournament)
  750.   { return (RETURN_ERROR);
  751.   }
  752.   if (args[1])
  753.   { device = DEVICE_FileTeX;
  754.   }
  755.  
  756.   OutCrossTable(args[0], device);
  757.   return((ULONG) OutputReturnCode);
  758. }
  759. struct Hook CrssTblCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  760.                   (HOOKFUNC) CrssTblCmd};
  761.  
  762.  
  763.  
  764.  
  765. /*
  766.     PlrCrdsCmd prints player cards
  767.  
  768.     Inputs: FILE - the file, which should receive the output
  769.         TEX  - creates tex source
  770. */
  771. ULONG PlrCrdsCmd(char *args[])
  772.  
  773. { int device = getdevice(args[0]);
  774.  
  775.   if (!SwissPairingTournament)
  776.   { return(RETURN_ERROR);
  777.   }
  778.   if (args[1])
  779.   { device = DEVICE_FileTeX;
  780.   }
  781.  
  782.   OutPlayerCards(args[0], device);
  783.   return((ULONG) OutputReturnCode);
  784. }
  785. struct Hook PlrCrdsCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  786.                   (HOOKFUNC) PlrCrdsCmd};
  787.  
  788.  
  789.  
  790.  
  791. /*
  792.     DWZRprtCmd prints the DWZ report
  793.  
  794.     Inputs: FILE - the file, which should receive the output
  795. */
  796. ULONG DWZRprtCmd(char *args[])
  797.  
  798. {
  799.   if (NumRounds == 0)
  800.   { return(RETURN_ERROR);
  801.   }
  802.  
  803.   OutDWZReport(args[0], getdevice(args[0]));
  804.   return((ULONG) OutputReturnCode);
  805. }
  806. struct Hook DWZRprtCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  807.                   (HOOKFUNC) DWZRprtCmd};
  808.  
  809.  
  810.  
  811.  
  812. /*
  813.     WindowCmd switches the main window on or off
  814.  
  815.     Inputs: ON  - switch the window on
  816.         OFF - switch it off
  817. */
  818. ULONG WindowCmd(char *args[])
  819.  
  820. { extern int NoWindow;
  821.   int open;
  822.  
  823.   if (args[0] == args[1])
  824.   { return(RETURN_ERROR);
  825.   }
  826.   NoWindow = (int) args[1];
  827.   get(MainWnd, MUIA_Window_Open, &open);
  828.   if (!open != NoWindow)
  829.   { set(MainWnd, MUIA_Window_Open, !open);
  830.   }
  831.   return(RETURN_OK);
  832. }
  833. struct Hook WindowCmdHook = {{NULL, NULL}, (HOOKFUNC) ARexxCmdFunc,
  834.                  (HOOKFUNC) WindowCmd};
  835.  
  836.  
  837.  
  838. struct MUI_Command ARexxCommands[] =
  839.   { {"NewTournament",   "NAME/A,FORCE/S",
  840.      2,  &NewTrnCmdHook,    NULL, NULL, NULL, NULL, NULL },
  841.     {"LoadTournament",  "FILE/A,FORCE/S",
  842.      2,  &LoadTrnCmdHook,   NULL, NULL, NULL, NULL, NULL },
  843.     {"SaveTournament",  "FILE/A,ICON/S",
  844.      1,  &SaveTrnCmdHook,   NULL, NULL, NULL, NULL, NULL },
  845.     {"AddPlayer",       "NAME/A,STREET/K,VILLAGE/K,CHESSCLUB/K,BIRTHDAY/K,PHONE/K,RATING/K,ELO/K/N,FLAGS/K,NOUSER/S",
  846.      9,  &AddPlrCmdHook,    NULL, NULL, NULL, NULL, NULL },
  847.     {"ModifyPlayer",    "PLAYER/A,NAME/K,STREET/K,VILLAGE/K,CHESSCLUB/K,BIRTHDAY/K,PHONE/K,RATING/K,ELO/K,FLAGS/K,NOUSER/S,",
  848.      10, &ModifyPlrCmdHook, NULL, NULL, NULL, NULL, NULL },
  849.     {"DeletePlayer",    "PLAYER/A,FORCE/S",
  850.      2,  &DelPlrCmdHook,    NULL, NULL, NULL, NULL, NULL },
  851.     {"SetPlayer",       "PLAYER,INIT/S,FORCE/S,SETCOLOR/S",
  852.      3,  &SetPlrCmdHook,    NULL, NULL, NULL, NULL, NULL },
  853.     {"DoPairings",      "SWISSPAIRING/S,ROUNDROBIN/S,ROUNDROBINSHIFT/S,NOUSER/S",
  854.      4,  &DoPairingsCmdHook,NULL, NULL, NULL, NULL, NULL },
  855.     {"EnterResult",     "WHITE/A,BLACK/A,RESULT/A/N,NOTPLAYED/S",
  856.      4,  &RsltCmdHook,      NULL, NULL, NULL, NULL, NULL },
  857.     {"PlayerList",      "FILE/A,SHORT/S",
  858.      3,  &PlrLstCmdHook,    NULL, NULL, NULL, NULL, NULL },
  859.     {"InternalRatings", "FILE/A",
  860.      1,  &IntRatCmdHook,    NULL, NULL, NULL, NULL, NULL },
  861.     {"Table",           "FILE/A,TABMODE/K/N,PLRMODE/K/N",
  862.      3,  &TblCmdHook,       NULL, NULL, NULL, NULL, NULL },
  863.     {"Round",           "FILE/A,NUMBER/N",
  864.      2,  &RndCmdHook,       NULL, NULL, NULL, NULL, NULL },
  865.     {"TableOfProgress", "FILE/A,TABMODE/K/N",
  866.      2,  &TblPrgrssCmdHook, NULL, NULL, NULL, NULL, NULL },
  867.     {"CrossTable",      "FILE/A,TEX/S",
  868.      2,  &CrssTblCmdHook,   NULL, NULL, NULL, NULL, NULL },
  869.     {"PlayerCards",     "FILE/A,TEX/S",
  870.      2,  &PlrCrdsCmdHook,   NULL, NULL, NULL, NULL, NULL },
  871.     {"DWZReport",       "FILE/A",
  872.      1,  &DWZRprtCmdHook,   NULL, NULL, NULL, NULL, NULL },
  873.     {"Window",          "ON/S,OFF/S",
  874.      2,  &WindowCmdHook,    NULL, NULL, NULL, NULL, NULL },
  875.     {NULL,              NULL,
  876.      0,  NULL,              NULL, NULL, NULL, NULL, NULL }
  877.   };
  878. #endif  /*  AMIGA   */
  879.