diff options
| author | Geoff Voelker | 1996-05-03 18:33:20 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1996-05-03 18:33:20 +0000 |
| commit | b3fa71dc1be5269620f1663fb7d5da5b1ce3ff31 (patch) | |
| tree | bcc6fc824bde255e36653a05c2f00f74d7b836fc | |
| parent | 480b0c5b52b7c3abfd6dfbe096166235a290b35a (diff) | |
| download | emacs-b3fa71dc1be5269620f1663fb7d5da5b1ce3ff31.tar.gz emacs-b3fa71dc1be5269620f1663fb7d5da5b1ce3ff31.zip | |
Check to see if already included.
(fd_set, filedesc): New structures.
(child_process, MAX_CHILDREN, CHILD_ACTIVE): Definitions moved
from ntproc.c.
(FD_SET, FD_CLR, FD_ISSET, FD_ZERO): Operate on fd_set structures.
(SELECT_TYPE): New macro.
New child process status enumeration.
(FILE_READ, FILE_WRITE, FILE_BINARY, FILE_PIPE, FILE_SOCKET):
New macros.
(fd_info, new_child, delete_child): Declared.
| -rw-r--r-- | src/w32.h | 108 |
1 files changed, 90 insertions, 18 deletions
| @@ -1,3 +1,6 @@ | |||
| 1 | #ifndef _NT_H_ | ||
| 2 | #define _NT_H_ | ||
| 3 | |||
| 1 | /* Support routines for the NT version of Emacs. | 4 | /* Support routines for the NT version of Emacs. |
| 2 | Copyright (C) 1994 Free Software Foundation, Inc. | 5 | Copyright (C) 1994 Free Software Foundation, Inc. |
| 3 | 6 | ||
| @@ -18,28 +21,93 @@ along with GNU Emacs; see the file COPYING. If not, write to | |||
| 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 21 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ | 22 | Boston, MA 02111-1307, USA. */ |
| 20 | 23 | ||
| 21 | /* File descriptor set emulation. */ | 24 | /* #define FULL_DEBUG */ |
| 25 | #define EMACSDEBUG | ||
| 22 | 26 | ||
| 23 | #ifdef FD_SET | 27 | #ifdef EMACSDEBUG |
| 24 | /* We could get this from param.h, but better not to depend on finding that. | 28 | #define DebPrint(stuff) _DebPrint stuff |
| 25 | And better not to risk that it might define other symbols used in this | ||
| 26 | file. */ | ||
| 27 | #ifdef FD_SETSIZE | ||
| 28 | #define MAXDESC FD_SETSIZE | ||
| 29 | #else | 29 | #else |
| 30 | #define MAXDESC 64 | 30 | #define DebPrint(stuff) |
| 31 | #endif | 31 | #endif |
| 32 | |||
| 33 | /* File descriptor set emulation. */ | ||
| 34 | |||
| 35 | /* MSVC runtime library has limit of 64 descriptors by default */ | ||
| 36 | #define FD_SETSIZE 64 | ||
| 37 | typedef struct { | ||
| 38 | unsigned int bits[FD_SETSIZE / 32]; | ||
| 39 | } fd_set; | ||
| 40 | |||
| 41 | /* standard access macros */ | ||
| 42 | #define FD_SET(n, p) \ | ||
| 43 | do { \ | ||
| 44 | if ((n) < FD_SETSIZE) { \ | ||
| 45 | (p)->bits[(n)/32] |= (1 << (n)%32); \ | ||
| 46 | } \ | ||
| 47 | } while (0) | ||
| 48 | #define FD_CLR(n, p) \ | ||
| 49 | do { \ | ||
| 50 | if ((n) < FD_SETSIZE) { \ | ||
| 51 | (p)->bits[(n)/32] &= ~(1 << (n)%32); \ | ||
| 52 | } \ | ||
| 53 | } while (0) | ||
| 54 | #define FD_ISSET(n, p) ((n) < FD_SETSIZE ? ((p)->bits[(n)/32] & (1 << (n)%32)) : 0) | ||
| 55 | #define FD_ZERO(p) memset((p), 0, sizeof(fd_set)) | ||
| 56 | |||
| 32 | #define SELECT_TYPE fd_set | 57 | #define SELECT_TYPE fd_set |
| 33 | #else /* no FD_SET */ | ||
| 34 | #define MAXDESC 32 | ||
| 35 | #define SELECT_TYPE int | ||
| 36 | 58 | ||
| 37 | /* Define the macros to access a single-int bitmap of descriptors. */ | 59 | /* ------------------------------------------------------------------------- */ |
| 38 | #define FD_SET(n, p) (*(p) |= (1 << (n))) | 60 | |
| 39 | #define FD_CLR(n, p) (*(p) &= ~(1 << (n))) | 61 | /* child_process.status values */ |
| 40 | #define FD_ISSET(n, p) (*(p) & (1 << (n))) | 62 | enum { |
| 41 | #define FD_ZERO(p) (*(p) = 0) | 63 | STATUS_READ_ERROR = -1, |
| 42 | #endif /* no FD_SET */ | 64 | STATUS_READ_READY, |
| 65 | STATUS_READ_IN_PROGRESS, | ||
| 66 | STATUS_READ_FAILED, | ||
| 67 | STATUS_READ_SUCCEEDED, | ||
| 68 | STATUS_READ_ACKNOWLEDGED | ||
| 69 | }; | ||
| 70 | |||
| 71 | /* This structure is used for both pipes and sockets; for | ||
| 72 | a socket, the process handle in pi is NULL. */ | ||
| 73 | typedef struct _child_process | ||
| 74 | { | ||
| 75 | int fd; | ||
| 76 | int pid; | ||
| 77 | HANDLE char_avail; | ||
| 78 | HANDLE char_consumed; | ||
| 79 | HANDLE thrd; | ||
| 80 | PROCESS_INFORMATION procinfo; | ||
| 81 | volatile int status; | ||
| 82 | char chr; | ||
| 83 | } child_process; | ||
| 84 | |||
| 85 | #define MAXDESC FD_SETSIZE | ||
| 86 | #define MAX_CHILDREN MAXDESC/2 | ||
| 87 | #define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL) | ||
| 88 | |||
| 89 | /* parallel array of private info on file handles */ | ||
| 90 | typedef struct | ||
| 91 | { | ||
| 92 | unsigned flags; | ||
| 93 | HANDLE hnd; | ||
| 94 | child_process * cp; | ||
| 95 | } filedesc; | ||
| 96 | |||
| 97 | extern filedesc fd_info [ MAXDESC ]; | ||
| 98 | |||
| 99 | /* fd_info flag definitions */ | ||
| 100 | #define FILE_READ 0x0001 | ||
| 101 | #define FILE_WRITE 0x0002 | ||
| 102 | #define FILE_BINARY 0x0010 | ||
| 103 | #define FILE_PIPE 0x0100 | ||
| 104 | #define FILE_SOCKET 0x0200 | ||
| 105 | |||
| 106 | extern child_process * new_child (void); | ||
| 107 | extern void delete_child (child_process *cp); | ||
| 108 | |||
| 109 | /* ------------------------------------------------------------------------- */ | ||
| 110 | |||
| 43 | 111 | ||
| 44 | /* Prepare our standard handles for proper inheritance by child processes. */ | 112 | /* Prepare our standard handles for proper inheritance by child processes. */ |
| 45 | extern void prepare_standard_handles (int in, int out, | 113 | extern void prepare_standard_handles (int in, int out, |
| @@ -50,5 +118,9 @@ extern void reset_standard_handles (int in, int out, | |||
| 50 | int err, HANDLE handles[4]); | 118 | int err, HANDLE handles[4]); |
| 51 | 119 | ||
| 52 | /* Return the string resource associated with KEY of type TYPE. */ | 120 | /* Return the string resource associated with KEY of type TYPE. */ |
| 53 | extern LPBYTE nt_get_resource (char *key, LPDWORD type); | 121 | extern LPBYTE nt_get_resource (char * key, LPDWORD type); |
| 122 | |||
| 123 | extern void init_ntproc (); | ||
| 124 | extern void term_ntproc (); | ||
| 54 | 125 | ||
| 126 | #endif /* _NT_H_ */ | ||