From: gotoken@... (GOTO Kentaro) Date: 1999-08-09T08:25:56+09:00 Subject: [ruby-list:15969] Re: termios --Multipart_Mon_Aug__9_08:25:24_1999-1 Content-Type: text/plain; charset=ISO-2022-JP ごとけんです In message "[ruby-list:15968] Re: termios" on 99/08/08, WATANABE Hirofumi writes: >termios とはやまだあきらさんの ruby-termios-module のことですか? そうです。 >:それはともかく、termios がmakeできません。rename.rbしないと >:いけないのは別にしても、struct termios が違うようです。 > >普通 termios には c_line はなくて termio にはあるから >4.4BSD系 は POSIX に忠実ってことかな. なるほど。 >というわけで termios ってことなら c_line は外しちゃったほうがいいと >思います. 外してみました。どなたかテストお願いします。 test3.rbがわたなべさんの書かれた stty -echo 相当の もの[ruby-list:15968]です。 -- gotoken ftp://ftp.arika.org/pub/Tools/Ruby/ruby-termios-module-0.0.3.tar.gz からのパッチです。 --Multipart_Mon_Aug__9_08:25:24_1999-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="ruby-termios-module-0.0.3-patch" Content-Transfer-Encoding: 7bit diff -u1rN ruby-termios-module.orig/MANIFEST ruby-termios-module/MANIFEST --- ruby-termios-module.orig/MANIFEST Mon Aug 9 08:12:36 1999 +++ ruby-termios-module/MANIFEST Mon Aug 9 08:02:54 1999 @@ -7 +7,2 @@ test2.rb +test3.rb diff -u1rN ruby-termios-module.orig/termios.c ruby-termios-module/termios.c --- ruby-termios-module.orig/termios.c Fri Feb 19 00:09:16 1999 +++ ruby-termios-module/termios.c Mon Aug 9 07:53:27 1999 @@ -25,9 +25,9 @@ int i; - c_cc = ary_new2(NCCS); + c_cc = rb_ary_new2(NCCS); for (i = 0; i < NCCS; i++) { - ary_push(c_cc, INT2FIX(t->c_cc[i])); + rb_ary_push(c_cc, INT2FIX(t->c_cc[i])); } - return struct_new(sTermios, + return rb_struct_new(sTermios, INT2FIX(t->c_iflag), @@ -36,3 +36,2 @@ INT2FIX(t->c_lflag), - INT2FIX(t->c_line), c_cc, @@ -55,3 +54,3 @@ } else { - TypeError("wrong structure value %s (expected Fixnum or Nil)", + rb_raise(rb_eTypeError, "wrong structure value %s (expected Fixnum or Nil)", name); @@ -72,10 +71,9 @@ t->c_lflag = rb_Termios_to_termios0(RSTRUCT(rt)->ptr[3], "c_lflag"); - t->c_line = rb_Termios_to_termios0(RSTRUCT(rt)->ptr[4], "c_line"); - for (i = 0; i < RARRAY(RSTRUCT(rt)->ptr[5])->len; i++) { + for (i = 0; i < RARRAY(RSTRUCT(rt)->ptr[4])->len; i++) { sprintf(c_cc, "c_cc[%d]", i); - t->c_cc[i] = rb_Termios_to_termios0(RARRAY(RSTRUCT(rt)->ptr[5])->ptr[i], + t->c_cc[i] = rb_Termios_to_termios0(RARRAY(RSTRUCT(rt)->ptr[4])->ptr[i], c_cc); } - cfsetispeed(t, rb_Termios_to_termios0(RSTRUCT(rt)->ptr[6], "c_ispeed")); - cfsetospeed(t, rb_Termios_to_termios0(RSTRUCT(rt)->ptr[7], "c_ospeed")); + cfsetispeed(t, rb_Termios_to_termios0(RSTRUCT(rt)->ptr[5], "c_ispeed")); + cfsetospeed(t, rb_Termios_to_termios0(RSTRUCT(rt)->ptr[6], "c_ospeed")); @@ -105,3 +103,3 @@ if (tcgetattr(fileno(fptr->f), &t) < 0) { - Fail("can't get terminal parameters (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't get terminal parameters (%s)", strerror(errno)); } @@ -132,3 +130,3 @@ if (strcmp(type, "Struct::Termios") != 0) { - TypeError("wrong argument type %s (expected Struct::Termios)", + rb_raise(rb_eTypeError, "wrong argument type %s (expected Struct::Termios)", type); @@ -140,3 +138,3 @@ if (tcsetattr(fileno(fptr->f), FIX2INT(opt), &t) < 0) { - Fail("can't set terminal parameters (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't set terminal parameters (%s)", strerror(errno)); } @@ -157,3 +155,3 @@ if (tcsendbreak(fileno(fptr->f), FIX2INT(duration)) < 0) { - Fail("can't transmits break (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't transmits break (%s)", strerror(errno)); } @@ -173,3 +171,3 @@ if (tcdrain(fileno(fptr->f)) < 0) { - Fail("can't drain (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't drain (%s)", strerror(errno)); } @@ -193,3 +191,3 @@ queue_selector != TCIOFLUSH) { - TypeError("wrong argument value %s (expected Termios::TCIFLUSH, Termios::TCOFLUSH or Termios::TCIOFLUSH)", + rb_raise(rb_eTypeError, "wrong argument value %s (expected Termios::TCIFLUSH, Termios::TCOFLUSH or Termios::TCIOFLUSH)", queue_selector); @@ -199,3 +197,3 @@ if (tcflush(fileno(fptr->f), queue_selector) < 0) { - Fail("can't flush (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't flush (%s)", strerror(errno)); } @@ -220,3 +218,3 @@ action != TCION) { - TypeError("wrong argument value %s (expected Termios::TCOOFF, Termios::TCOON, Termios::TCIOFF or Termios::TCION)", + rb_raise(rb_eTypeError, "wrong argument value %s (expected Termios::TCOOFF, Termios::TCOON, Termios::TCIOFF or Termios::TCION)", action); @@ -226,3 +224,3 @@ if (tcflow(fileno(fptr->f), action) < 0) { - Fail("can't control transmitting data flow (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't control transmitting data flow (%s)", strerror(errno)); } @@ -243,3 +241,3 @@ if (pid = tcgetpgrp(fileno(fptr->f)) < 0) { - Fail("can't get process group id (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't get process group id (%s)", strerror(errno)); } @@ -261,3 +259,3 @@ if (tcsetpgrp(fileno(fptr->f), FIX2INT(pgrpid)) < 0) { - Fail("can't set process group id (%s)", strerror(errno)); + rb_raise(rb_eRuntimeError, "can't set process group id (%s)", strerror(errno)); } @@ -275,12 +273,12 @@ VALUE c_iflag, c_oflag, c_cflag, c_lflag, - c_line, c_cc, c_ispeed, c_ospeed; + c_cc, c_ispeed, c_ospeed; int i; - rb_scan_args(argc, argv, "08", + rb_scan_args(argc, argv, "07", &c_iflag, &c_oflag, &c_cflag, &c_lflag, - &c_line, &c_cc, &c_ispeed, &c_ospeed); + &c_cc, &c_ispeed, &c_ospeed); if (NIL_P(c_cc)) { - c_cc = ary_new2(NCCS); + c_cc = rb_ary_new2(NCCS); for (i = 0; i < NCCS; i++) { - ary_push(c_cc, Qnil); + rb_ary_push(c_cc, Qnil); } @@ -290,5 +288,5 @@ - return struct_new(sTermios, + return rb_struct_new(sTermios, c_iflag, c_oflag, c_cflag, c_lflag, - c_line, c_cc, c_ispeed, c_ospeed); + c_cc, c_ispeed, c_ospeed); } @@ -312,3 +310,3 @@ - sTermios = struct_define("Termios", + sTermios = rb_struct_define("Termios", "c_iflag", /* input modes */ @@ -317,3 +315,2 @@ "c_lflag", /* local modes */ - "c_line", /* line discipline */ "c_cc", /* control chars */ diff -u1rN ruby-termios-module.orig/test1.rb ruby-termios-module/test1.rb --- ruby-termios-module.orig/test1.rb Thu Feb 18 02:24:21 1999 +++ ruby-termios-module/test1.rb Mon Aug 9 07:58:41 1999 @@ -6,3 +6,3 @@ -RESCUE = Termios::new_termios(1280, 5, 3261, 35387, 0, +RESCUE = Termios::new_termios(1280, 5, 3261, 35387, [3, 28, 127, 21, 4, 0, 1, 0, 17, diff -u1rN ruby-termios-module.orig/test3.rb ruby-termios-module/test3.rb --- ruby-termios-module.orig/test3.rb Thu Jan 1 09:00:00 1970 +++ ruby-termios-module/test3.rb Mon Aug 9 08:15:26 1999 @@ -0,0 +1,13 @@ +# shadows input then reports [ruby-list:15968] +require 'termios' +include Termios + +oldt = getattr($stdin) +newt = oldt.dup +newt.c_lflag &= ~ECHO +setattr($stdin, TCSANOW, newt) +print "noecho> " +a = $stdin.gets +setattr($stdin, TCSANOW, oldt) +print "\n" +p a --Multipart_Mon_Aug__9_08:25:24_1999-1--