ruby-termios 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,146 @@
1
+ 2009-08-28 akira yamada <akira@arika.org>
2
+
3
+ * version 0.9.6.
4
+
5
+ 2009-02-05 akira yamada <akira@arika.org>
6
+
7
+ * termios.c: added RDoc.
8
+
9
+ * README: converted to RDoc.
10
+
11
+ * ruby-termios.gemspec: added.
12
+
13
+ 2008-10-23 akira yamada <akira@arika.org>
14
+
15
+ * termios.c: added IOCTL_COMMANDS, IOCTL_COMMAND_NAMES,
16
+ MODEM_SIGNALS, MODEM_SIGNAL_NAMES, PTY_PACKET_OPTIONS,
17
+ PTY_PACKET_OPTION_NAMES, LINE_DISCIPLINES and
18
+ LINE_DISCIPLINE_NAMES.
19
+
20
+ This change is contributed from Chris Hoffman
21
+ <chrishoffman_cardialife.com>.
22
+
23
+ * termios.c, extconf.rb: included <sys/ioctl.h>.
24
+
25
+ 2008-06-03 akira yamada <akira@arika.org>
26
+
27
+ * extconf.rb, termios.c: adjusted rb_io_t/OpenFile checks for Ruby
28
+ 1.8.7.
29
+
30
+ 2007-05-30 akira yamada <akira@arika.org>
31
+
32
+ * extconf.rb: rb_io_t test isn't needed for Ruby 1.6.
33
+
34
+ * version 0.9.5.
35
+
36
+ 2007-05-29 Tanaka Akira <akr@fsij.org>
37
+
38
+ * extconf.rb: check rb_io_t.
39
+ check fd member in OpenFile.
40
+
41
+ * termios.c: support Ruby 1.9.
42
+ use unsigned long for flags bigger than Fixnum such as CRTSCTS.
43
+ use rb_sys_fail instead of rb_raise(rb_eRuntimeError).
44
+ (Termios_to_termios): use rb_ary_entry to access cc_ary to avoid SEGV.
45
+ (termios_tcgetpgrp): use pid_t.
46
+ (termios_tcsetpgrp): ditto.
47
+ (Termios::Termios#dup): defined to duplicate cc.
48
+ (Termios::Termios#clone): ditto.
49
+ (Termios::POSIX_VDISABLE): defined.
50
+ (Termios::CCINDEX_NAMES): defined.
51
+ (Termios::IFLAG_NAMES): defined.
52
+ (Termios::OFLAG_NAMES): defined.
53
+ (Termios::OFLAG_CHOICES): defined.
54
+ (Termios::CFLAG_NAMES): defined.
55
+ (Termios::CFLAG_CHOICES): defined.
56
+ (Termios::LFLAG_NAMES): defined.
57
+ (Termios::BAUD_NAMES): defined.
58
+ (Termios::IUTF8): defined.
59
+ (Termios::VDSUSP): defined for 4.4BSD.
60
+ (Termios::VSTATUS): defined for 4.4BSD.
61
+ (Termios::MDMBUF): defined for 4.4BSD.
62
+
63
+ * lib/termios.rb: new file. inspect and pretty_print defined.
64
+
65
+ 2005-05-30 akira yamada <akira@arika.org>
66
+
67
+ * termios.c: applied a patch which makes ruby-termios work under
68
+ both ruby1.8 and ruby1.9. [ruby-talk:143781]
69
+ Thanks to: Akr.
70
+
71
+ 2002-10-13 akira yamada <akira@arika.org>
72
+
73
+ * termios.c
74
+ (termios_set_ispeed): fixed typo.
75
+ (termios_initialize): 0-cleared "@cc".
76
+ (Termios_to_termios): unknown cc-values are treated as 0.
77
+
78
+ * examples/modem_check.rb: renamed examples/modem_check1.rb.
79
+
80
+ * examples/modem_check0.rb, exampes/modem_check2.rb: new.
81
+
82
+ * version 0.9.4.
83
+
84
+ 2002-10-12 akira yamada <akira@arika.org>
85
+
86
+ * termios.c: revoked Termios::Termios#set_cc and removed some methods
87
+ such as Termios::Termios#iflag etc. they became attr_reader.
88
+
89
+ * version 0.9.3.
90
+
91
+ 2002-10-12 akira yamada <akira@arika.org>
92
+
93
+ * termios.c
94
+ (termios_cc): accepts index of c_cc.
95
+ (termios_set_a_cc): new function for Termios::Termios#set_cc.
96
+ (Init_termios): added new constants Termios::CCINDEX, Termios::IFLAGS,
97
+ Termios::OFLAGS, Termios::CFLAGS, Termios::LFLAGS and Termios::BAUD.
98
+
99
+ * examples/modem_check.rb: it did not work. rewrited.
100
+
101
+ * test/test0.rb: rewrited.
102
+
103
+ * version 0.9.2.
104
+
105
+ 2002-10-10 akira yamada <akira@arika.org>
106
+
107
+ * termios.c
108
+ (Init_termios): revived Termios::Termios#c_foo/c_foo= for backward
109
+ compatibility.
110
+
111
+ 2002-09-25 akira yamada <akira@arika.org>
112
+
113
+ * termios.c
114
+ (termios_clone): new method "clone" for Termios::Termios.
115
+ (Init_termios): revived Termios.new_termios for backward
116
+ compatibility.
117
+
118
+ * version 0.9.1.
119
+
120
+ 2002-09-25 akira yamada <akira@arika.org>
121
+
122
+ * Termios module can be included to IO classes and can extend IO
123
+ objects.
124
+
125
+ * now Termios::Termios is rb_cObject class.
126
+
127
+ * version 0.9.0.
128
+
129
+ Wed Nov 15 19:03:06 2000 akira yamada <akira@arika.org>
130
+
131
+ * renamed to ruby-termios.
132
+
133
+ Wed Dec 1 21:27:23 1999 GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp>
134
+
135
+ * termios.c: removed c_line.
136
+ * test1.rb: removed c_line.
137
+ * test3.rb: stty -echo.
138
+
139
+ Fri Feb 19 00:05:20 1999 akira yamada <akira@linux.or.jp>
140
+
141
+ * termios.c (Init_termios): now sTermios is hidden.
142
+ * test2.rb: rewrited.
143
+
144
+ Fri Thu 18 02:24:21 1999 akira yamada <akira@linux.or.jp>
145
+
146
+ * 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