version 1.4.31b
[polyglot.git] / pipex.h
1 #ifndef PIPEX_H
2 #define PIPEX_H
3 #ifdef _WIN32
4
5 // WIN32 part
6
7 // includes
8
9 #include <windows.h>
10 #include <stdio.h>
11 #include "util.h"
12
13 // defines
14
15 #define PIPEX_EOF (1<<0)
16 #define PIPEX_ACTIVE (1<<1)
17
18 // This should be bigger than the maximum length of an engine output or GUI
19 // input line.
20
21 #define LINE_INPUT_MAX_CHAR 4096
22
23 // types
24
25 typedef struct {
26     HANDLE hProcess;
27     HANDLE hEvent;
28     HANDLE hInput, hOutput;
29     FILE *fpInput;
30     HANDLE hThread;
31     BOOL bConsole;
32     BOOL bPipe;
33     CRITICAL_SECTION CriticalSection;
34     volatile DWORD state;
35     volatile char * lpFeedEnd;
36     volatile int nReadEnd;
37     char lpBuffer[LINE_INPUT_MAX_CHAR];
38     char lpReadBuffer[LINE_INPUT_MAX_CHAR];
39     const char *name;
40
41 } pipex_t;
42
43 #else
44
45 // POSIX part
46
47 // includes
48
49 #include <sys/types.h>
50 #include <unistd.h>
51 #include <sys/time.h>
52 #include <sys/resource.h>
53
54
55 #include "io.h"
56 #include "util.h"
57
58 // defines
59
60 #define PIPEX_EOF (1<<0)
61 #define PIPEX_ACTIVE (1<<1)
62
63 // types
64
65 typedef struct {
66     io_t io[1];
67     pid_t pid;
68     int state;
69 } pipex_t;
70
71 #endif
72
73 // part common to WIN32 and POSIX
74
75 // functions 
76
77 extern void pipex_open         (pipex_t *pipex, 
78                                 const char *name,
79                                 const char *command);
80 extern bool pipex_active       (pipex_t *pipex);
81 extern bool pipex_readln       (pipex_t *pipex, char *string);
82 extern bool pipex_readln_nb    (pipex_t *pipex, char *string);
83 extern void pipex_writeln      (pipex_t *pipex, const char *string);
84 extern bool pipex_eof          (pipex_t *pipex);
85 extern void pipex_send_eof     (pipex_t *pipex);
86 extern void pipex_exit         (pipex_t *pipex);
87 extern void pipex_set_priority (pipex_t *pipex, int value);
88 extern void pipex_set_affinity (pipex_t *pipex, int value);
89 extern void pipex_wait_event   (pipex_t *pipex[]);
90
91 // pipex
92
93 #endif