termios 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ 2002-10-13 akira yamada <akira@arika.org>
2
+
3
+ * termios.c
4
+ (termios_set_ispeed): fixed typo.
5
+ (termios_initialize): 0-cleared "@cc".
6
+ (Termios_to_termios): unknown cc-values are treated as 0.
7
+
8
+ * examples/modem_check.rb: renamed examples/modem_check1.rb.
9
+
10
+ * examples/modem_check0.rb, exampes/modem_check2.rb: new.
11
+
12
+ * version 0.9.4.
13
+
14
+ 2002-10-12 akira yamada <akira@arika.org>
15
+
16
+ * termios.c: revoked Termios::Termios#set_cc and removed some methods
17
+ such as Termios::Termios#iflag etc. they became attr_reader.
18
+
19
+ * version 0.9.3.
20
+
21
+ 2002-10-12 akira yamada <akira@arika.org>
22
+
23
+ * termios.c
24
+ (termios_cc): accepts index of c_cc.
25
+ (termios_set_a_cc): new function for Termios::Termios#set_cc.
26
+ (Init_termios): added new constants Termios::CCINDEX, Termios::IFLAGS,
27
+ Termios::OFLAGS, Termios::CFLAGS, Termios::LFLAGS and Termios::BAUD.
28
+
29
+ * examples/modem_check.rb: it did not work. rewrited.
30
+
31
+ * test/test0.rb: rewrited.
32
+
33
+ * version 0.9.2.
34
+
35
+ 2002-10-10 akira yamada <akira@arika.org>
36
+
37
+ * termios.c
38
+ (Init_termios): revived Termios::Termios#c_foo/c_foo= for backward
39
+ compatibility.
40
+
41
+ 2002-09-25 akira yamada <akira@arika.org>
42
+
43
+ * termios.c
44
+ (termios_clone): new method "clone" for Termios::Termios.
45
+ (Init_termios): revived Termios.new_termios for backward
46
+ compatibility.
47
+
48
+ * version 0.9.1.
49
+
50
+ 2002-09-25 akira yamada <akira@arika.org>
51
+
52
+ * Termios module can be included to IO classes and can extend IO
53
+ objects.
54
+
55
+ * now Termios::Termios is rb_cObject class.
56
+
57
+ * version 0.9.0.
58
+
59
+ Wed Nov 15 19:03:06 2000 akira yamada <akira@arika.org>
60
+
61
+ * renamed to ruby-termios.
62
+
63
+ Wed Dec 1 21:27:23 1999 GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp>
64
+
65
+ * termios.c: removed c_line.
66
+ * test1.rb: removed c_line.
67
+ * test3.rb: stty -echo.
68
+
69
+ Fri Feb 19 00:05:20 1999 akira yamada <akira@linux.or.jp>
70
+
71
+ * termios.c (Init_termios): now sTermios is hidden.
72
+ * test2.rb: rewrited.
73
+
74
+ Fri Thu 18 02:24:21 1999 akira yamada <akira@linux.or.jp>
75
+
76
+ * development started.
@@ -0,0 +1,8 @@
1
+ MANIFEST
2
+ README
3
+ extconf.rb
4
+ termios.c
5
+ test/test0.rb
6
+ test/test1.rb
7
+ test/test2.rb
8
+ test/test3.rb
data/README ADDED
@@ -0,0 +1,86 @@
1
+ ruby-termios
2
+ ============
3
+
4
+ Description
5
+ -----------
6
+
7
+ Ruby-termios enables you to use termios(3) interface.
8
+
9
+ Termios module are simple wrapper for termios(3). It can be included
10
+ into IO-family classes and can extend IO-family objects. In addition,
11
+ the methods can use as module function.
12
+
13
+
14
+ Requires
15
+ --------
16
+
17
+ * Ruby 1.6 (or later)
18
+
19
+
20
+ Installation
21
+ ------------
22
+
23
+ ruby extconf.rb
24
+ make
25
+ make install
26
+
27
+
28
+ Copyright
29
+ ---------
30
+
31
+ Ruby-termios for Ruby is copyrighted free software by akira yamada
32
+ <akira@arika.org>. You can redistribute it and/or modify it under either
33
+ the terms of the GPL, or the conditions below:
34
+
35
+ 1. You may make and give away verbatim copies of the source form of the
36
+ software without restriction, provided that you duplicate all of the
37
+ original copyright notices and associated disclaimers.
38
+
39
+ 2. You may modify your copy of the software in any way, provided that
40
+ you do at least ONE of the following:
41
+
42
+ a) place your modifications in the Public Domain or otherwise
43
+ make them Freely Available, such as by posting said
44
+ modifications to Usenet or an equivalent medium, or by allowing
45
+ the author to include your modifications in the software.
46
+
47
+ b) use the modified software only within your corporation or
48
+ organization.
49
+
50
+ c) rename any non-standard executables so the names do not conflict
51
+ with standard executables, which must also be provided.
52
+
53
+ d) make other distribution arrangements with the author.
54
+
55
+ 3. You may distribute the software in object code or executable
56
+ form, provided that you do at least ONE of the following:
57
+
58
+ a) distribute the executables and library files of the software,
59
+ together with instructions (in the manual page or equivalent)
60
+ on where to get the original distribution.
61
+
62
+ b) accompany the distribution with the machine-readable source of
63
+ the software.
64
+
65
+ c) give non-standard executables non-standard names, with
66
+ instructions on where to get the original software distribution.
67
+
68
+ d) make other distribution arrangements with the author.
69
+
70
+ 4. You may modify and include the part of the software into any other
71
+ software (possibly commercial). But some files in the distribution
72
+ are not written by the author, so that they are not under this terms.
73
+ They are gc.c(partly), utils.c(partly), regex.[ch], fnmatch.[ch],
74
+ glob.c, st.[ch] and some files under the ./missing directory. See
75
+ each file for the copying condition.
76
+
77
+ 5. The scripts and library files supplied as input to or produced as
78
+ output from the software do not automatically fall under the
79
+ copyright of the software, but belong to whomever generated them,
80
+ and may be sold commercially, and may be aggregated with this
81
+ software.
82
+
83
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
84
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
85
+ WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
86
+ PURPOSE.
data/TODO.ja ADDED
File without changes
@@ -0,0 +1,69 @@
1
+ require 'fcntl'
2
+ require 'termios'
3
+ include Termios
4
+
5
+ DEVICE = '/dev/modem'
6
+ BAUDRATE = B115200
7
+
8
+ def dev_open(path)
9
+ dev = open(DEVICE, File::RDWR | File::NONBLOCK)
10
+ mode = dev.fcntl(Fcntl::F_GETFL, 0)
11
+ dev.fcntl(Fcntl::F_SETFL, mode & ~File::NONBLOCK)
12
+ dev
13
+ end
14
+
15
+ def dump_termios(tio, banner)
16
+ puts banner
17
+ puts " ispeed = #{BAUDS[tio.ispeed]}, ospeed = #{BAUDS[tio.ospeed]}"
18
+ ["iflag", "oflag", "cflag", "lflag"].each do |x|
19
+ flag = tio.send(x)
20
+ flags = []
21
+ eval("#{x.upcase}S").each do |f, sym|
22
+ flags << sym.to_s if flag & f != 0
23
+ end
24
+ puts " #{x} = #{flags.sort.join(' | ')}"
25
+ end
26
+ print " cc ="
27
+ cc = tio.cc
28
+ cc.each_with_index do |x, idx|
29
+ print " #{CCINDEX[idx]}=#{x}" if CCINDEX.include?(idx)
30
+ end
31
+ puts
32
+ end
33
+
34
+ dev = dev_open(DEVICE)
35
+
36
+ oldtio = getattr(dev)
37
+ dump_termios(oldtio, "current tio:")
38
+
39
+ newtio = new_termios()
40
+ newtio.iflag = IGNPAR
41
+ newtio.oflag = 0
42
+ newtio.cflag = (CRTSCTS | CS8 | CREAD)
43
+ newtio.lflag = 0
44
+ newtio.cc[VTIME] = 0
45
+ newtio.cc[VMIN] = 1
46
+ newtio.ispeed = BAUDRATE
47
+ newtio.ospeed = BAUDRATE
48
+ dump_termios(newtio, "new tio:")
49
+
50
+ flush(dev, TCIOFLUSH)
51
+ setattr(dev, TCSANOW, newtio)
52
+ dump_termios(getattr(dev), "current tio:")
53
+
54
+ "AT\x0d".each_byte {|c|
55
+ c = c.chr
56
+ p [:write_char, c]
57
+ dev.putc c
58
+ d = dev.getc
59
+ p [:echo_back, d && d.chr || nil]
60
+ }
61
+
62
+ r = ''
63
+ while /OK\x0d\x0a/o !~ r
64
+ r << dev.getc.chr
65
+ p [:response, r]
66
+ end
67
+
68
+ setattr(dev, TCSANOW, oldtio)
69
+ dump_termios(getattr(dev), "current tio:")
@@ -0,0 +1,68 @@
1
+ require 'fcntl'
2
+ require 'termios'
3
+
4
+ DEVICE = '/dev/modem'
5
+ BAUDRATE = Termios::B115200
6
+
7
+ def dev_open(path)
8
+ dev = open(DEVICE, File::RDWR | File::NONBLOCK)
9
+ mode = dev.fcntl(Fcntl::F_GETFL, 0)
10
+ dev.fcntl(Fcntl::F_SETFL, mode & ~File::NONBLOCK)
11
+ dev
12
+ end
13
+
14
+ def dump_termios(tio, banner)
15
+ puts banner
16
+ puts " ispeed = #{Termios::BAUDS[tio.ispeed]}, ospeed = #{Termios::BAUDS[tio.ospeed]}"
17
+ ["iflag", "oflag", "cflag", "lflag"].each do |x|
18
+ flag = tio.send(x)
19
+ flags = []
20
+ eval("Termios::#{x.upcase}S").each do |f, sym|
21
+ flags << sym.to_s if flag & f != 0
22
+ end
23
+ puts " #{x} = #{flags.sort.join(' | ')}"
24
+ end
25
+ print " cc ="
26
+ cc = tio.cc
27
+ cc.each_with_index do |x, idx|
28
+ print " #{Termios::CCINDEX[idx]}=#{x}" if Termios::CCINDEX.include?(idx)
29
+ end
30
+ puts
31
+ end
32
+
33
+ dev = dev_open(DEVICE)
34
+
35
+ oldtio = Termios::tcgetattr(dev)
36
+ dump_termios(oldtio, "current tio:")
37
+
38
+ newtio = Termios::new_termios()
39
+ newtio.iflag = Termios::IGNPAR
40
+ newtio.oflag = 0
41
+ newtio.cflag = (Termios::CRTSCTS | Termios::CS8 | Termios::CREAD)
42
+ newtio.lflag = 0
43
+ newtio.cc[Termios::VTIME] = 0
44
+ newtio.cc[Termios::VMIN] = 1
45
+ newtio.ispeed = BAUDRATE
46
+ newtio.ospeed = BAUDRATE
47
+ dump_termios(newtio, "new tio:")
48
+
49
+ Termios::tcflush(dev, Termios::TCIOFLUSH)
50
+ Termios::tcsetattr(dev, Termios::TCSANOW, newtio)
51
+ dump_termios(Termios::tcgetattr(dev), "current tio:")
52
+
53
+ "AT\x0d".each_byte {|c|
54
+ c = c.chr
55
+ p [:write_char, c]
56
+ dev.putc c
57
+ d = dev.getc
58
+ p [:echo_back, d && d.chr || nil]
59
+ }
60
+
61
+ r = ''
62
+ while /OK\x0d\x0a/o !~ r
63
+ r << dev.getc.chr
64
+ p [:response, r]
65
+ end
66
+
67
+ Termios::tcsetattr(dev, Termios::TCSANOW, oldtio)
68
+ dump_termios(Termios::tcgetattr(dev), "current tio:")
@@ -0,0 +1,69 @@
1
+ require 'fcntl'
2
+ require 'termios'
3
+
4
+ DEVICE = '/dev/modem'
5
+ BAUDRATE = Termios::B115200
6
+
7
+ def dev_open(path)
8
+ dev = open(DEVICE, File::RDWR | File::NONBLOCK)
9
+ mode = dev.fcntl(Fcntl::F_GETFL, 0)
10
+ dev.fcntl(Fcntl::F_SETFL, mode & ~File::NONBLOCK)
11
+ dev
12
+ end
13
+
14
+ def dump_termios(tio, banner)
15
+ puts banner
16
+ puts " ispeed = #{Termios::BAUDS[tio.ispeed]}, ospeed = #{Termios::BAUDS[tio.ospeed]}"
17
+ ["iflag", "oflag", "cflag", "lflag"].each do |x|
18
+ flag = tio.send(x)
19
+ flags = []
20
+ eval("Termios::#{x.upcase}S").each do |f, sym|
21
+ flags << sym.to_s if flag & f != 0
22
+ end
23
+ puts " #{x} = #{flags.sort.join(' | ')}"
24
+ end
25
+ print " cc ="
26
+ cc = tio.cc
27
+ cc.each_with_index do |x, idx|
28
+ print " #{Termios::CCINDEX[idx]}=#{x}" if Termios::CCINDEX.include?(idx)
29
+ end
30
+ puts
31
+ end
32
+
33
+ dev = dev_open(DEVICE)
34
+ dev.extend Termios
35
+
36
+ oldtio = dev.tcgetattr
37
+ dump_termios(oldtio, "current tio:")
38
+
39
+ newtio = Termios::new_termios()
40
+ newtio.iflag = Termios::IGNPAR
41
+ newtio.oflag = 0
42
+ newtio.cflag = (Termios::CRTSCTS | Termios::CS8 | Termios::CREAD)
43
+ newtio.lflag = 0
44
+ newtio.cc[Termios::VTIME] = 0
45
+ newtio.cc[Termios::VMIN] = 1
46
+ newtio.ispeed = BAUDRATE
47
+ newtio.ospeed = BAUDRATE
48
+ dump_termios(newtio, "new tio:")
49
+
50
+ dev.tcflush(Termios::TCIOFLUSH)
51
+ dev.tcsetattr(Termios::TCSANOW, newtio)
52
+ dump_termios(dev.tcgetattr, "current tio:")
53
+
54
+ "AT\x0d".each_byte {|c|
55
+ c = c.chr
56
+ p [:write_char, c]
57
+ dev.putc c
58
+ d = dev.getc
59
+ p [:echo_back, d && d.chr || nil]
60
+ }
61
+
62
+ r = ''
63
+ while /OK\x0d\x0a/o !~ r
64
+ r << dev.getc.chr
65
+ p [:response, r]
66
+ end
67
+
68
+ dev.tcsetattr(Termios::TCSANOW, oldtio)
69
+ dump_termios(dev.tcgetattr, "current tio:")
@@ -0,0 +1,12 @@
1
+ # to input secretly [ruby-list:15968]
2
+ require 'termios'
3
+
4
+ oldt = Termios.tcgetattr($stdin)
5
+ newt = oldt.dup
6
+ newt.lflag &= ~Termios::ECHO
7
+ Termios.tcsetattr($stdin, Termios::TCSANOW, newt)
8
+ print "noecho> "
9
+ a = $stdin.gets
10
+ Termios.tcsetattr($stdin, Termios::TCSANOW, oldt)
11
+ print "\n"
12
+ p a
@@ -0,0 +1,14 @@
1
+ # to input secretly [ruby-list:15968]
2
+ require 'termios'
3
+
4
+ $stdin.extend Termios
5
+
6
+ oldt = $stdin.tcgetattr
7
+ newt = oldt.dup
8
+ newt.lflag &= ~Termios::ECHO
9
+ $stdin.tcsetattr(Termios::TCSANOW, newt)
10
+ print "noecho> "
11
+ a = $stdin.gets
12
+ $stdin.tcsetattr(Termios::TCSANOW, oldt)
13
+ print "\n"
14
+ p a
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ if have_header('termios.h') &&
4
+ have_header('unistd.h')
5
+ create_makefile('termios')
6
+ end
@@ -0,0 +1,949 @@
1
+ /*
2
+
3
+ A termios library for Ruby.
4
+ Copyright (C) 1999, 2000, 2002 akira yamada.
5
+ $Id: termios.c,v 1.8 2002/10/12 15:15:25 akira Exp $
6
+
7
+ */
8
+
9
+ #include "ruby.h"
10
+ #include "rubyio.h"
11
+ #include <termios.h>
12
+ #include <unistd.h>
13
+ #include <string.h>
14
+
15
+ static VALUE mTermios;
16
+ static VALUE cTermios;
17
+ static VALUE tcsetattr_opt, tcflush_qs, tcflow_act;
18
+ static ID id_iflag, id_oflag, id_cflag, id_lflag, id_cc, id_ispeed, id_ospeed;
19
+
20
+ static VALUE
21
+ termios_set_iflag(self, value)
22
+ VALUE self, value;
23
+ {
24
+ Check_Type(value, T_FIXNUM);
25
+ rb_ivar_set(self, id_iflag, value);
26
+
27
+ return value;
28
+ }
29
+
30
+ static VALUE
31
+ termios_set_oflag(self, value)
32
+ VALUE self, value;
33
+ {
34
+ Check_Type(value, T_FIXNUM);
35
+ rb_ivar_set(self, id_oflag, value);
36
+
37
+ return value;
38
+ }
39
+
40
+ static VALUE
41
+ termios_set_cflag(self, value)
42
+ VALUE self, value;
43
+ {
44
+ Check_Type(value, T_FIXNUM);
45
+ rb_ivar_set(self, id_cflag, value);
46
+
47
+ return value;
48
+ }
49
+
50
+ static VALUE
51
+ termios_set_lflag(self, value)
52
+ VALUE self, value;
53
+ {
54
+ Check_Type(value, T_FIXNUM);
55
+ rb_ivar_set(self, id_lflag, value);
56
+
57
+ return value;
58
+ }
59
+
60
+ static VALUE
61
+ termios_set_cc(self, value)
62
+ VALUE self, value;
63
+ {
64
+ Check_Type(value, T_ARRAY);
65
+ rb_ivar_set(self, id_cc, value);
66
+
67
+ return value;
68
+ }
69
+
70
+ static VALUE
71
+ termios_set_ispeed(self, value)
72
+ VALUE self, value;
73
+ {
74
+ Check_Type(value, T_FIXNUM);
75
+ rb_ivar_set(self, id_ispeed, value);
76
+
77
+ return value;
78
+ }
79
+
80
+ static VALUE
81
+ termios_set_ospeed(self, value)
82
+ VALUE self, value;
83
+ {
84
+ Check_Type(value, T_FIXNUM);
85
+ rb_ivar_set(self, id_ospeed, value);
86
+
87
+ return value;
88
+ }
89
+
90
+ static VALUE
91
+ termios_initialize(argc, argv, self)
92
+ int argc;
93
+ VALUE *argv;
94
+ VALUE self;
95
+ {
96
+ VALUE c_iflag, c_oflag, c_cflag, c_lflag, c_cc, c_ispeed, c_ospeed;
97
+ VALUE cc_ary;
98
+ int i;
99
+
100
+ cc_ary = rb_ary_new2(NCCS);
101
+ for (i = 0; i < NCCS; i++) {
102
+ rb_ary_store(cc_ary, i, INT2FIX(0));
103
+ }
104
+
105
+ rb_ivar_set(self, id_iflag, Qnil);
106
+ rb_ivar_set(self, id_oflag, Qnil);
107
+ rb_ivar_set(self, id_cflag, Qnil);
108
+ rb_ivar_set(self, id_lflag, Qnil);
109
+ rb_ivar_set(self, id_cc, cc_ary);
110
+ rb_ivar_set(self, id_ispeed, Qnil);
111
+ rb_ivar_set(self, id_ospeed, Qnil);
112
+
113
+ rb_scan_args(argc, argv, "07",
114
+ &c_iflag, &c_oflag, &c_cflag, &c_lflag,
115
+ &c_cc, &c_ispeed, &c_ospeed);
116
+
117
+ if (!NIL_P(c_iflag))
118
+ termios_set_iflag(self, c_iflag);
119
+
120
+ if (!NIL_P(c_oflag))
121
+ termios_set_oflag(self, c_oflag);
122
+
123
+ if (!NIL_P(c_cflag))
124
+ termios_set_cflag(self, c_cflag);
125
+
126
+ if (!NIL_P(c_lflag))
127
+ termios_set_lflag(self, c_lflag);
128
+
129
+ if (!NIL_P(c_cc))
130
+ termios_set_cc(self, c_cc);
131
+
132
+ if (!NIL_P(c_ispeed))
133
+ termios_set_ispeed(self, c_ispeed);
134
+
135
+ if (!NIL_P(c_ospeed))
136
+ termios_set_ispeed(self, c_ospeed);
137
+
138
+ return self;
139
+ }
140
+
141
+ static VALUE
142
+ termios_to_Termios(t)
143
+ struct termios *t;
144
+ {
145
+ int i;
146
+ VALUE obj, cc_ary;
147
+
148
+ obj = rb_funcall(cTermios, rb_intern("new"), 0);
149
+
150
+ termios_set_iflag(obj, INT2FIX(t->c_iflag));
151
+ termios_set_oflag(obj, INT2FIX(t->c_oflag));
152
+ termios_set_cflag(obj, INT2FIX(t->c_cflag));
153
+ termios_set_lflag(obj, INT2FIX(t->c_lflag));
154
+
155
+ cc_ary = rb_ary_new2(NCCS);
156
+ for (i = 0; i < NCCS; i++) {
157
+ rb_ary_store(cc_ary, i, INT2FIX(t->c_cc[i]));
158
+ }
159
+ termios_set_cc(obj, cc_ary);
160
+
161
+ termios_set_ispeed(obj, INT2FIX(cfgetispeed(t)));
162
+ termios_set_ospeed(obj, INT2FIX(cfgetospeed(t)));
163
+
164
+ return obj;
165
+ }
166
+
167
+ static void
168
+ Termios_to_termios(obj, t)
169
+ VALUE obj;
170
+ struct termios *t;
171
+ {
172
+ int i;
173
+ VALUE cc_ary;
174
+
175
+ t->c_iflag = FIX2INT(rb_ivar_get(obj, id_iflag));
176
+ t->c_oflag = FIX2INT(rb_ivar_get(obj, id_oflag));
177
+ t->c_cflag = FIX2INT(rb_ivar_get(obj, id_cflag));
178
+ t->c_lflag = FIX2INT(rb_ivar_get(obj, id_lflag));
179
+
180
+ cc_ary = rb_ivar_get(obj, id_cc);
181
+ for (i = 0; i < NCCS; i++) {
182
+ if (TYPE(RARRAY(cc_ary)->ptr[i]) == T_FIXNUM) {
183
+ t->c_cc[i] = NUM2INT(RARRAY(cc_ary)->ptr[i]);
184
+ }
185
+ else {
186
+ t->c_cc[i] = 0;
187
+ }
188
+ }
189
+
190
+ cfsetispeed(t, FIX2INT(rb_ivar_get(obj, id_ispeed)));
191
+ cfsetospeed(t, FIX2INT(rb_ivar_get(obj, id_ospeed)));
192
+ }
193
+
194
+
195
+ static VALUE
196
+ termios_tcgetattr(io)
197
+ VALUE io;
198
+ {
199
+ struct termios t;
200
+ OpenFile *fptr;
201
+
202
+ Check_Type(io, T_FILE);
203
+ GetOpenFile(io, fptr);
204
+ if (tcgetattr(fileno(fptr->f), &t) < 0) {
205
+ rb_raise(rb_eRuntimeError,
206
+ "can't get terminal parameters (%s)", strerror(errno));
207
+ }
208
+
209
+ return termios_to_Termios(&t);
210
+ }
211
+
212
+ static VALUE
213
+ termios_s_tcgetattr(obj, io)
214
+ VALUE obj, io;
215
+ {
216
+ return termios_tcgetattr(io);
217
+ }
218
+
219
+ static VALUE
220
+ termios_tcsetattr(io, opt, param)
221
+ VALUE io, opt, param;
222
+ {
223
+ VALUE old;
224
+ OpenFile *fptr;
225
+ struct termios t;
226
+ int tcsetattr_option;
227
+
228
+ Check_Type(io, T_FILE);
229
+ Check_Type(opt, T_FIXNUM);
230
+ if (CLASS_OF(param) != cTermios) {
231
+ char *type = rb_class2name(CLASS_OF(param));
232
+ rb_raise(rb_eArgError,
233
+ "wrong argument type %s (expected Termios::Termios)",
234
+ type);
235
+ }
236
+
237
+ tcsetattr_option = FIX2INT(opt);
238
+ if (rb_ary_includes(tcsetattr_opt, opt) != Qtrue) {
239
+ rb_raise(rb_eArgError,
240
+ "wrong option value %d", tcsetattr_option);
241
+ }
242
+
243
+ old = termios_tcgetattr(io);
244
+ GetOpenFile(io, fptr);
245
+ Termios_to_termios(param, &t);
246
+ if (tcsetattr(fileno(fptr->f), tcsetattr_option, &t) < 0) {
247
+ rb_raise(rb_eRuntimeError,
248
+ "can't set terminal parameters (%s)", strerror(errno));
249
+ }
250
+
251
+ return old;
252
+ }
253
+
254
+ static VALUE
255
+ termios_s_tcsetattr(obj, io, opt, param)
256
+ VALUE obj, io, opt, param;
257
+ {
258
+ return termios_tcsetattr(io, opt, param);
259
+ }
260
+
261
+ static VALUE
262
+ termios_tcsendbreak(io, duration)
263
+ VALUE io, duration;
264
+ {
265
+ OpenFile *fptr;
266
+
267
+ Check_Type(io, T_FILE);
268
+ Check_Type(duration, T_FIXNUM);
269
+
270
+ GetOpenFile(io, fptr);
271
+ if (tcsendbreak(fileno(fptr->f), FIX2INT(duration)) < 0) {
272
+ rb_raise(rb_eRuntimeError,
273
+ "can't transmits break (%s)", strerror(errno));
274
+ }
275
+
276
+ return Qtrue;
277
+ }
278
+
279
+ static VALUE
280
+ termios_s_tcsendbreak(obj, io, duration)
281
+ VALUE obj, io, duration;
282
+ {
283
+ return termios_tcsendbreak(io, duration);
284
+ }
285
+
286
+ static VALUE
287
+ termios_tcdrain(io)
288
+ VALUE io;
289
+ {
290
+ OpenFile *fptr;
291
+
292
+ Check_Type(io, T_FILE);
293
+
294
+ GetOpenFile(io, fptr);
295
+ if (tcdrain(fileno(fptr->f)) < 0) {
296
+ rb_raise(rb_eRuntimeError, "can't drain (%s)", strerror(errno));
297
+ }
298
+
299
+ return Qtrue;
300
+ }
301
+
302
+ static VALUE
303
+ termios_s_tcdrain(obj, io)
304
+ VALUE obj, io;
305
+ {
306
+ return termios_tcdrain(io);
307
+ }
308
+
309
+ static VALUE
310
+ termios_tcflush(io, qs)
311
+ VALUE io, qs;
312
+ {
313
+ OpenFile *fptr;
314
+ int queue_selector;
315
+
316
+ Check_Type(io, T_FILE);
317
+ Check_Type(qs, T_FIXNUM);
318
+ queue_selector = FIX2INT(qs);
319
+ if (rb_ary_includes(tcflush_qs, qs) != Qtrue) {
320
+ rb_raise(rb_eTypeError,
321
+ "wrong queue-selector value %d", queue_selector);
322
+ }
323
+
324
+ GetOpenFile(io, fptr);
325
+ if (tcflush(fileno(fptr->f), queue_selector) < 0) {
326
+ rb_raise(rb_eRuntimeError, "can't flush (%s)", strerror(errno));
327
+ }
328
+
329
+ return Qtrue;
330
+ }
331
+
332
+ static VALUE
333
+ termios_s_tcflush(obj, io, qs)
334
+ VALUE obj, io, qs;
335
+ {
336
+ return termios_tcflush(io, qs);
337
+ }
338
+
339
+ static VALUE
340
+ termios_tcflow(io, act)
341
+ VALUE io, act;
342
+ {
343
+ OpenFile *fptr;
344
+ int action;
345
+
346
+ Check_Type(io, T_FILE);
347
+ Check_Type(act, T_FIXNUM);
348
+ action = FIX2INT(act);
349
+ if (rb_ary_includes(tcflow_act, act) != Qtrue) {
350
+ rb_raise(rb_eArgError,
351
+ "wrong action value %d", action);
352
+ }
353
+
354
+ GetOpenFile(io, fptr);
355
+ if (tcflow(fileno(fptr->f), action) < 0) {
356
+ rb_raise(rb_eRuntimeError,
357
+ "can't control transmitting data flow (%s)", strerror(errno));
358
+ }
359
+
360
+ return Qtrue;
361
+ }
362
+
363
+ static VALUE
364
+ termios_s_tcflow(obj, io, act)
365
+ VALUE obj, io, act;
366
+ {
367
+ return termios_tcflow(io, act);
368
+ }
369
+
370
+ static VALUE
371
+ termios_tcgetpgrp(io)
372
+ VALUE io;
373
+ {
374
+ OpenFile *fptr;
375
+ int pid;
376
+
377
+ Check_Type(io, T_FILE);
378
+ GetOpenFile(io, fptr);
379
+ if ((pid = tcgetpgrp(fileno(fptr->f))) < 0) {
380
+ rb_raise(rb_eRuntimeError,
381
+ "can't get process group id (%s)", strerror(errno));
382
+ }
383
+
384
+ return INT2FIX(pid);
385
+ }
386
+
387
+ static VALUE
388
+ termios_s_tcgetpgrp(obj, io)
389
+ VALUE obj, io;
390
+ {
391
+ return termios_tcgetpgrp(io);
392
+ }
393
+
394
+ static VALUE
395
+ termios_tcsetpgrp(io, pgrpid)
396
+ VALUE io, pgrpid;
397
+ {
398
+ OpenFile *fptr;
399
+
400
+ Check_Type(io, T_FILE);
401
+ Check_Type(pgrpid, T_FIXNUM);
402
+
403
+ GetOpenFile(io, fptr);
404
+ if (tcsetpgrp(fileno(fptr->f), FIX2INT(pgrpid)) < 0) {
405
+ rb_raise(rb_eRuntimeError,
406
+ "can't set process group id (%s)", strerror(errno));
407
+ }
408
+
409
+ return Qtrue;
410
+ }
411
+
412
+ static VALUE
413
+ termios_s_tcsetpgrp(obj, io, pgrpid)
414
+ VALUE obj, io, pgrpid;
415
+ {
416
+ return termios_tcsetpgrp(io, pgrpid);
417
+ }
418
+
419
+ static VALUE
420
+ termios_s_newtermios(argc, argv, klass)
421
+ int argc;
422
+ VALUE *argv;
423
+ VALUE klass;
424
+ {
425
+ return rb_funcall2(cTermios, rb_intern("new"), argc, argv);
426
+ }
427
+
428
+ void
429
+ Init_termios()
430
+ {
431
+ VALUE ccindex, iflags, oflags, cflags, lflags, bauds;
432
+
433
+ /* module Termios */
434
+
435
+ mTermios = rb_define_module("Termios");
436
+
437
+ rb_define_module_function(mTermios,"tcgetattr", termios_s_tcgetattr, 1);
438
+ rb_define_module_function(mTermios, "getattr", termios_s_tcgetattr, 1);
439
+ rb_define_method(mTermios, "tcgetattr", termios_tcgetattr, 0);
440
+
441
+ rb_define_module_function(mTermios,"tcsetattr", termios_s_tcsetattr, 3);
442
+ rb_define_module_function(mTermios, "setattr", termios_s_tcsetattr, 3);
443
+ rb_define_method(mTermios, "tcsetattr", termios_tcsetattr, 2);
444
+
445
+ rb_define_module_function(mTermios,"tcsendbreak",termios_s_tcsendbreak,2);
446
+ rb_define_module_function(mTermios, "sendbreak",termios_s_tcsendbreak,2);
447
+ rb_define_method(mTermios, "tcsendbreak",termios_tcsendbreak, 1);
448
+
449
+ rb_define_module_function(mTermios,"tcdrain", termios_s_tcdrain, 1);
450
+ rb_define_module_function(mTermios, "drain", termios_s_tcdrain, 1);
451
+ rb_define_method(mTermios, "tcdrain", termios_tcdrain, 0);
452
+
453
+ rb_define_module_function(mTermios,"tcflush", termios_s_tcflush, 2);
454
+ rb_define_module_function(mTermios, "flush", termios_s_tcflush, 2);
455
+ rb_define_method(mTermios, "tcflush", termios_tcflush, 1);
456
+
457
+ rb_define_module_function(mTermios,"tcflow", termios_s_tcflow, 2);
458
+ rb_define_module_function(mTermios, "flow", termios_s_tcflow, 2);
459
+ rb_define_method(mTermios, "tcflow", termios_tcflow, 1);
460
+
461
+ rb_define_module_function(mTermios,"tcgetpgrp", termios_s_tcgetpgrp, 1);
462
+ rb_define_module_function(mTermios, "getpgrp", termios_s_tcgetpgrp, 1);
463
+ rb_define_method(mTermios, "tcgetpgrp", termios_tcgetpgrp, 0);
464
+
465
+ rb_define_module_function(mTermios,"tcsetpgrp", termios_s_tcsetpgrp, 2);
466
+ rb_define_module_function(mTermios, "setpgrp", termios_s_tcsetpgrp, 2);
467
+ rb_define_method(mTermios, "tcsetpgrp", termios_tcsetpgrp, 1);
468
+
469
+ rb_define_module_function(mTermios,"new_termios",termios_s_newtermios, -1);
470
+
471
+ /* class Termios::Termios */
472
+
473
+ cTermios = rb_define_class_under(mTermios, "Termios", rb_cObject);
474
+
475
+ id_iflag = rb_intern("@iflag");
476
+ id_oflag = rb_intern("@oflag");
477
+ id_cflag = rb_intern("@cflag");
478
+ id_lflag = rb_intern("@lflag");
479
+ id_cc = rb_intern("@cc");
480
+ id_ispeed = rb_intern("@ispeed");
481
+ id_ospeed = rb_intern("@ospeed");
482
+
483
+ rb_attr(cTermios, rb_intern("iflag"), 1, 0, Qtrue);
484
+ rb_attr(cTermios, rb_intern("oflag"), 1, 0, Qtrue);
485
+ rb_attr(cTermios, rb_intern("cflag"), 1, 0, Qtrue);
486
+ rb_attr(cTermios, rb_intern("lflag"), 1, 0, Qtrue);
487
+ rb_attr(cTermios, rb_intern("cc"), 1, 0, Qtrue);
488
+ rb_attr(cTermios, rb_intern("ispeed"), 1, 0, Qtrue);
489
+ rb_attr(cTermios, rb_intern("ospeed"), 1, 0, Qtrue);
490
+
491
+ rb_define_private_method(cTermios, "initialize", termios_initialize, -1);
492
+
493
+ rb_define_method(cTermios, "iflag=", termios_set_iflag, 1);
494
+ rb_define_method(cTermios, "oflag=", termios_set_oflag, 1);
495
+ rb_define_method(cTermios, "cflag=", termios_set_cflag, 1);
496
+ rb_define_method(cTermios, "lflag=", termios_set_lflag, 1);
497
+ rb_define_method(cTermios, "cc=", termios_set_cc, 1);
498
+ rb_define_method(cTermios, "ispeed=", termios_set_ispeed, 1);
499
+ rb_define_method(cTermios, "ospeed=", termios_set_ospeed, 1);
500
+
501
+ rb_define_alias(cTermios, "c_iflag", "iflag");
502
+ rb_define_alias(cTermios, "c_iflag=", "iflag=");
503
+ rb_define_alias(cTermios, "c_oflag", "oflag");
504
+ rb_define_alias(cTermios, "c_oflag=", "oflag=");
505
+ rb_define_alias(cTermios, "c_cflag", "cflag");
506
+ rb_define_alias(cTermios, "c_cflag=", "cflag=");
507
+ rb_define_alias(cTermios, "c_lflag", "lflag");
508
+ rb_define_alias(cTermios, "c_lflag=", "lflag=");
509
+ rb_define_alias(cTermios, "c_cc", "cc");
510
+ rb_define_alias(cTermios, "c_cc=", "cc=");
511
+ rb_define_alias(cTermios, "c_ispeed", "ispeed");
512
+ rb_define_alias(cTermios, "c_ispeed=", "ispeed=");
513
+ rb_define_alias(cTermios, "c_ospeed", "ospeed");
514
+ rb_define_alias(cTermios, "c_ospeed=", "ospeed=");
515
+
516
+ /* constants under Termios module */
517
+
518
+ rb_define_const(mTermios, "NCCS", INT2FIX(NCCS));
519
+
520
+ ccindex = rb_hash_new();
521
+ rb_define_const(mTermios, "CCINDEX", ccindex);
522
+
523
+ iflags = rb_hash_new();
524
+ rb_define_const(mTermios, "IFLAGS", iflags);
525
+
526
+ oflags = rb_hash_new();
527
+ rb_define_const(mTermios, "OFLAGS", oflags);
528
+
529
+ cflags = rb_hash_new();
530
+ rb_define_const(mTermios, "CFLAGS", cflags);
531
+
532
+ lflags = rb_hash_new();
533
+ rb_define_const(mTermios, "LFLAGS", lflags);
534
+
535
+ bauds = rb_hash_new();
536
+ rb_define_const(mTermios, "BAUDS", bauds);
537
+
538
+ tcsetattr_opt = rb_ary_new();
539
+ rb_define_const(mTermios, "SETATTR_OPTS", tcsetattr_opt);
540
+
541
+ tcflush_qs = rb_ary_new();
542
+ rb_define_const(mTermios, "FLUSH_QSELECTORS", tcflush_qs);
543
+
544
+ tcflow_act = rb_ary_new();
545
+ rb_define_const(mTermios, "FLOW_ACTIONS", tcflow_act);
546
+
547
+ #define define_flag(hash, flag) \
548
+ { \
549
+ rb_define_const(mTermios, #flag, INT2FIX(flag)); \
550
+ rb_hash_aset(hash, rb_const_get(mTermios, rb_intern(#flag)), \
551
+ ID2SYM(rb_intern(#flag))); \
552
+ }
553
+ #define define_flag2(ary, flag) \
554
+ { \
555
+ rb_define_const(mTermios, #flag, INT2FIX(flag)); \
556
+ rb_ary_push(ary, rb_const_get(mTermios, rb_intern(#flag)));\
557
+ }
558
+
559
+ /* c_cc characters */
560
+ #ifdef VINTR
561
+ define_flag(ccindex, VINTR);
562
+ #endif
563
+ #ifdef VQUIT
564
+ define_flag(ccindex, VQUIT);
565
+ #endif
566
+ #ifdef VERASE
567
+ define_flag(ccindex, VERASE);
568
+ #endif
569
+ #ifdef VKILL
570
+ define_flag(ccindex, VKILL);
571
+ #endif
572
+ #ifdef VEOF
573
+ define_flag(ccindex, VEOF);
574
+ #endif
575
+ #ifdef VTIME
576
+ define_flag(ccindex, VTIME);
577
+ #endif
578
+ #ifdef VMIN
579
+ define_flag(ccindex, VMIN);
580
+ #endif
581
+ #ifdef VSWTC
582
+ define_flag(ccindex, VSWTC);
583
+ #endif
584
+ #ifdef VSTART
585
+ define_flag(ccindex, VSTART);
586
+ #endif
587
+ #ifdef VSTOP
588
+ define_flag(ccindex, VSTOP);
589
+ #endif
590
+ #ifdef VSUSP
591
+ define_flag(ccindex, VSUSP);
592
+ #endif
593
+ #ifdef VEOL
594
+ define_flag(ccindex, VEOL);
595
+ #endif
596
+ #ifdef VREPRINT
597
+ define_flag(ccindex, VREPRINT);
598
+ #endif
599
+ #ifdef VDISCARD
600
+ define_flag(ccindex, VDISCARD);
601
+ #endif
602
+ #ifdef VWERASE
603
+ define_flag(ccindex, VWERASE);
604
+ #endif
605
+ #ifdef VLNEXT
606
+ define_flag(ccindex, VLNEXT);
607
+ #endif
608
+ #ifdef VEOL2
609
+ define_flag(ccindex, VEOL2);
610
+ #endif
611
+
612
+ /* c_iflag bits */
613
+ #ifdef IGNBRK
614
+ define_flag(iflags, IGNBRK);
615
+ #endif
616
+ #ifdef BRKINT
617
+ define_flag(iflags, BRKINT);
618
+ #endif
619
+ #ifdef IGNPAR
620
+ define_flag(iflags, IGNPAR);
621
+ #endif
622
+ #ifdef PARMRK
623
+ define_flag(iflags, PARMRK);
624
+ #endif
625
+ #ifdef INPCK
626
+ define_flag(iflags, INPCK);
627
+ #endif
628
+ #ifdef ISTRIP
629
+ define_flag(iflags, ISTRIP);
630
+ #endif
631
+ #ifdef INLCR
632
+ define_flag(iflags, INLCR);
633
+ #endif
634
+ #ifdef IGNCR
635
+ define_flag(iflags, IGNCR);
636
+ #endif
637
+ #ifdef ICRNL
638
+ define_flag(iflags, ICRNL);
639
+ #endif
640
+ #ifdef IUCLC
641
+ define_flag(iflags, IUCLC);
642
+ #endif
643
+ #ifdef IXON
644
+ define_flag(iflags, IXON);
645
+ #endif
646
+ #ifdef IXANY
647
+ define_flag(iflags, IXANY);
648
+ #endif
649
+ #ifdef IXOFF
650
+ define_flag(iflags, IXOFF);
651
+ #endif
652
+ #ifdef IMAXBEL
653
+ define_flag(iflags, IMAXBEL);
654
+ #endif
655
+
656
+ /* c_oflag bits */
657
+ #ifdef OPOST
658
+ define_flag(oflags, OPOST);
659
+ #endif
660
+ #ifdef OLCUC
661
+ define_flag(oflags, OLCUC);
662
+ #endif
663
+ #ifdef ONLCR
664
+ define_flag(oflags, ONLCR);
665
+ #endif
666
+ #ifdef OCRNL
667
+ define_flag(oflags, OCRNL);
668
+ #endif
669
+ #ifdef ONOCR
670
+ define_flag(oflags, ONOCR);
671
+ #endif
672
+ #ifdef ONLRET
673
+ define_flag(oflags, ONLRET);
674
+ #endif
675
+ #ifdef OFILL
676
+ define_flag(oflags, OFILL);
677
+ #endif
678
+ #ifdef OFDEL
679
+ define_flag(oflags, OFDEL);
680
+ #endif
681
+ #ifdef NLDLY
682
+ define_flag(oflags, NLDLY);
683
+ #endif
684
+ #ifdef NL0
685
+ define_flag(oflags, NL0);
686
+ #endif
687
+ #ifdef NL1
688
+ define_flag(oflags, NL1);
689
+ #endif
690
+ #ifdef CRDLY
691
+ define_flag(oflags, CRDLY);
692
+ #endif
693
+ #ifdef CR0
694
+ define_flag(oflags, CR0);
695
+ #endif
696
+ #ifdef CR1
697
+ define_flag(oflags, CR1);
698
+ #endif
699
+ #ifdef CR2
700
+ define_flag(oflags, CR2);
701
+ #endif
702
+ #ifdef CR3
703
+ define_flag(oflags, CR3);
704
+ #endif
705
+ #ifdef TABDLY
706
+ define_flag(oflags, TABDLY);
707
+ #endif
708
+ #ifdef TAB0
709
+ define_flag(oflags, TAB0);
710
+ #endif
711
+ #ifdef TAB1
712
+ define_flag(oflags, TAB1);
713
+ #endif
714
+ #ifdef TAB2
715
+ define_flag(oflags, TAB2);
716
+ #endif
717
+ #ifdef TAB3
718
+ define_flag(oflags, TAB3);
719
+ #endif
720
+ #ifdef XTABS
721
+ define_flag(oflags, XTABS);
722
+ #endif
723
+ #ifdef BSDLY
724
+ define_flag(oflags, BSDLY);
725
+ #endif
726
+ #ifdef BS0
727
+ define_flag(oflags, BS0);
728
+ #endif
729
+ #ifdef BS1
730
+ define_flag(oflags, BS1);
731
+ #endif
732
+ #ifdef VTDLY
733
+ define_flag(oflags, VTDLY);
734
+ #endif
735
+ #ifdef VT0
736
+ define_flag(oflags, VT0);
737
+ #endif
738
+ #ifdef VT1
739
+ define_flag(oflags, VT1);
740
+ #endif
741
+ #ifdef FFDLY
742
+ define_flag(oflags, FFDLY);
743
+ #endif
744
+ #ifdef FF0
745
+ define_flag(oflags, FF0);
746
+ #endif
747
+ #ifdef FF1
748
+ define_flag(oflags, FF1);
749
+ #endif
750
+
751
+ /* c_cflag bit meaning */
752
+ #ifdef CBAUD
753
+ define_flag(cflags, CBAUD);
754
+ #endif
755
+ #ifdef B0
756
+ define_flag(bauds, B0);
757
+ #endif
758
+ #ifdef B50
759
+ define_flag(bauds, B50);
760
+ #endif
761
+ #ifdef B75
762
+ define_flag(bauds, B75);
763
+ #endif
764
+ #ifdef B110
765
+ define_flag(bauds, B110);
766
+ #endif
767
+ #ifdef B134
768
+ define_flag(bauds, B134);
769
+ #endif
770
+ #ifdef B150
771
+ define_flag(bauds, B150);
772
+ #endif
773
+ #ifdef B200
774
+ define_flag(bauds, B200);
775
+ #endif
776
+ #ifdef B300
777
+ define_flag(bauds, B300);
778
+ #endif
779
+ #ifdef B600
780
+ define_flag(bauds, B600);
781
+ #endif
782
+ #ifdef B1200
783
+ define_flag(bauds, B1200);
784
+ #endif
785
+ #ifdef B1800
786
+ define_flag(bauds, B1800);
787
+ #endif
788
+ #ifdef B2400
789
+ define_flag(bauds, B2400);
790
+ #endif
791
+ #ifdef B4800
792
+ define_flag(bauds, B4800);
793
+ #endif
794
+ #ifdef B9600
795
+ define_flag(bauds, B9600);
796
+ #endif
797
+ #ifdef B19200
798
+ define_flag(bauds, B19200);
799
+ #endif
800
+ #ifdef B38400
801
+ define_flag(bauds, B38400);
802
+ #endif
803
+ #ifdef EXTA
804
+ define_flag(cflags, EXTA);
805
+ #endif
806
+ #ifdef EXTB
807
+ define_flag(cflags, EXTB);
808
+ #endif
809
+ #ifdef CSIZE
810
+ define_flag(cflags, CSIZE);
811
+ #endif
812
+ #ifdef CS5
813
+ define_flag(cflags, CS5);
814
+ #endif
815
+ #ifdef CS6
816
+ define_flag(cflags, CS6);
817
+ #endif
818
+ #ifdef CS7
819
+ define_flag(cflags, CS7);
820
+ #endif
821
+ #ifdef CS8
822
+ define_flag(cflags, CS8);
823
+ #endif
824
+ #ifdef CSTOPB
825
+ define_flag(cflags, CSTOPB);
826
+ #endif
827
+ #ifdef CREAD
828
+ define_flag(cflags, CREAD);
829
+ #endif
830
+ #ifdef PARENB
831
+ define_flag(cflags, PARENB);
832
+ #endif
833
+ #ifdef PARODD
834
+ define_flag(cflags, PARODD);
835
+ #endif
836
+ #ifdef HUPCL
837
+ define_flag(cflags, HUPCL);
838
+ #endif
839
+ #ifdef CLOCAL
840
+ define_flag(cflags, CLOCAL);
841
+ #endif
842
+ #ifdef CBAUDEX
843
+ define_flag(cflags, CBAUDEX);
844
+ #endif
845
+ #ifdef B57600
846
+ define_flag(bauds, B57600);
847
+ #endif
848
+ #ifdef B115200
849
+ define_flag(bauds, B115200);
850
+ #endif
851
+ #ifdef B230400
852
+ define_flag(bauds, B230400);
853
+ #endif
854
+ #ifdef B460800
855
+ define_flag(bauds, B460800);
856
+ #endif
857
+ #ifdef CIBAUD
858
+ define_flag(cflags, CIBAUD);
859
+ #endif
860
+ #ifdef CRTSCTS
861
+ define_flag(cflags, CRTSCTS);
862
+ #endif
863
+
864
+ /* c_lflag bits */
865
+ #ifdef ISIG
866
+ define_flag(lflags, ISIG);
867
+ #endif
868
+ #ifdef ICANON
869
+ define_flag(lflags, ICANON);
870
+ #endif
871
+ #ifdef XCASE
872
+ define_flag(lflags, XCASE);
873
+ #endif
874
+ #ifdef ECHO
875
+ define_flag(lflags, ECHO);
876
+ #endif
877
+ #ifdef ECHOE
878
+ define_flag(lflags, ECHOE);
879
+ #endif
880
+ #ifdef ECHOK
881
+ define_flag(lflags, ECHOK);
882
+ #endif
883
+ #ifdef ECHONL
884
+ define_flag(lflags, ECHONL);
885
+ #endif
886
+ #ifdef NOFLSH
887
+ define_flag(lflags, NOFLSH);
888
+ #endif
889
+ #ifdef TOSTOP
890
+ define_flag(lflags, TOSTOP);
891
+ #endif
892
+ #ifdef ECHOCTL
893
+ define_flag(lflags, ECHOCTL);
894
+ #endif
895
+ #ifdef ECHOPRT
896
+ define_flag(lflags, ECHOPRT);
897
+ #endif
898
+ #ifdef ECHOKE
899
+ define_flag(lflags, ECHOKE);
900
+ #endif
901
+ #ifdef FLUSHO
902
+ define_flag(lflags, FLUSHO);
903
+ #endif
904
+ #ifdef PENDIN
905
+ define_flag(lflags, PENDIN);
906
+ #endif
907
+ #ifdef IEXTEN
908
+ define_flag(lflags, IEXTEN);
909
+ #endif
910
+
911
+ /* tcflow() and TCXONC use these */
912
+ #ifdef TCOOFF
913
+ define_flag2(tcflow_act, TCOOFF);
914
+ #endif
915
+ #ifdef TCOON
916
+ define_flag2(tcflow_act, TCOON);
917
+ #endif
918
+ #ifdef TCIOFF
919
+ define_flag2(tcflow_act, TCIOFF);
920
+ #endif
921
+ #ifdef TCION
922
+ define_flag2(tcflow_act, TCION);
923
+ #endif
924
+
925
+ /* tcflush() and TCFLSH use these */
926
+ #ifdef TCIFLUSH
927
+ define_flag2(tcflush_qs, TCIFLUSH);
928
+ #endif
929
+ #ifdef TCOFLUSH
930
+ define_flag2(tcflush_qs, TCOFLUSH);
931
+ #endif
932
+ #ifdef TCIOFLUSH
933
+ define_flag2(tcflush_qs, TCIOFLUSH);
934
+ #endif
935
+
936
+ /* tcsetattr uses these */
937
+ #ifdef TCSANOW
938
+ define_flag2(tcsetattr_opt, TCSANOW);
939
+ #endif
940
+ #ifdef TCSADRAIN
941
+ define_flag2(tcsetattr_opt, TCSADRAIN);
942
+ #endif
943
+ #ifdef TCSAFLUSH
944
+ define_flag2(tcsetattr_opt, TCSAFLUSH);
945
+ #endif
946
+ #ifdef TCSASOFT
947
+ define_flag2(tcsetattr_opt, TCSASOFT);
948
+ #endif
949
+ }