arika-ruby-termios 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +142 -0
- data/README +80 -0
- data/examples/modem_check0.rb +69 -0
- data/examples/modem_check1.rb +68 -0
- data/examples/modem_check2.rb +69 -0
- data/examples/secret_input1.rb +12 -0
- data/examples/secret_input2.rb +14 -0
- data/extconf.rb +20 -0
- data/lib/termios.rb +151 -0
- data/termios.c +1537 -0
- data/test/test0.rb +29 -0
- metadata +75 -0
data/ChangeLog
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
2009-02-05 akira yamada <akira@arika.org>
|
2
|
+
|
3
|
+
* termios.c: added RDoc.
|
4
|
+
|
5
|
+
* README: converted to RDoc.
|
6
|
+
|
7
|
+
* ruby-termios.gemspec: added.
|
8
|
+
|
9
|
+
2008-10-23 akira yamada <akira@arika.org>
|
10
|
+
|
11
|
+
* termios.c: added IOCTL_COMMANDS, IOCTL_COMMAND_NAMES,
|
12
|
+
MODEM_SIGNALS, MODEM_SIGNAL_NAMES, PTY_PACKET_OPTIONS,
|
13
|
+
PTY_PACKET_OPTION_NAMES, LINE_DISCIPLINES and
|
14
|
+
LINE_DISCIPLINE_NAMES.
|
15
|
+
|
16
|
+
This change is contributed from Chris Hoffman
|
17
|
+
<chrishoffman_cardialife.com>.
|
18
|
+
|
19
|
+
* termios.c, extconf.rb: included <sys/ioctl.h>.
|
20
|
+
|
21
|
+
2008-06-03 akira yamada <akira@arika.org>
|
22
|
+
|
23
|
+
* extconf.rb, termios.c: adjusted rb_io_t/OpenFile checks for Ruby
|
24
|
+
1.8.7.
|
25
|
+
|
26
|
+
2007-05-30 akira yamada <akira@arika.org>
|
27
|
+
|
28
|
+
* extconf.rb: rb_io_t test isn't needed for Ruby 1.6.
|
29
|
+
|
30
|
+
* version 0.9.5.
|
31
|
+
|
32
|
+
2007-05-29 Tanaka Akira <akr@fsij.org>
|
33
|
+
|
34
|
+
* extconf.rb: check rb_io_t.
|
35
|
+
check fd member in OpenFile.
|
36
|
+
|
37
|
+
* termios.c: support Ruby 1.9.
|
38
|
+
use unsigned long for flags bigger than Fixnum such as CRTSCTS.
|
39
|
+
use rb_sys_fail instead of rb_raise(rb_eRuntimeError).
|
40
|
+
(Termios_to_termios): use rb_ary_entry to access cc_ary to avoid SEGV.
|
41
|
+
(termios_tcgetpgrp): use pid_t.
|
42
|
+
(termios_tcsetpgrp): ditto.
|
43
|
+
(Termios::Termios#dup): defined to duplicate cc.
|
44
|
+
(Termios::Termios#clone): ditto.
|
45
|
+
(Termios::POSIX_VDISABLE): defined.
|
46
|
+
(Termios::CCINDEX_NAMES): defined.
|
47
|
+
(Termios::IFLAG_NAMES): defined.
|
48
|
+
(Termios::OFLAG_NAMES): defined.
|
49
|
+
(Termios::OFLAG_CHOICES): defined.
|
50
|
+
(Termios::CFLAG_NAMES): defined.
|
51
|
+
(Termios::CFLAG_CHOICES): defined.
|
52
|
+
(Termios::LFLAG_NAMES): defined.
|
53
|
+
(Termios::BAUD_NAMES): defined.
|
54
|
+
(Termios::IUTF8): defined.
|
55
|
+
(Termios::VDSUSP): defined for 4.4BSD.
|
56
|
+
(Termios::VSTATUS): defined for 4.4BSD.
|
57
|
+
(Termios::MDMBUF): defined for 4.4BSD.
|
58
|
+
|
59
|
+
* lib/termios.rb: new file. inspect and pretty_print defined.
|
60
|
+
|
61
|
+
2005-05-30 akira yamada <akira@arika.org>
|
62
|
+
|
63
|
+
* termios.c: applied a patch which makes ruby-termios work under
|
64
|
+
both ruby1.8 and ruby1.9. [ruby-talk:143781]
|
65
|
+
Thanks to: Akr.
|
66
|
+
|
67
|
+
2002-10-13 akira yamada <akira@arika.org>
|
68
|
+
|
69
|
+
* termios.c
|
70
|
+
(termios_set_ispeed): fixed typo.
|
71
|
+
(termios_initialize): 0-cleared "@cc".
|
72
|
+
(Termios_to_termios): unknown cc-values are treated as 0.
|
73
|
+
|
74
|
+
* examples/modem_check.rb: renamed examples/modem_check1.rb.
|
75
|
+
|
76
|
+
* examples/modem_check0.rb, exampes/modem_check2.rb: new.
|
77
|
+
|
78
|
+
* version 0.9.4.
|
79
|
+
|
80
|
+
2002-10-12 akira yamada <akira@arika.org>
|
81
|
+
|
82
|
+
* termios.c: revoked Termios::Termios#set_cc and removed some methods
|
83
|
+
such as Termios::Termios#iflag etc. they became attr_reader.
|
84
|
+
|
85
|
+
* version 0.9.3.
|
86
|
+
|
87
|
+
2002-10-12 akira yamada <akira@arika.org>
|
88
|
+
|
89
|
+
* termios.c
|
90
|
+
(termios_cc): accepts index of c_cc.
|
91
|
+
(termios_set_a_cc): new function for Termios::Termios#set_cc.
|
92
|
+
(Init_termios): added new constants Termios::CCINDEX, Termios::IFLAGS,
|
93
|
+
Termios::OFLAGS, Termios::CFLAGS, Termios::LFLAGS and Termios::BAUD.
|
94
|
+
|
95
|
+
* examples/modem_check.rb: it did not work. rewrited.
|
96
|
+
|
97
|
+
* test/test0.rb: rewrited.
|
98
|
+
|
99
|
+
* version 0.9.2.
|
100
|
+
|
101
|
+
2002-10-10 akira yamada <akira@arika.org>
|
102
|
+
|
103
|
+
* termios.c
|
104
|
+
(Init_termios): revived Termios::Termios#c_foo/c_foo= for backward
|
105
|
+
compatibility.
|
106
|
+
|
107
|
+
2002-09-25 akira yamada <akira@arika.org>
|
108
|
+
|
109
|
+
* termios.c
|
110
|
+
(termios_clone): new method "clone" for Termios::Termios.
|
111
|
+
(Init_termios): revived Termios.new_termios for backward
|
112
|
+
compatibility.
|
113
|
+
|
114
|
+
* version 0.9.1.
|
115
|
+
|
116
|
+
2002-09-25 akira yamada <akira@arika.org>
|
117
|
+
|
118
|
+
* Termios module can be included to IO classes and can extend IO
|
119
|
+
objects.
|
120
|
+
|
121
|
+
* now Termios::Termios is rb_cObject class.
|
122
|
+
|
123
|
+
* version 0.9.0.
|
124
|
+
|
125
|
+
Wed Nov 15 19:03:06 2000 akira yamada <akira@arika.org>
|
126
|
+
|
127
|
+
* renamed to ruby-termios.
|
128
|
+
|
129
|
+
Wed Dec 1 21:27:23 1999 GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp>
|
130
|
+
|
131
|
+
* termios.c: removed c_line.
|
132
|
+
* test1.rb: removed c_line.
|
133
|
+
* test3.rb: stty -echo.
|
134
|
+
|
135
|
+
Fri Feb 19 00:05:20 1999 akira yamada <akira@linux.or.jp>
|
136
|
+
|
137
|
+
* termios.c (Init_termios): now sTermios is hidden.
|
138
|
+
* test2.rb: rewrited.
|
139
|
+
|
140
|
+
Fri Thu 18 02:24:21 1999 akira yamada <akira@linux.or.jp>
|
141
|
+
|
142
|
+
* development started.
|
data/README
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= termios (ruby-termios) - a simple wrapper of termios(3)
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This extension library provides Termios module. It enables you to use
|
6
|
+
termios(3) interface.
|
7
|
+
|
8
|
+
Termios module is simple wrapper of termios(3). It can be included into
|
9
|
+
IO-family classes and can extend IO-family objects. In addition, the
|
10
|
+
methods can use as module function.
|
11
|
+
|
12
|
+
== Requires
|
13
|
+
|
14
|
+
This extension library can use with Ruby 1.6, 1.8 or 1.9. (Ruby-termios can
|
15
|
+
build with Ruby 1.6 but it has not yet been tested enough.)
|
16
|
+
|
17
|
+
== Installation
|
18
|
+
|
19
|
+
ruby extconf.rb
|
20
|
+
make
|
21
|
+
make install
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Ruby-termios for Ruby is copyrighted free software by akira yamada
|
26
|
+
<akira@arika.org>. You can redistribute it and/or modify it under either
|
27
|
+
the terms of the GPL, or the conditions below:
|
28
|
+
|
29
|
+
1. You may make and give away verbatim copies of the source form of the
|
30
|
+
software without restriction, provided that you duplicate all of the
|
31
|
+
original copyright notices and associated disclaimers.
|
32
|
+
|
33
|
+
2. You may modify your copy of the software in any way, provided that
|
34
|
+
you do at least ONE of the following:
|
35
|
+
|
36
|
+
a) place your modifications in the Public Domain or otherwise
|
37
|
+
make them Freely Available, such as by posting said
|
38
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
39
|
+
the author to include your modifications in the software.
|
40
|
+
|
41
|
+
b) use the modified software only within your corporation or
|
42
|
+
organization.
|
43
|
+
|
44
|
+
c) rename any non-standard executables so the names do not conflict
|
45
|
+
with standard executables, which must also be provided.
|
46
|
+
|
47
|
+
d) make other distribution arrangements with the author.
|
48
|
+
|
49
|
+
3. You may distribute the software in object code or executable
|
50
|
+
form, provided that you do at least ONE of the following:
|
51
|
+
|
52
|
+
a) distribute the executables and library files of the software,
|
53
|
+
together with instructions (in the manual page or equivalent)
|
54
|
+
on where to get the original distribution.
|
55
|
+
|
56
|
+
b) accompany the distribution with the machine-readable source of
|
57
|
+
the software.
|
58
|
+
|
59
|
+
c) give non-standard executables non-standard names, with
|
60
|
+
instructions on where to get the original software distribution.
|
61
|
+
|
62
|
+
d) make other distribution arrangements with the author.
|
63
|
+
|
64
|
+
4. You may modify and include the part of the software into any other
|
65
|
+
software (possibly commercial). But some files in the distribution
|
66
|
+
are not written by the author, so that they are not under this terms.
|
67
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], fnmatch.[ch],
|
68
|
+
glob.c, st.[ch] and some files under the ./missing directory. See
|
69
|
+
each file for the copying condition.
|
70
|
+
|
71
|
+
5. The scripts and library files supplied as input to or produced as
|
72
|
+
output from the software do not automatically fall under the
|
73
|
+
copyright of the software, but belong to whomever generated them,
|
74
|
+
and may be sold commercially, and may be aggregated with this
|
75
|
+
software.
|
76
|
+
|
77
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
78
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
79
|
+
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
80
|
+
PURPOSE.
|
@@ -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
|
data/extconf.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
if have_header('termios.h') &&
|
4
|
+
have_header('unistd.h')
|
5
|
+
have_header('sys/ioctl.h')
|
6
|
+
|
7
|
+
if RUBY_VERSION >= '1.7'
|
8
|
+
have_header('ruby/io.h')
|
9
|
+
if have_type("rb_io_t", ["ruby.h", "rubyio.h"])
|
10
|
+
have_struct_member("rb_io_t", "fd", ["ruby.h", "rubyio.h"])
|
11
|
+
else
|
12
|
+
have_struct_member("OpenFile", "fd", ["ruby.h", "rubyio.h"])
|
13
|
+
end
|
14
|
+
if have_macro("OpenFile", ["ruby.h", "rubyio.h"])
|
15
|
+
$defs.push("-DHAVE_MACRO_OPENFILE")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
create_makefile('termios')
|
20
|
+
end
|
data/lib/termios.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'termios.so'
|
2
|
+
|
3
|
+
module Termios
|
4
|
+
VISIBLE_CHAR = {}
|
5
|
+
[
|
6
|
+
"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G",
|
7
|
+
"^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O",
|
8
|
+
"^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
|
9
|
+
"^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_",
|
10
|
+
"<sp>", "!", "\"", "#", "$", "%", "&", "'",
|
11
|
+
"(", ")", "*", "+", ",", "-", ".", "/",
|
12
|
+
"0", "1", "2", "3", "4", "5", "6", "7",
|
13
|
+
"8", "9", ":", ";", "<", "=", ">", "?",
|
14
|
+
"@", "A", "B", "C", "D", "E", "F", "G",
|
15
|
+
"H", "I", "J", "K", "L", "M", "N", "O",
|
16
|
+
"P", "Q", "R", "S", "T", "U", "V", "W",
|
17
|
+
"X", "Y", "Z", "[", "\\", "]", "^", "_",
|
18
|
+
"`", "a", "b", "c", "d", "e", "f", "g",
|
19
|
+
"h", "i", "j", "k", "l", "m", "n", "o",
|
20
|
+
"p", "q", "r", "s", "t", "u", "v", "w",
|
21
|
+
"x", "y", "z", "{", "|", "}", "~", "^?",
|
22
|
+
"M-^@", "M-^A", "M-^B", "M-^C", "M-^D", "M-^E", "M-^F", "M-^G",
|
23
|
+
"M-^H", "M-^I", "M-^J", "M-^K", "M-^L", "M-^M", "M-^N", "M-^O",
|
24
|
+
"M-^P", "M-^Q", "M-^R", "M-^S", "M-^T", "M-^U", "M-^V", "M-^W",
|
25
|
+
"M-^X", "M-^Y", "M-^Z", "M-^[", "M-^\\", "M-^]", "M-^^", "M-^_",
|
26
|
+
"M-<sp>", "M-!", "M-\"", "M-#", "M-$", "M-%", "M-&", "M-'",
|
27
|
+
"M-(", "M-)", "M-*", "M-+", "M-,", "M--", "M-.", "M-/",
|
28
|
+
"M-0", "M-1", "M-2", "M-3", "M-4", "M-5", "M-6", "M-7",
|
29
|
+
"M-8", "M-9", "M-:", "M-;", "M-<", "M-=", "M->", "M-?",
|
30
|
+
"M-@", "M-A", "M-B", "M-C", "M-D", "M-E", "M-F", "M-G",
|
31
|
+
"M-H", "M-I", "M-J", "M-K", "M-L", "M-M", "M-N", "M-O",
|
32
|
+
"M-P", "M-Q", "M-R", "M-S", "M-T", "M-U", "M-V", "M-W",
|
33
|
+
"M-X", "M-Y", "M-Z", "M-[", "M-\\", "M-]", "M-^", "M-_",
|
34
|
+
"M-`", "M-a", "M-b", "M-c", "M-d", "M-e", "M-f", "M-g",
|
35
|
+
"M-h", "M-i", "M-j", "M-k", "M-l", "M-m", "M-n", "M-o",
|
36
|
+
"M-p", "M-q", "M-r", "M-s", "M-t", "M-u", "M-v", "M-w",
|
37
|
+
"M-x", "M-y", "M-z", "M-{", "M-|", "M-}", "M-~", "M-^?",
|
38
|
+
].each_with_index {|s, i|
|
39
|
+
VISIBLE_CHAR[i] = s
|
40
|
+
VISIBLE_CHAR[[i].pack("C")] = s
|
41
|
+
}
|
42
|
+
VISIBLE_CHAR[POSIX_VDISABLE] = "<undef>"
|
43
|
+
VISIBLE_CHAR[[POSIX_VDISABLE].pack("C")] = "<undef>"
|
44
|
+
|
45
|
+
class Termios
|
46
|
+
def inspect
|
47
|
+
str = "\#<#{self.class}"
|
48
|
+
if self.ispeed == self.ospeed
|
49
|
+
speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
|
50
|
+
str << " speed #{speed} baud;"
|
51
|
+
else
|
52
|
+
ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
|
53
|
+
ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
|
54
|
+
str << " ispeed #{ispeed} baud; ospeed #{ospeed} baud;"
|
55
|
+
end
|
56
|
+
|
57
|
+
CCINDEX_NAMES.each {|ccindex|
|
58
|
+
next if ccindex == :VMIN || ccindex == :VTIME
|
59
|
+
str << " #{ccindex.to_s[1..-1].downcase}"
|
60
|
+
str << "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
|
61
|
+
}
|
62
|
+
str << " min=#{self.cc[VMIN]}"
|
63
|
+
str << " time=#{self.cc[VTIME]}"
|
64
|
+
|
65
|
+
[
|
66
|
+
[:cflag,
|
67
|
+
CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
|
68
|
+
CFLAG_CHOICES],
|
69
|
+
[:iflag, IFLAG_NAMES, nil],
|
70
|
+
[:oflag, OFLAG_NAMES, OFLAG_CHOICES],
|
71
|
+
[:lflag, LFLAG_NAMES, nil]
|
72
|
+
].each {|l|
|
73
|
+
str << ";"
|
74
|
+
flag_type, flag_names, choices = l
|
75
|
+
flags = self.send(flag_type)
|
76
|
+
choice_names = choices ? choices.values.flatten : []
|
77
|
+
(flag_names-choice_names).each {|name|
|
78
|
+
str << " "
|
79
|
+
if choices and ns = choices[name]
|
80
|
+
mask = ::Termios.const_get(name)
|
81
|
+
ns.each {|n|
|
82
|
+
if (flags & mask) == ::Termios.const_get(n)
|
83
|
+
str << n.to_s.downcase
|
84
|
+
break
|
85
|
+
end
|
86
|
+
}
|
87
|
+
else
|
88
|
+
str << "-" if (flags & ::Termios.const_get(name)) == 0
|
89
|
+
str << name.to_s.downcase
|
90
|
+
end
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
str << ">"
|
95
|
+
str
|
96
|
+
end
|
97
|
+
|
98
|
+
def pretty_print(q) # :nodoc:
|
99
|
+
q.object_group(self) {
|
100
|
+
if self.ispeed == self.ospeed
|
101
|
+
speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
|
102
|
+
q.fill_breakable; q.text "speed #{speed} baud;"
|
103
|
+
else
|
104
|
+
ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
|
105
|
+
ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
|
106
|
+
q.fill_breakable; q.text "ispeed #{ispeed} baud;"
|
107
|
+
q.fill_breakable; q.text "ospeed #{ospeed} baud;"
|
108
|
+
end
|
109
|
+
q.breakable
|
110
|
+
|
111
|
+
q.seplist(CCINDEX_NAMES-[:VMIN, :VTIME],
|
112
|
+
lambda { q.fill_breakable }) {|ccindex|
|
113
|
+
q.text ccindex.to_s[1..-1].downcase
|
114
|
+
q.text "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
|
115
|
+
}
|
116
|
+
q.breakable; q.text "min=#{self.cc[VMIN]}"
|
117
|
+
q.fill_breakable; q.text "time=#{self.cc[VTIME]}"
|
118
|
+
|
119
|
+
[
|
120
|
+
[:cflag,
|
121
|
+
CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
|
122
|
+
CFLAG_CHOICES],
|
123
|
+
[:iflag, IFLAG_NAMES, nil],
|
124
|
+
[:oflag, OFLAG_NAMES, OFLAG_CHOICES],
|
125
|
+
[:lflag, LFLAG_NAMES, nil]
|
126
|
+
].each {|l|
|
127
|
+
q.text ";"
|
128
|
+
q.breakable
|
129
|
+
flag_type, flag_names, choices = l
|
130
|
+
flags = self.send(flag_type)
|
131
|
+
choice_names = choices ? choices.values.flatten : []
|
132
|
+
q.seplist(flag_names-choice_names,
|
133
|
+
lambda { q.fill_breakable }) {|name|
|
134
|
+
if choices and ns = choices[name]
|
135
|
+
mask = ::Termios.const_get(name)
|
136
|
+
ns.each {|n|
|
137
|
+
if (flags & mask) == ::Termios.const_get(n)
|
138
|
+
q.text n.to_s.downcase
|
139
|
+
break
|
140
|
+
end
|
141
|
+
}
|
142
|
+
else
|
143
|
+
q.text "-" if (flags & ::Termios.const_get(name)) == 0
|
144
|
+
q.text name.to_s.downcase
|
145
|
+
end
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|