From 92a5061fe11dab6ef0bb339cbe7798e6ccb35626 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 9 Jun 2011 09:51:04 +0200 Subject: [PATCH] version 1.4b26 --- ChangeLog | 7 + config.h | 6 +- configure | 20 +- configure.ac | 2 +- engine.cpp | 33 ++-- gui.cpp | 10 +- io.cpp | 668 ++++++++++++++++++++++++++++---------------------------- main.cpp | 2 +- mainloop.cpp | 7 +- pipe.cpp | 30 ++- pipe.h | 29 ++-- polyglot.spec | 2 +- 12 files changed, 431 insertions(+), 385 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ce2f42..dc5959b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +=========1.4b26=========== +- Contraction of version number. +- Log if SetProcessAffinityMask is not available (suggested by E.M.). +- pipe.cpp : Make PipeStruct a proper class with private/public members. +- Check for EOF in GUI input. +- pipe.cpp : delay reporting EOF until buffer is empty. +- Messages from the Engine to PG were not logged in the windows version. =========1.4w10UCIb24=========== - Portability fixes for WIN9X (Eric Mullins). - Portability fixes for MSVC++ (Eric Mullins). diff --git a/config.h b/config.h index 17b64ef..e00a8b5 100644 --- a/config.h +++ b/config.h @@ -115,13 +115,13 @@ #define PACKAGE_NAME "polyglot" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "polyglot 1.4w10UCIb24" +#define PACKAGE_STRING "polyglot 1.4b26" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "polyglot" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.4w10UCIb24" +#define PACKAGE_VERSION "1.4b26" /* Define to 1 if the C compiler supports function prototypes. */ #define PROTOTYPES 1 @@ -150,7 +150,7 @@ #define TIME_WITH_SYS_TIME 1 /* Version number of package */ -#define VERSION "1.4w10UCIb24" +#define VERSION "1.4b26" /* Define like PROTOTYPES; this can be used by system headers. */ #define __PROTOTYPES 1 diff --git a/configure b/configure index 16d6bb9..752001a 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for polyglot 1.4w10UCIb24. +# Generated by GNU Autoconf 2.61 for polyglot 1.4b26. # # Report bugs to . # @@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='polyglot' PACKAGE_TARNAME='polyglot' -PACKAGE_VERSION='1.4w10UCIb24' -PACKAGE_STRING='polyglot 1.4w10UCIb24' +PACKAGE_VERSION='1.4b26' +PACKAGE_STRING='polyglot 1.4b26' PACKAGE_BUGREPORT='michel.vandenbergh@uhasselt.be' ac_unique_file="mainloop.cpp" @@ -1216,7 +1216,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures polyglot 1.4w10UCIb24 to adapt to many kinds of systems. +\`configure' configures polyglot 1.4b26 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1282,7 +1282,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of polyglot 1.4w10UCIb24:";; + short | recursive ) echo "Configuration of polyglot 1.4b26:";; esac cat <<\_ACEOF @@ -1368,7 +1368,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -polyglot configure 1.4w10UCIb24 +polyglot configure 1.4b26 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1382,7 +1382,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by polyglot $as_me 1.4w10UCIb24, which was +It was created by polyglot $as_me 1.4b26, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -2072,7 +2072,7 @@ fi # Define the identity of the package. PACKAGE='polyglot' - VERSION='1.4w10UCIb24' + VERSION='1.4b26' cat >>confdefs.h <<_ACEOF @@ -7344,7 +7344,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by polyglot $as_me 1.4w10UCIb24, which was +This file was extended by polyglot $as_me 1.4b26, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7397,7 +7397,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -polyglot config.status 1.4w10UCIb24 +polyglot config.status 1.4b26 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 3e195b8..9cabff7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([polyglot], [1.4w10UCIb24], [michel.vandenbergh@uhasselt.be]) +AC_INIT([polyglot], [1.4b26], [michel.vandenbergh@uhasselt.be]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([mainloop.cpp]) AC_CONFIG_HEADER([config.h]) diff --git a/engine.cpp b/engine.cpp index b6c0f4b..f86f0fb 100644 --- a/engine.cpp +++ b/engine.cpp @@ -323,14 +323,18 @@ engine_t Engine[1]; void set_affinity(engine_t *engine, int affin){ if(affin==-1) return; - { typedef void (WINAPI *SPAM)(HANDLE, int); - SPAM pSPAM; - - pSPAM = (SPAM) GetProcAddress( - GetModuleHandle(TEXT("kernel32.dll")), - "SetProcessAffinityMask"); - if(NULL != pSPAM) // [HGM] avoid crash on Win95 by first checking if API call exists - pSPAM((engine->io).hProcess,affin); + + typedef void (WINAPI *SPAM)(HANDLE, int); + SPAM pSPAM; + pSPAM = (SPAM) GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), + "SetProcessAffinityMask"); + if(NULL != pSPAM){ + // [HGM] avoid crash on Win95 by first checking if API call exists + my_log("POLYGLOT Setting process affinity to %d\n",affin); + pSPAM((engine->io).hProcess,affin); + }else{ + my_log("POLYGLOT API call \"SetProcessAffinityMask\" not available\n"); } } @@ -371,9 +375,8 @@ void engine_close(engine_t * engine){ char string[StringSize]; (engine->io).Close(); // TODO: Timeout - while (!engine_eof(Engine)) { - engine_get_non_blocking(Engine,string,StringSize); - Idle(); + while (!engine_eof(engine)) { + engine_get(Engine,string,StringSize); } (engine->io).Kill(); } @@ -412,13 +415,14 @@ bool engine_eof(engine_t *engine){ bool engine_get_non_blocking(engine_t * engine, char *szLineStr, int size){ if(engine_eof(engine)){ return false;} - if ((engine->io).GetBuffer(szLineStr)) { + if ((engine->io).GetBuffer(szLineStr)) { my_log("Engine->Adapter: %s\n",szLineStr); return true; } else { szLineStr[0]='\0'; if(engine->io.EOF_()){ engine->state|=ENGINE_EOF; + my_log("POLYGLOT *** EOF from Engine ***\n"); } return false; } @@ -427,7 +431,10 @@ bool engine_get_non_blocking(engine_t * engine, char *szLineStr, int size){ void engine_get(engine_t * engine, char *szLineStr, int size){ (engine->io).LineInput(szLineStr); if(engine->io.EOF_()){ - engine->state|=ENGINE_EOF; + engine->state|=ENGINE_EOF; + my_log("POLYGLOT *** EOF from Engine ***\n"); + }else{ + my_log("Engine->Adapter: %s\n",szLineStr); } } diff --git a/gui.cpp b/gui.cpp index dac260f..71d0cc0 100644 --- a/gui.cpp +++ b/gui.cpp @@ -68,7 +68,11 @@ bool gui_get_non_blocking(gui_t * gui, char string[], int size) { return false; } #else - if ((gui->io).GetBuffer(string)) { + if((gui->io).EOF_()){ + my_log("POLYGLOT *** EOF from GUI ***\n"); + quit(); + return true; // we never get here + }else if ((gui->io).GetBuffer(string)) { my_log("GUI->Adapter: %s\n", string); return true; } else { @@ -83,6 +87,10 @@ bool gui_get_non_blocking(gui_t * gui, char string[], int size) { void gui_get(gui_t * gui, char string[], int size) { bool data_available; #ifdef _WIN32 + if((gui->io).EOF_()){ + my_log("POLYGLOT *** EOF from GUI ***\n"); + quit(); + } (gui->io).LineInput(string); my_log("GUI->Adapter: %s\n", string); #else diff --git a/io.cpp b/io.cpp index 7246e89..b53d94c 100644 --- a/io.cpp +++ b/io.cpp @@ -1,334 +1,334 @@ -#ifndef _WIN32 - -// io.cpp - -// includes - -#include -#include -#include -#include -#include - -#include -#include - -#include "io.h" -#include "util.h" - -// constants - -static const bool UseDebug = false; -static const bool UseCR = false; - -static const int StringSize = 4096; - -static const char LF = '\n'; -static const char CR = '\r'; - -// prototypes - -static int my_read (int fd, char string[], int size); -static void my_write (int fd, const char string[], int size); - -// functions - -// io_is_ok() - -bool io_is_ok(const io_t * io) { - - if (io == NULL) return false; - - if (io->name == NULL) return false; - - if (io->in_eof != true && io->in_eof != false) return false; - - if (io->in_size < 0 || io->in_size > BufferSize) return false; - if (io->out_size < 0 || io->out_size > BufferSize) return false; - - return true; -} - -// io_init() - -void io_init(io_t * io) { - - ASSERT(io!=NULL); - - io->in_eof = false; - - io->in_size = 0; - io->out_size = 0; - - ASSERT(io_is_ok(io)); -} - -// io_close() - -void io_close(io_t * io) { - - ASSERT(io_is_ok(io)); - - ASSERT(io->out_fd>=0); - - my_log("> %s EOF\n",io->name); - - if (close(io->out_fd) == -1) { - my_fatal("io_close(): close(): %s\n",strerror(errno)); - } - - io->out_fd = -1; -} - -// io_get_update() - -void io_get_update(io_t * io) { - - int pos, size; - int n; - - ASSERT(io_is_ok(io)); - - ASSERT(io->in_fd>=0); - ASSERT(!io->in_eof); - - // init - - pos = io->in_size; - - size = BufferSize - pos; - if (size <= 0) my_fatal("io_get_update(): buffer overflow\n"); - - // read as many data as possible - n = my_read(io->in_fd,&io->in_buffer[pos],size); - if (UseDebug) my_log("POLYGLOT read %d byte%s from %s\n",n,(n>1)?"s":"",io->name); - - if (n > 0) { // at least one character was read - - // update buffer size - - ASSERT(n>=1&&n<=size); - - io->in_size += n; - ASSERT(io->in_size>=0&&io->in_size<=BufferSize); - - } else { // EOF - - ASSERT(n==0); - - io->in_eof = true; - } -} - -// io_line_ready() - -bool io_line_ready(const io_t * io) { - - ASSERT(io_is_ok(io)); - - if (io->in_eof) return true; - - if (memchr(io->in_buffer,LF,io->in_size) != NULL) return true; // buffer contains LF - - return false; -} - -// io_get_line() - -bool io_get_line(io_t * io, char string[], int size) { - - int src, dst; - int c; - - ASSERT(io_is_ok(io)); - ASSERT(string!=NULL); - ASSERT(size>=256); - - src = 0; - dst = 0; - - while (true) { - - // test for end of buffer - - if (src >= io->in_size) { - if (io->in_eof) { - my_log("%s->Adapter: EOF\n",io->name); - return false; - } else { - my_fatal("io_get_line(): no EOL in buffer\n"); - } - } - - // test for end of string - - if (dst >= size) my_fatal("io_get_line(): buffer overflow\n"); - - // copy the next character - - c = io->in_buffer[src++]; - - if (c == LF) { // LF => line complete - string[dst] = '\0'; - break; - } else if (c != CR) { // skip CRs - string[dst++] = c; - } - } - - // shift the buffer - - ASSERT(src>0); - - io->in_size -= src; - ASSERT(io->in_size>=0); - - if (io->in_size > 0) memmove(&io->in_buffer[0],&io->in_buffer[src],io->in_size); - - // return - - my_log("%s->Adapter: %s\n",io->name,string); - - return true; -} - -// io_send() - -void io_send(io_t * io, const char format[], ...) { - - va_list arg_list; - char string[StringSize]; - int len; - - ASSERT(io_is_ok(io)); - ASSERT(format!=NULL); - - ASSERT(io->out_fd>=0); - - // format - - va_start(arg_list,format); - vsprintf(string,format,arg_list); - va_end(arg_list); - - // append string to buffer - - len = strlen(string); - if (io->out_size + len > BufferSize-2) my_fatal("io_send(): buffer overflow\n"); - - memcpy(&io->out_buffer[io->out_size],string,len); - io->out_size += len; - - ASSERT(io->out_size>=0&&io->out_size<=BufferSize-2); - - // log - - io->out_buffer[io->out_size] = '\0'; - my_log("Adapter->%s: %s\n",io->name,io->out_buffer); -// my_log("> %f %s %s\n",now_real(),io->name,io->out_buffer); - // append EOL to buffer - - if (UseCR) io->out_buffer[io->out_size++] = CR; - io->out_buffer[io->out_size++] = LF; - - ASSERT(io->out_size>=0&&io->out_size<=BufferSize); - - // flush buffer - - if (UseDebug) my_log("POLYGLOT writing %d byte%s to %s\n",io->out_size,(io->out_size>1)?"s":"",io->name); - my_write(io->out_fd,io->out_buffer,io->out_size); - - io->out_size = 0; -} - -// io_send_queue() - -void io_send_queue(io_t * io, const char format[], ...) { - - va_list arg_list; - char string[StringSize]; - int len; - - ASSERT(io_is_ok(io)); - ASSERT(format!=NULL); - - ASSERT(io->out_fd>=0); - - // format - - va_start(arg_list,format); - vsprintf(string,format,arg_list); - va_end(arg_list); - - // append string to buffer - - len = strlen(string); - if (io->out_size + len > BufferSize-2) my_fatal("io_send_queue(): buffer overflow\n"); - - memcpy(&io->out_buffer[io->out_size],string,len); - io->out_size += len; - - ASSERT(io->out_size>=0&&io->out_size<=BufferSize-2); -} - -// my_read() - -static int my_read(int fd, char string[], int size) { - - int n; - - ASSERT(fd>=0); - ASSERT(string!=NULL); - ASSERT(size>0); - - do { - n = read(fd,string,size); - } while (n == -1 && errno == EINTR); - - if (n == -1) my_fatal("my_read(): read(): %s\n",strerror(errno)); - - ASSERT(n>=0); - - return n; -} - -// my_write() - -static void my_write(int fd, const char string[], int size) { - - int n; - - ASSERT(fd>=0); - ASSERT(string!=NULL); - ASSERT(size>0); - - do { - - n = write(fd,string,size); - - // if (n == -1 && errno != EINTR && errno != EPIPE) my_fatal("my_write(): write(): %s\n",strerror(errno)); - - if (n == -1) { - if (false) { - } else if (errno == EINTR) { - n = 0; // nothing has been written - } else if (errno == EPIPE) { - n = size; // pretend everything has been written - } else { - my_fatal("my_write(): write(): %s\n",strerror(errno)); - } - } - - ASSERT(n>=0); - - string += n; - size -= n; - - } while (size > 0); - - ASSERT(size==0); -} - -// end of io.cpp - -#endif +#ifndef _WIN32 + +// io.cpp + +// includes + +#include +#include +#include +#include +#include + +#include +#include + +#include "io.h" +#include "util.h" + +// constants + +static const bool UseDebug = false; +static const bool UseCR = false; + +static const int StringSize = 4096; + +static const char LF = '\n'; +static const char CR = '\r'; + +// prototypes + +static int my_read (int fd, char string[], int size); +static void my_write (int fd, const char string[], int size); + +// functions + +// io_is_ok() + +bool io_is_ok(const io_t * io) { + + if (io == NULL) return false; + + if (io->name == NULL) return false; + + if (io->in_eof != true && io->in_eof != false) return false; + + if (io->in_size < 0 || io->in_size > BufferSize) return false; + if (io->out_size < 0 || io->out_size > BufferSize) return false; + + return true; +} + +// io_init() + +void io_init(io_t * io) { + + ASSERT(io!=NULL); + + io->in_eof = false; + + io->in_size = 0; + io->out_size = 0; + + ASSERT(io_is_ok(io)); +} + +// io_close() + +void io_close(io_t * io) { + + ASSERT(io_is_ok(io)); + + ASSERT(io->out_fd>=0); + + my_log("Adapter>Engine: EOF\n",io->name); + + if (close(io->out_fd) == -1) { + my_fatal("io_close(): close(): %s\n",strerror(errno)); + } + + io->out_fd = -1; +} + +// io_get_update() + +void io_get_update(io_t * io) { + + int pos, size; + int n; + + ASSERT(io_is_ok(io)); + + ASSERT(io->in_fd>=0); + ASSERT(!io->in_eof); + + // init + + pos = io->in_size; + + size = BufferSize - pos; + if (size <= 0) my_fatal("io_get_update(): buffer overflow\n"); + + // read as many data as possible + n = my_read(io->in_fd,&io->in_buffer[pos],size); + if (UseDebug) my_log("POLYGLOT read %d byte%s from %s\n",n,(n>1)?"s":"",io->name); + + if (n > 0) { // at least one character was read + + // update buffer size + + ASSERT(n>=1&&n<=size); + + io->in_size += n; + ASSERT(io->in_size>=0&&io->in_size<=BufferSize); + + } else { // EOF + + ASSERT(n==0); + + io->in_eof = true; + } +} + +// io_line_ready() + +bool io_line_ready(const io_t * io) { + + ASSERT(io_is_ok(io)); + + if (io->in_eof) return true; + + if (memchr(io->in_buffer,LF,io->in_size) != NULL) return true; // buffer contains LF + + return false; +} + +// io_get_line() + +bool io_get_line(io_t * io, char string[], int size) { + + int src, dst; + int c; + + ASSERT(io_is_ok(io)); + ASSERT(string!=NULL); + ASSERT(size>=256); + + src = 0; + dst = 0; + + while (true) { + + // test for end of buffer + + if (src >= io->in_size) { + if (io->in_eof) { + my_log("%s->Adapter: EOF\n",io->name); + return false; + } else { + my_fatal("io_get_line(): no EOL in buffer\n"); + } + } + + // test for end of string + + if (dst >= size) my_fatal("io_get_line(): buffer overflow\n"); + + // copy the next character + + c = io->in_buffer[src++]; + + if (c == LF) { // LF => line complete + string[dst] = '\0'; + break; + } else if (c != CR) { // skip CRs + string[dst++] = c; + } + } + + // shift the buffer + + ASSERT(src>0); + + io->in_size -= src; + ASSERT(io->in_size>=0); + + if (io->in_size > 0) memmove(&io->in_buffer[0],&io->in_buffer[src],io->in_size); + + // return + + my_log("%s->Adapter: %s\n",io->name,string); + + return true; +} + +// io_send() + +void io_send(io_t * io, const char format[], ...) { + + va_list arg_list; + char string[StringSize]; + int len; + + ASSERT(io_is_ok(io)); + ASSERT(format!=NULL); + + ASSERT(io->out_fd>=0); + + // format + + va_start(arg_list,format); + vsprintf(string,format,arg_list); + va_end(arg_list); + + // append string to buffer + + len = strlen(string); + if (io->out_size + len > BufferSize-2) my_fatal("io_send(): buffer overflow\n"); + + memcpy(&io->out_buffer[io->out_size],string,len); + io->out_size += len; + + ASSERT(io->out_size>=0&&io->out_size<=BufferSize-2); + + // log + + io->out_buffer[io->out_size] = '\0'; + my_log("Adapter->%s: %s\n",io->name,io->out_buffer); +// my_log("> %f %s %s\n",now_real(),io->name,io->out_buffer); + // append EOL to buffer + + if (UseCR) io->out_buffer[io->out_size++] = CR; + io->out_buffer[io->out_size++] = LF; + + ASSERT(io->out_size>=0&&io->out_size<=BufferSize); + + // flush buffer + + if (UseDebug) my_log("POLYGLOT writing %d byte%s to %s\n",io->out_size,(io->out_size>1)?"s":"",io->name); + my_write(io->out_fd,io->out_buffer,io->out_size); + + io->out_size = 0; +} + +// io_send_queue() + +void io_send_queue(io_t * io, const char format[], ...) { + + va_list arg_list; + char string[StringSize]; + int len; + + ASSERT(io_is_ok(io)); + ASSERT(format!=NULL); + + ASSERT(io->out_fd>=0); + + // format + + va_start(arg_list,format); + vsprintf(string,format,arg_list); + va_end(arg_list); + + // append string to buffer + + len = strlen(string); + if (io->out_size + len > BufferSize-2) my_fatal("io_send_queue(): buffer overflow\n"); + + memcpy(&io->out_buffer[io->out_size],string,len); + io->out_size += len; + + ASSERT(io->out_size>=0&&io->out_size<=BufferSize-2); +} + +// my_read() + +static int my_read(int fd, char string[], int size) { + + int n; + + ASSERT(fd>=0); + ASSERT(string!=NULL); + ASSERT(size>0); + + do { + n = read(fd,string,size); + } while (n == -1 && errno == EINTR); + + if (n == -1) my_fatal("my_read(): read(): %s\n",strerror(errno)); + + ASSERT(n>=0); + + return n; +} + +// my_write() + +static void my_write(int fd, const char string[], int size) { + + int n; + + ASSERT(fd>=0); + ASSERT(string!=NULL); + ASSERT(size>0); + + do { + + n = write(fd,string,size); + + // if (n == -1 && errno != EINTR && errno != EPIPE) my_fatal("my_write(): write(): %s\n",strerror(errno)); + + if (n == -1) { + if (false) { + } else if (errno == EINTR) { + n = 0; // nothing has been written + } else if (errno == EPIPE) { + n = size; // pretend everything has been written + } else { + my_fatal("my_write(): write(): %s\n",strerror(errno)); + } + } + + ASSERT(n>=0); + + string += n; + size -= n; + + } while (size > 0); + + ASSERT(size==0); +} + +// end of io.cpp + +#endif diff --git a/main.cpp b/main.cpp index a54aefe..4bd2fbb 100644 --- a/main.cpp +++ b/main.cpp @@ -35,7 +35,7 @@ // constants -static const char * const Version = "1.4W10UCIb24"; +static const char * const Version = "1.4b26"; static const char * const HelpMessage = "\ SYNTAX\n\ * polyglot [configfile]\n\ diff --git a/mainloop.cpp b/mainloop.cpp index ffef0c9..0bb378c 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -84,7 +84,12 @@ void mainloop() { } mainloop_wait_for_event(); } - my_log("POLYGLOT *** EOF file received from engine ***\n"); + my_log("POLYGLOT *** Mainloop has ended ***\n"); + // This should be handled better. + engine_close(Engine); + my_log("POLYGLOT Calling exit\n"); + exit(EXIT_SUCCESS); + } diff --git a/pipe.cpp b/pipe.cpp index 48f0c72..170da4a 100644 --- a/pipe.cpp +++ b/pipe.cpp @@ -6,7 +6,7 @@ DWORD WINAPI ThreadProc(LPVOID lpParam){ PipeStruct *p=(PipeStruct *) lpParam; - while(!p->EOF_()){ + while(!p->EOF_input()){ if(p->nReadEndReadInput(); }else{ @@ -123,7 +123,7 @@ void PipeStruct::Kill(void) const { CloseHandle(hProcess); } -bool PipeStruct::EOF_(void){ // EOF is defined +bool PipeStruct::EOF_input(void){ // EOF is defined int ret; EnterCriticalSection(&CriticalSection); ret=state&PIPE_EOF; @@ -131,7 +131,7 @@ bool PipeStruct::EOF_(void){ // EOF is defined return ret; } -void PipeStruct::set_EOF_(void){ +void PipeStruct::set_EOF_input(void){ EnterCriticalSection(&CriticalSection); state|=PIPE_EOF; LeaveCriticalSection(&CriticalSection); @@ -159,7 +159,7 @@ int PipeStruct::ReadData(void){ // This just means we have read less than we could have. ret=fgets(lpReadBuffer,LINE_INPUT_MAX_CHAR-nReadEnd,fpInput); if(!ret){ - set_EOF_(); + set_EOF_input(); lpReadBuffer[0]='\0'; return 0; } @@ -176,7 +176,7 @@ void PipeStruct::ReadInput(void) { // would block during the blocking read ret=ReadData(); EnterCriticalSection(&CriticalSection); - if(!EOF_()){ + if(!EOF_input()){ if(ret+nReadEnd>=LINE_INPUT_MAX_CHAR){ my_fatal("PipeStruct::ReadInput(): Internal error: buffer overflow\n"); } @@ -192,11 +192,25 @@ void PipeStruct::ReadInput(void) { } } LeaveCriticalSection(&CriticalSection); - if(EOF_() || bSetEvent){ + if(EOF_input() || bSetEvent){ SetEvent(hEvent); } } +bool PipeStruct::EOF_(void){ + int ret; + EnterCriticalSection(&CriticalSection); + if(lpFeedEnd != NULL){ + ret=FALSE; + }else if(EOF_input()){ + ret=TRUE; + }else{ + ret=FALSE; + } + LeaveCriticalSection(&CriticalSection); + return ret; +} + bool PipeStruct::GetBuffer(char *szLineStr) { int nFeedEnd; int ret; @@ -221,8 +235,10 @@ bool PipeStruct::GetBuffer(char *szLineStr) { return ret; } + + void PipeStruct::LineInput(char *szLineStr) { - while(!EOF_()){ + while(!EOF_()){ if (GetBuffer(szLineStr)) { break; }else{ diff --git a/pipe.h b/pipe.h index ad01c18..d24ed8c 100644 --- a/pipe.h +++ b/pipe.h @@ -21,13 +21,23 @@ const int LINE_INPUT_MAX_CHAR = 40960; // types -struct PipeStruct { - +class PipeStruct { + friend DWORD WINAPI ThreadProc(LPVOID lpParam); + public: + HANDLE hProcess; + HANDLE hEvent; + bool GetBuffer(char *szLineStr); + void LineInput(char *szLineStr); + void LineOutput(const char *szLineStr) const; + void Open(const char *szExecFile = NULL); + void Close(void) const; + void Kill(void) const; + bool Active(void); + bool EOF_(void); + private: HANDLE hInput, hOutput; FILE *fpInput; - HANDLE hProcess; HANDLE hThread; - HANDLE hEvent; BOOL bConsole; BOOL bPipe; @@ -39,18 +49,11 @@ struct PipeStruct { char lpBuffer[LINE_INPUT_MAX_CHAR]; char lpReadBuffer[LINE_INPUT_MAX_CHAR]; - void Open(const char *szExecFile = NULL); - void Close(void) const; - void Kill(void) const; - bool EOF_(void); - void set_EOF_(void); - bool Active(void); + bool EOF_input(void); + void set_EOF_input(void); void set_Active(void); void ReadInput(void); int ReadData(void); - bool GetBuffer(char *szLineStr); - void LineInput(char *szLineStr); - void LineOutput(const char *szLineStr) const; }; diff --git a/polyglot.spec b/polyglot.spec index 851557d..04cb5f1 100644 --- a/polyglot.spec +++ b/polyglot.spec @@ -1,6 +1,6 @@ Summary: A Winboard protocol to UCI protocol adapter Name: polyglot -Version: 1.4w10UCIb24 +Version: 1.4b26 Release: 1 License: GPL Group: Amusement/Games -- 1.7.0.4