1 /***************************************************************************
5 copyright : (C) 2005 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
22 #include "search_gui.h"
24 void Engine::output(const char* fmt
, ...)
30 len
= MIN(vsnprintf( buf
, 4096, fmt
, va
), 4096);
33 fwrite(buf
, 1, len
, stdout
);
36 fwrite(buf
, 1, len
, log
);
41 void Engine::run_command(int argc
, char** argv
)
43 if(argv
[0][0] == '#' || argv
[0][0] == ';')
46 CmdSet::iterator it
= commands
.lower_bound(argv
[0]);
47 if( it
!= commands
.end() &&
48 it
->first
.compare(0, strlen(argv
[0]), argv
[0]) == 0 )
52 if(it
->first
!= argv
[0])
53 output("%s\n", it
->first
.c_str());
56 output("Error, not enough arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
57 else if(argc
-1 > c
.max())
58 output("Error, too many arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
60 c
.run(argc
-1, argv
+1);
63 output("Unknown command: '%s' (try 'help')\n", argv
[0]);
66 void Engine::load_ini()
68 FILE *f
= fopen("rattatechess.ini", "r");
75 while( (argv
= fget_tokenized(f
, &argc
)) )
77 if(!argc
|| strlen(argv
[0])==0)
82 run_command(argc
, argv
);
89 void Engine::process_input()
96 search_gui
->wait_input();
97 argv
= get_tokenized(&argc
);
102 if(!argc
|| strlen(argv
[0])==0)
108 /* is this a move? */
109 mv
= board
.move_from_string(argv
[0]);
111 if(mv
== Move::Illegal())
112 output("Illegal move: %s\n", argv
[0]);
113 else if(mv
== Move::Ambiguous())
114 output("Illegal move (ambiguous): %s\n", argv
[0]);
115 else if(mv
== Move::None()) /* not a move */
116 run_command(argc
, argv
);
117 else /* a valid move */