Check-in modifications made by HGM so far
[capablanca.git] / lasker-2.2.3 / src / iset.c
1 /*
2    Copyright (C) Andrew Tridgell 2002
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
20 #include "includes.h"
21
22 /*
23   set a boolean ivar
24 */
25 static int iset_bool(int p, unsigned *v, const char *var, const char *value)
26 {
27         if (strcmp(value, "1") == 0) {
28                 *v = 1;
29                 pprintf(p, "%s set\n", var);
30         } else if (strcmp(value, "0") == 0) {
31                 *v = 0;
32                 pprintf(p, "%s unset\n", var);
33         } else {
34                 pprintf(p, "Bad value '%s' given for ivariable '%s'.\n", value, var);
35         }
36         return COM_OK;
37 }
38
39 /*
40   support the iset command
41 */
42 int com_iset(int p, param_list param)
43 {
44         struct player *pp = &player_globals.parray[p];
45         char *var = param[0].val.word;
46         char *value = param[1].val.string;
47         struct ivariables *iv;
48
49         iv = &pp->ivariables;
50
51         if (iv->lock) {
52                 pprintf(p,"Cannot alter: Interface setting locked.\n");
53                 return COM_OK;
54         }
55
56         if (strcasecmp(var,"ms") == 0) {
57                 return iset_bool(p, &iv->ms, var, value);
58         } else if (strcasecmp(var,"lock") == 0) {
59                 return iset_bool(p, &iv->lock, var, value);
60         } else if (strcasecmp(var,"startpos") == 0) {
61                 return iset_bool(p, &iv->startpos, var, value);
62         } else {
63                 pprintf(p,"No such ivariable \"%s\".\n", var);
64         }
65
66         return COM_OK;
67 }