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::process_input()
48 search_gui
->wait_input();
49 argv
= get_tokenized(&argc
);
54 if(!argc
|| strlen(argv
[0])==0)
61 mv
= board
.move_from_string(argv
[0]);
63 if(mv
== Move::Illegal())
64 output("Illegal move: %s\n", argv
[0]);
65 else if(mv
== Move::Ambiguous())
66 output("Illegal move (ambiguous): %s\n", argv
[0]);
67 else if(mv
== Move::None()) /* not a move */
69 CmdSet::iterator it
= commands
.lower_bound(argv
[0]);
70 if( it
!= commands
.end() &&
71 it
->first
.compare(0, strlen(argv
[0]), argv
[0]) == 0 )
75 if(it
->first
!= argv
[0])
76 output("%s\n", it
->first
.c_str());
79 output("Error, not enough arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
80 else if(argc
-1 > c
.max())
81 output("Error, too many arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
83 c
.run(argc
-1, argv
+1);
86 output("Unknown command: '%s' (try 'help')\n", argv
[0]);