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 ***************************************************************************/
23 void Engine::output(const char* fmt
, ...)
29 len
= MIN(vsnprintf( buf
, 4096, fmt
, va
), 4096);
32 fwrite(buf
, 1, len
, stdout
);
33 fwrite(buf
, 1, len
, log
);
37 void Engine::process_input()
46 if(!fgets(str
,4096,stdin
))
49 fwrite("--> ", 1, 4, log
);
50 fwrite(str
, 1, strlen(str
), log
);
53 for(int i
=0;i
<256;i
++)
55 char *t
= strtok_r( i
? NULL
: str
, " \t\r\n", &tmp
);
62 if(!argc
|| strlen(argv
[0])==0)
66 retv
= parse_move(&mv
,str
);
71 CmdSet::iterator it
= commands
.lower_bound(argv
[0]);
72 if( it
!= commands
.end() &&
73 it
->first
.compare(0, strlen(argv
[0]), argv
[0]) == 0 )
77 if(it
->first
!= argv
[0])
78 output("%s\n", it
->first
.c_str());
81 output("Error, not enough arguments for command '%s' (try 'help')\n", it
->first
.c_str() );
82 else if(argc
-1 > c
.max())
83 output("Error, too many arguments for command '%s' (try 'help')\n", it
->first
.c_str() );
85 c
.run(argc
-1, argv
+1);
88 output("Illegal command: '%s' (try 'help')\n", argv
[0]);
90 /* a legal valid move */
101 /* a move that is illegal or ambiguous */