18 #define StringSize 4096
\r
22 static int write_index = 0;
\r
23 static char write_buffer[StringSize];
\r
30 void set_affinity(engine_t *engine, int value){
\r
31 pipex_set_affinity(engine->pipex,value);
\r
34 // engine_set_nice_value()
\r
36 void engine_set_nice_value(engine_t *engine, int value){
\r
37 pipex_set_priority(engine->pipex,value);
\r
40 // engine_send_queue()
\r
42 void engine_send_queue(engine_t * engine, const char *format, ...) {
\r
43 if(write_index>=StringSize){
\r
44 my_fatal("engine_send_queue(): write_buffer overflow\n");
\r
46 write_index += vsnprintf(write_buffer + write_index,
\r
47 StringSize-write_index,
\r
49 (va_list) (&format + 1));
\r
54 void engine_send(engine_t * engine, const char *format, ...) {
\r
55 if(write_index>=StringSize){
\r
56 my_fatal("engine_send(): write_buffer overflow\n");
\r
58 vsnprintf(write_buffer + write_index,
\r
59 StringSize-write_index,
\r
61 (va_list) (&format + 1));
\r
62 pipex_writeln(engine->pipex,write_buffer);
\r
68 void engine_close(engine_t * engine){
\r
69 char string[StringSize];
\r
70 pipex_send_eof(engine->pipex);
\r
72 while (!engine_eof(engine)) {
\r
73 engine_get(Engine,string);
\r
75 pipex_exit(engine->pipex);
\r
80 void engine_open(engine_t * engine){
\r
83 if( (my_dir = my_getcwd( NULL, 0 )) == NULL )
\r
84 my_fatal("engine_open(): no current directory: %s\n",strerror(errno));
\r
85 if(my_chdir(option_get_string("EngineDir"))){
\r
86 my_fatal("engine_open(): cannot change directory: %s\n",strerror(errno));
\r
88 pipex_open(engine->pipex,"Engine",option_get_string("EngineCommand"));
\r
89 if(pipex_active(engine->pipex)){
\r
90 //play with affinity (bad idea)
\r
91 affinity=option_get_int("Affinity");
\r
92 if(affinity!=-1) set_affinity(engine,affinity); //AAA
\r
95 // set a low priority
\r
96 if (option_get_bool("UseNice")){
\r
97 my_log("POLYGLOT Adjust Engine Piority\n");
\r
98 engine_set_nice_value(engine, option_get_int("NiceValue"));
\r
104 bool engine_active(engine_t *engine){
\r
105 return pipex_active(engine->pipex);
\r
108 bool engine_eof(engine_t *engine){
\r
109 return pipex_eof(engine->pipex);
\r
112 bool engine_get_non_blocking(engine_t * engine, char *string){
\r
113 return pipex_readln_nb(engine->pipex,string);
\r
116 void engine_get(engine_t * engine, char *string){
\r
117 pipex_readln(engine->pipex,string);
\r