1 /* -*-C-*-
2 
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
6     Institute of Technology
7 
8 This file is part of MIT/GNU Scheme.
9 
10 MIT/GNU Scheme is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
14 
15 MIT/GNU Scheme is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with MIT/GNU Scheme; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 
25 */
26 
27 #ifndef SCM_NTIO_H
28 #define SCM_NTIO_H
29 
30 #include "osio.h"
31 
32 typedef long channel_op_read (Tchannel, void *, unsigned long);
33 typedef long channel_op_write (Tchannel, const void *, unsigned long);
34 typedef void channel_op_close (Tchannel, int);
35 typedef long channel_op_n_read (Tchannel);
36 
37 typedef struct _channel_class_t
38 {
39   enum channel_type type;
40   channel_op_read * op_read;
41   channel_op_write * op_write;
42   channel_op_close * op_close;
43   channel_op_n_read * op_n_read;
44 } channel_class_t;
45 
46 #define CHANNEL_CLASS_TYPE(class) ((class) -> type)
47 #define CHANNEL_CLASS_OP_READ(class) ((class) -> op_read)
48 #define CHANNEL_CLASS_OP_WRITE(class) ((class) -> op_write)
49 #define CHANNEL_CLASS_OP_CLOSE(class) ((class) -> op_close)
50 #define CHANNEL_CLASS_OP_N_READ(class) ((class) -> op_n_read)
51 
52 #define CHANNEL_N_READ_UNKNOWN (-2)
53 #define CHANNEL_N_READ_WOULD_BLOCK (-1)
54 
55 struct channel
56 {
57   channel_class_t * class;
58   HANDLE handle;
59   unsigned int internal : 1;
60   unsigned int nonblocking : 1;
61   unsigned int buffered : 1;
62   unsigned int cooked : 1;
63 };
64 
65 #define CHANNEL_CLASS(c) ((NT_channel_table[c]) . class)
66 #define CHANNEL_HANDLE(c) ((NT_channel_table[c]) . handle)
67 #define CHANNEL_INTERNAL(c) ((NT_channel_table[c]) . internal)
68 #define CHANNEL_NONBLOCKING(c) ((NT_channel_table[c]) . nonblocking)
69 #define CHANNEL_BUFFERED(c) ((NT_channel_table[c]) . buffered)
70 #define CHANNEL_COOKED(c) ((NT_channel_table[c]) . cooked)
71 
72 #define CHANNEL_TYPE(channel) (CHANNEL_CLASS_TYPE (CHANNEL_CLASS (channel)))
73 #define MARK_CHANNEL_CLOSED(channel)					\
74   ((CHANNEL_HANDLE (channel)) = INVALID_HANDLE_VALUE)
75 #define CHANNEL_CLOSED_P(channel)					\
76   ((CHANNEL_HANDLE (channel)) == INVALID_HANDLE_VALUE)
77 #define CHANNEL_OPEN_P(channel)						\
78   ((CHANNEL_HANDLE (channel)) != INVALID_HANDLE_VALUE)
79 #define CHANNEL_BLOCKING_P(channel) (!CHANNEL_NONBLOCKING (channel))
80 
81 extern channel_class_t * NT_channel_class_generic;
82 extern channel_class_t * NT_channel_class_file;
83 extern channel_class_t * NT_channel_class_screen;
84 extern channel_class_t * NT_channel_class_console;
85 extern channel_class_t * NT_channel_class_anonymous_pipe;
86 extern channel_class_t * NT_channel_class_named_pipe;
87 extern struct channel * NT_channel_table;
88 
89 extern Tchannel NT_make_channel (HANDLE, channel_class_t *);
90 extern channel_class_t * NT_handle_channel_class (HANDLE);
91 extern Tchannel NT_open_handle (HANDLE);
92 extern void NT_handle_close_on_abort (HANDLE);
93 extern long NT_channel_n_read (Tchannel);
94 
95 #define BACKSPACE		'\b'
96 #define SPACE			' '
97 #define CARRIAGE_RETURN		'\r'
98 #define LINEFEED		'\n'
99 #define CNTRL_Z			'\032'
100 #define ASCII_DELETE		'\177'
101 
102 extern BOOL Screen_IsScreenHandle (HANDLE);
103 
104 #ifndef GUI
105 #  define CONSOLE_HANDLE (STDIN_HANDLE)
106 #  define IsConsoleHandle(h)  ((h) == CONSOLE_HANDLE)
107 #else
108 #  define IsConsoleHandle(h)  (0 == 1)
109 #endif
110 
111 #endif /* SCM_NTIO_H */
112