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
);
35 fwrite(buf
, 1, len
, log
);
40 void Engine::process_input()
48 if(!fgets(str
,4096,stdin
))
53 fwrite("--> ", 1, 4, log
);
54 fwrite(str
, 1, strlen(str
), log
);
59 ptr
+= strspn(ptr
, " \t\r\n");
61 for(int i
=0;i
<256;i
++)
66 char *tmp
= (ptr
+= strcspn(ptr
, " \t\r\n"));
67 ptr
+= strspn(ptr
, ". \t\r\n");
70 printf("got \"%s\"\n", t
);
74 if(!argc
|| strlen(argv
[0])==0)
78 retv
= parse_move(&mv
,str
);
83 CmdSet::iterator it
= commands
.lower_bound(argv
[0]);
84 if( it
!= commands
.end() &&
85 it
->first
.compare(0, strlen(argv
[0]), argv
[0]) == 0 )
89 if(it
->first
!= argv
[0])
90 output("%s\n", it
->first
.c_str());
93 output("Error, not enough arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
94 else if(argc
-1 > c
.max())
95 output("Error, too many arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
97 c
.run(argc
-1, argv
+1);
100 output("Illegal command: '%s' (try 'help')\n", argv
[0]);
102 /* a legal valid move */
113 /* a move that is illegal or ambiguous */