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()
47 argv
= get_tokenized(&argc
);
52 // printf("%d arguments\n", argc);
53 // for(int i=0;i<argc;i++)
54 // printf("got \"%s\"\n", argv[i]);
56 if(!argc
|| strlen(argv
[0])==0)
63 retv
= parse_move(&mv
, argv
[0]);
68 CmdSet::iterator it
= commands
.lower_bound(argv
[0]);
69 if( it
!= commands
.end() &&
70 it
->first
.compare(0, strlen(argv
[0]), argv
[0]) == 0 )
74 if(it
->first
!= argv
[0])
75 output("%s\n", it
->first
.c_str());
78 output("Error, not enough arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
79 else if(argc
-1 > c
.max())
80 output("Error, too many arguments (%d) for command '%s' (try 'help')\n", argc
-1, it
->first
.c_str() );
82 c
.run(argc
-1, argv
+1);
85 output("Illegal command: '%s' (try 'help')\n", argv
[0]);
87 /* a legal valid move */
98 /* a move that is illegal or ambiguous */