[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freewnn:00997] Re: NOT MEMBER article from kabe@sra-tohoku.co.jp (freewnn ML) (1/2)



From: Hiroo Ono <hiroo@oikumene.gcd.org>
To: freewnn@tomo.gr.jp
Subject: Re: NOT MEMBER article from kabe@sra-tohoku.co.jp (freewnn ML)
In-Reply-To: <200307170535.FMLAAA3318.freewnn@tomo.gr.jp>
References: <1299017200304.400741@sra-tohoku.co.jp.msgid>
	<200307170535.FMLAAA3318.freewnn@tomo.gr.jp>
User-Agent: Wanderlust/2.10.0 (Venus) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.4 Emacs/21.3 (i386--freebsd) MULE/5.0 (SAKAKI)
MIME-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen")
Content-Type: text/plain; charset=ISO-2022-JP

小野寛生です

青野さんに指摘された かべ@SRA さんの patch ですが、届いていました。
spam に埋もれて見落としていました。すみません。

---- 以下、元のメール

From: <kabe@sra-tohoku.co.jp>
To: <freewnn@tomo.gr.jp>
Message-ID: <1299017200304.400741@sra-tohoku.co.jp.msgid>
Organization: carbon, oxygen, hydrogen
Newsgroups: fj.comp.input-method
Subject: Mass patch for FreeWnn-1.10-pl020 to enable uum on NetBSD/Solaris (2)
References: <1271804200314.410738@sra-tohoku.co.jp.msgid>
X-Mailer: mnews [version 1.22PL5] 2002-11-27(Wed)
Date: Thu, 17 Jul 2003 04:55:00 JST

かべ。

To: <freewnn@tomo.gr.jp>
Newsgroups: fj.comp.input-method

※まだ修正したいところはたくさんありますが、現状放出。

NetBSD-1.6.1 (x86)/Solaris 2.6 で、FreeWnnのuumを動かそうとしてみましたが
そのままでは pty の取得まわりがうまくいかないので、

以前 ftp.tohoku.ac.jp に置いてもらっていた
Solaris/HPUX用パッチをベースに
ごりごりと Wnn/uum/jhlp.c を書き換えてみました。

一応、ちゃんと立ち上がってジョブコントールも効きます。
設定ファイルを少し細工すればWnn6のjserverにつなげて変換もできます。

動作確認:Solaris 2.6/SPARC Ultra1, NetBSD 1.6.1/x86

たぶんこの記事はJISになっているので、
パッチを当てる際はEUCに戻してください。


pty回りは昔からの建て増しをすると究極に汚くなるので、
思いきって
・sgi
・/dev/ptmx (ptm(7D))
・openpty(3)
・伝統的 /dev/ttyXXスキャン

の4通りに整理してあります。
TODO: configureでちゃんとどれを使うか検出する。
(NetBSD-1.6では伝統式とopenpty()両方動くようだ)

==
懸案というか疑問:

ptyで何かを動かすにあたっては、普通は
・ptyのmaster と slaveを取得
・fork()
・子供側で slave をつなぎ替える
・親は masterに入出力

なんですが、main() ではなぜか linuxだけは
fork()した「後」にslaveを開いて(open_ttyp())います。

fork後に開かないと動かなかった理由でもあるんですかね?

かなり昔からこのまんまになっているようですが、
可能ならfork前slave取得に統一した方がいいような…

(openpty(3) なんかはfork前slave取得しかできないので、
 fork前に統一すると open_pty() と open_ttyp() が合体できてすっきりする)

-- 
kabe

Index: FreeWnn/ChangeLog
diff -c FreeWnn/ChangeLog:1.1.1.1 FreeWnn/ChangeLog:1.7
*** FreeWnn/ChangeLog:1.1.1.1	Sun Apr  6 16:45:18 2003
--- FreeWnn/ChangeLog	Thu Jul 17 04:50:08 2003
***************
*** 1,3 ****
--- 1,52 ----
+ 	TODO:
+ 	uum: Solarisでは -ltermcap ではなく -lcurses をつかうべし。
+ 	しかし -ltermcap は makerule.mk で固定されている…
+ 	(要configure書き直し)
+ 	    旧Wnn4.2では、Wnn4.2.tmplにてTermcapLibraryを
+ 	    -lcurses, -ltermlib, -ltermcap のいずれかに定義し、
+ 	    WNNTERM_LIB = TermcapLibrary
+ 
+ 	uum,jd/: cvt_key_tbl はキー名が termcap エントリで書かれているが、
+ 	(Solarisな?)terminfoではキー名定義が違うので ktermだと
+ 	大量に
+ convert_key: Warning! Illegal entry name "FA" was ignored.
+ convert-table filename = /usr/local/FreeWnn/lib/wnn/cvt_key_tbl.kt
+ 	が出る。Solaris付属Wnn6のを参考に書き換えるべし?
+ 	(conv/cvt_read.c: cvttbl_entry[] をTERMCAP用の定義にすることで
+ 	 逃げることもできるが…)
+ 
+ Tue Jul 15 02:10:53 JST 2003	Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	* Wnn/uum/jhlp.c: select() の第二引数を、手動ビット操作ではなく
+ 	  FD_ZERO()系のマクロに変更。
+ 	
+ 	TODO: select()の第一引数はクラシカルに 20 固定になっている。
+ 	もういいかげん FD_SETSIZE に変えてもよかろうという気はする。
+ 
+ Tue Jul 15 01:10:06 JST 2003	Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	* Wnn/uum/jhlp.c: Solaris用修正。
+ 	  err() は 使われていないので、<err.h> は外す。
+ 	  /dev/ptmx 環境では pty masterのパス名は「存在しない」ので、
+ 	  char tty_master[] の定義は sgi と USE_PTMX では行わない。
+ 	  (万が一参照した場合はコンパイルエラーになるようにしとく)
+ 
+ 	一応Solarisで動いている。
+ 
+ 	TODO: wait3() の第一引数の union wait は古い、らしい。
+ 	最近のOSではみんな int になっているが、今までのソースは
+ 	linuxだけintで、残りはcastしてwarningを押さえ込んでいる?
+ 
+ 	* Wnn/uum/Makefile.in: LOCAL_LIBRARIES が
+ 	  リンク用と依存関係の両方に使われていて、-lnsl を作ろうとするのを
+ 	  修正。依存ライブラリ用にDEPLIBS を新設。
+ 	  configureで --with-wnn-libraries時に @DEPWNNJLIB@ は定義されるが
+ 	  TODO: @DEPWNNCONVLIB@ がないので、やや中途半端な修正になっている
+ 	  (コメント参照)。
+ 
+ Fri, 11 Jul 2003 21:30:17 Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	uumまわり jumbo patch.
+ 	Solaris/HPUX 用パッチ (kouji@hiroshima-u.ac.jp + kabe)
+ 	から、さらに NetBSD でもuum が動くようにする。
+ 
  Sun, 6 Apr 2003 06:30:49  Hiroo Ono <hiroo oikumene.gcd.org>
  	* Wnn/uum/jhlp.c: err() を uum_err() に変更し、libc の err() と重なら
  	  ないようにする。
Index: FreeWnn/ChangeLog.en
diff -c FreeWnn/ChangeLog.en:1.1.1.1 FreeWnn/ChangeLog.en:1.3
*** FreeWnn/ChangeLog.en:1.1.1.1	Sun Apr  6 16:45:18 2003
--- FreeWnn/ChangeLog.en	Tue Jul 15 03:26:13 2003
***************
*** 1,3 ****
--- 1,24 ----
+ Tue Jul 15 02:10:53 JST 2003	Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	* Wnn/uum/jhlp.c: Change preparing the 2nd arg of select() 
+ 	  to use FD_ZERO() family.
+ 	
+ Tue Jul 15 01:10:06 JST 2003	Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	* Wnn/uum/jhlp.c: Fixes for Solaris.
+ 	  Remove including <err.h> as err() isn't used.
+ 	  pty master pathname doesn't exist, so
+ 	  don't declare char tty_master[] on sgi and USE_PTMX.
+ 	* Wnn/uum/Makefile.in: Previously, LOCAL_LIBRARIES had been used for 
+ 	  both dependent libs and link library, which had been trying to build
+ 	  "-lnsl" (nonsense).
+ 	  New make macro DEPLIBS to hold library dependency only.
+ 
+ 	  Now it is working on Solaris.
+ 
+ Fri, 11 Jul 2003 21:30:17 Taketo Kabe <kabe sra-tohoku.co.jp>
+ 	Jumbo patch for uum.
+ 	Applied Solaris/HPUX patch (kouji@hiroshima-u.ac.jp + kabe)
+ 	and furthur fix to make uum work on NetBSD.
+ 
  Sun, 6 Apr 2003 06:30:49  Hiroo Ono <hiroo oikumene.gcd.org>
  	* Wnn/uum/jhlp.c: Change err() to uum_err().
  	  Avoid overriding err() in libc.
Index: FreeWnn/Wnn/conv/cvt_head.h
diff -c FreeWnn/Wnn/conv/cvt_head.h:1.1.1.1 FreeWnn/Wnn/conv/cvt_head.h:1.2
*** FreeWnn/Wnn/conv/cvt_head.h:1.1.1.1	Thu Mar 21 12:32:45 2002
--- FreeWnn/Wnn/conv/cvt_head.h	Fri Jul 11 21:05:10 2003
***************
*** 40,46 ****
  
  #include "commonhd.h"
  
! #if defined(luna) || defined(DGUX)
  #ifndef SUPPORT_TWODIGIT_FUNCTIONS
  #define SUPPORT_TWODIGIT_FUNCTIONS
  #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
--- 40,46 ----
  
  #include "commonhd.h"
  
! #if defined(luna) || defined(DGUX) || defined(hpux) || defined(sun)
  #ifndef SUPPORT_TWODIGIT_FUNCTIONS
  #define SUPPORT_TWODIGIT_FUNCTIONS
  #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
Index: FreeWnn/Wnn/conv/cvt_read.c
diff -c FreeWnn/Wnn/conv/cvt_read.c:1.1.1.1 FreeWnn/Wnn/conv/cvt_read.c:1.2
*** FreeWnn/Wnn/conv/cvt_read.c:1.1.1.1	Wed Apr  3 13:16:19 2002
--- FreeWnn/Wnn/conv/cvt_read.c	Fri Jul 11 21:05:11 2003
***************
*** 455,460 ****
--- 455,494 ----
    keydef_key[i++] = stradd (&tdataptr, key_f29);
    keydef_key[i++] = stradd (&tdataptr, key_f30);
    keydef_key[i++] = stradd (&tdataptr, key_f31);
+ #ifndef uniosu
+   keydef_key[i++] = stradd (&tdataptr, key_f32);
+   keydef_key[i++] = stradd (&tdataptr, key_f33);
+   keydef_key[i++] = stradd (&tdataptr, key_f34);
+   keydef_key[i++] = stradd (&tdataptr, key_f35);
+   keydef_key[i++] = stradd (&tdataptr, key_f36);
+   keydef_key[i++] = stradd (&tdataptr, key_f37);
+   keydef_key[i++] = stradd (&tdataptr, key_f38);
+   keydef_key[i++] = stradd (&tdataptr, key_f39);
+   keydef_key[i++] = stradd (&tdataptr, key_f40);
+   keydef_key[i++] = stradd (&tdataptr, key_f41);
+   keydef_key[i++] = stradd (&tdataptr, key_f42);
+   keydef_key[i++] = stradd (&tdataptr, key_f43);
+   keydef_key[i++] = stradd (&tdataptr, key_f44);
+   keydef_key[i++] = stradd (&tdataptr, key_f45);
+   keydef_key[i++] = stradd (&tdataptr, key_f46);
+   keydef_key[i++] = stradd (&tdataptr, key_f47);
+   keydef_key[i++] = stradd (&tdataptr, key_f48);
+   keydef_key[i++] = stradd (&tdataptr, key_f49);
+   keydef_key[i++] = stradd (&tdataptr, key_f50);
+   keydef_key[i++] = stradd (&tdataptr, key_f51);
+   keydef_key[i++] = stradd (&tdataptr, key_f52);
+   keydef_key[i++] = stradd (&tdataptr, key_f53);
+   keydef_key[i++] = stradd (&tdataptr, key_f54);
+   keydef_key[i++] = stradd (&tdataptr, key_f55);
+   keydef_key[i++] = stradd (&tdataptr, key_f56);
+   keydef_key[i++] = stradd (&tdataptr, key_f57);
+   keydef_key[i++] = stradd (&tdataptr, key_f58);
+   keydef_key[i++] = stradd (&tdataptr, key_f59);
+   keydef_key[i++] = stradd (&tdataptr, key_f60);
+   keydef_key[i++] = stradd (&tdataptr, key_f61);
+   keydef_key[i++] = stradd (&tdataptr, key_f62);
+   keydef_key[i++] = stradd (&tdataptr, key_f63);
+ #endif /*uniosu*/
  #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
  /* 以下順に
          "kcuu1", "kcuf1", "kcub1", "kcud1", "khome",
Index: FreeWnn/Wnn/include/commonhd.h
diff -c FreeWnn/Wnn/include/commonhd.h:1.1.1.1 FreeWnn/Wnn/include/commonhd.h:1.2
*** FreeWnn/Wnn/include/commonhd.h:1.1.1.1	Sun May  5 14:13:08 2002
--- FreeWnn/Wnn/include/commonhd.h	Fri Jul 11 21:05:16 2003
***************
*** 119,124 ****
--- 119,125 ----
  # endif
  # ifdef sun
  #  define SOLARIS
+ #  define USE_PTMX 1	/*VVV should use configure*/
  # endif
  #else
  # ifndef        BSD43
Index: FreeWnn/Wnn/uum/Makefile.in
diff -c FreeWnn/Wnn/uum/Makefile.in:1.1.1.1 FreeWnn/Wnn/uum/Makefile.in:1.2
*** FreeWnn/Wnn/uum/Makefile.in:1.1.1.1	Sat Jun 22 22:26:21 2002
--- FreeWnn/Wnn/uum/Makefile.in	Tue Jul 15 01:46:28 2003
***************
*** 38,43 ****
--- 38,46 ----
         UUMOWNER = root
         INCLUDES = -I$(WNNINCLUDESRC) -I$(WNNROMKANSRC) -I$(TOP)
          DEFINES = $(WNNDEFINES) $(WNNLANGDEF)
+ ## VVV todo: should update configure to switch both WNNJLIB and WNNCONVLIB
+ ## according to --with-wnn-libraries
+         DEPLIBS = @DEPWNNJLIB@ $(WNNCONVLIB)
  LOCAL_LIBRARIES = $(WNNJLIB) $(WNNCONVLIB) @LIBS@
  
  SRC1= epilogue.c header.c kensaku.c kuten.c jis_in.c       prologue.c touroku.c jikouho.c jutil.c w_string.c       printf.c termio.c hinsi.c termcap.c       ttyfdslot.c setutmp.c redraw.c history.c key_bind.c       screen.c basic_op.c uif.c cursor.c jhlp.c       select_ele.c inspect.c wnnrc_op.c functions.c
***************
*** 59,65 ****
  
  all:: uum
  
! uum: $(OBJS) $(LOCAL_LIBRARIES)
  	$(RM) $@
  	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB)
  
--- 62,68 ----
  
  all:: uum
  
! uum: $(OBJS) $(DEPLIBS)
  	$(RM) $@
  	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB)
  
Index: FreeWnn/Wnn/uum/jhlp.c
diff -c FreeWnn/Wnn/uum/jhlp.c:1.1.1.1 FreeWnn/Wnn/uum/jhlp.c:1.4
*** FreeWnn/Wnn/uum/jhlp.c:1.1.1.1	Sun Apr  6 14:55:17 2003
--- FreeWnn/Wnn/uum/jhlp.c	Tue Jul 15 03:26:13 2003
***************
*** 43,49 ****
  #if STDC_HEADERS
  #  include <stdlib.h>
  #  include <string.h>
- #  include <err.h>
  #else
  #  if HAVE_STRINGS_H
  #    include <strings.h>
--- 43,48 ----
***************
*** 364,370 ****
  
    open_pty ();
  #ifndef linux
!   open_ttyp ();
  #endif
    exec_cmd (argv);
  
--- 363,369 ----
  
    open_pty ();
  #ifndef linux
!   open_ttyp ();		/* (only?) linux opens slave after fork */
  #endif
    exec_cmd (argv);
  
***************
*** 869,878 ****
  /* *INDENT-ON* */
  {
  #ifdef HAVE_WAIT3
! #ifdef linux
    int status;
  #else
!   union wait status;
  #endif
    int pid;
  
--- 868,877 ----
  /* *INDENT-ON* */
  {
  #ifdef HAVE_WAIT3
! #if defined(linux) || defined(sun)
    int status;
  #else
!   union wait status;	/*VVV union wait is mostly deprecated; the (int*) cast below should be eventually eliminated */
  #endif
    int pid;
  
***************
*** 880,886 ****
   * Remove warning.
   * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp)         1996/8/20
   */
! /*  if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) { */
    if ((pid = wait3 ((int *) &status, WNOHANG | WUNTRACED, NULL)) == child_id)
      {
        if (WIFSTOPPED (status))
--- 879,885 ----
   * Remove warning.
   * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp)         1996/8/20
   */
! /*  if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) */
    if ((pid = wait3 ((int *) &status, WNOHANG | WUNTRACED, NULL)) == child_id)
      {
        if (WIFSTOPPED (status))
***************
*** 963,972 ****
  
  /** メインループ */
  
! int sel_ptn;
! int pty_bit;
! int tty_bit;
! int ptyfd;
  
  static void
  do_main ()
--- 962,972 ----
  
  /** メインループ */
  
! /* Assuming fd_set, FD_ZERO() family is available;
!  * copy the defines in ../jserver/de.c if in need
!  */
! fd_set sel_ptn;
! int ptyfd;	/* pseudo tty master */
  
  static void
  do_main ()
***************
*** 985,993 ****
        do_end ();
      }
  
!   pty_bit = 1 << ptyfd;
!   tty_bit = 1 << ttyfd;
!   sel_ptn = pty_bit | tty_bit;
  
    if (henkan_off_flag == 0)
      {
--- 985,993 ----
        do_end ();
      }
  
!   FD_ZERO(&sel_ptn);
!   FD_SET(ptyfd, &sel_ptn);
!   FD_SET(ttyfd, &sel_ptn);
  
    if (henkan_off_flag == 0)
      {
***************
*** 1060,1067 ****
    static unsigned char *bufend = outbuf;
    static unsigned char *bufstart = outbuf;
    int n;
!   int rfds;
!   int i, j, mask;
    unsigned char *p;
    extern int henkan_off_flag;
    struct timeval time_out;      /* If your OS's select was implemented as 
--- 1060,1067 ----
    static unsigned char *bufend = outbuf;
    static unsigned char *bufstart = outbuf;
    int n;
!   fd_set rfds, mask;
!   int i, j;
    unsigned char *p;
    extern int henkan_off_flag;
    struct timeval time_out;      /* If your OS's select was implemented as 
***************
*** 1105,1110 ****
--- 1105,1111 ----
  #ifdef linux
             (sel_ret = select (20, &rfds, 0, 0, NULL)) < 0 && errno == EINTR;
  #else
+ 	   /* should be using FD_SETSIZE rather than classical 20 */
             (sel_ret = select (20, &rfds, 0, 0, &time_out)) < 0 && errno == EINTR;
  #endif
             rfds = sel_ptn)
***************
*** 1124,1130 ****
  */
          }
  
!       if (rfds & pty_bit)
          {
            if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
              {
--- 1125,1131 ----
  */
          }
  
!       if (FD_ISSET(ptyfd, &rfds))
          {
            if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
              {
***************
*** 1156,1168 ****
                        p += j;
                        i -= j;
                      }
!                   mask = 1 << ttyfd;
                    select (32, 0, &mask, 0, 0);
                  }
                pop_cursor ();
              }
          }
!       if (rfds & tty_bit)
          {
            if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
              {
--- 1157,1170 ----
                        p += j;
                        i -= j;
                      }
! 		  FD_ZERO(&mask);
! 		  FD_SET(ttyfd, &mask);
                    select (32, 0, &mask, 0, 0);
                  }
                pop_cursor ();
              }
          }
!       if (FD_ISSET(ttyfd, &rfds))
          {
            if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
              {
***************
*** 1275,1281 ****
  
  /** 子プロセスを起こす。*/
  
! int ttypfd;
  
  static void
  exec_cmd (argv)
--- 1277,1283 ----
  
  /** 子プロセスを起こす。*/
  
! int ttypfd;	/* slave tty */
  
  static void
  exec_cmd (argv)
***************
*** 1289,1298 ****
    struct winsize win;
    extern Term_RowWidth, crow;
  #endif
- #if defined(SYSVR2) && !defined(linux)
-   setpgrp ();
-   close (open (ttyname (ttypfd), O_WRONLY, 0));
- #endif /* SYSVR2 */
  
    if (!(child_id = fork ()))
      {
--- 1291,1296 ----
***************
*** 1319,1324 ****
--- 1317,1326 ----
        close (open (ttyname (ttypfd), O_WRONLY, 0));
        setpgrp (0, pid);
  #endif /* BSD42 */
+ #if defined(SYSVR2) && !defined(linux)
+       setpgrp ();	/* should setpgrp() AFTER fork() */
+       close (open (ttyname (ttypfd), O_WRONLY, 0));
+ #endif /* SYSVR2 */
  
  #if !(defined(BSD) && (BSD >= 199306))
        if (setutmp (ttypfd) == ERROR)
***************
*** 1327,1333 ****
          }
  #endif
  
! #ifdef linux
        setsid ();
        open_ttyp ();
        close (ptyfd);
--- 1329,1335 ----
          }
  #endif
  
! #ifdef linux	/* (only?) linux open slave tty after fork */
        setsid ();
        open_ttyp ();
        close (ptyfd);
***************
*** 1496,1522 ****
  
  /** ttyp のオープン */
  
! int ptyno;
! char *ptynm = "/dev/pty";
! #ifdef sgi
! extern char *_getpty (int *, int, mode_t, int);
! char *ttypnm = "/dev/ttyqxxx";
! #else
! char *ttypnm = "/dev/tty";
! #endif /* sgi */
  
! #if defined(BSD43) || defined(DGUX)     /* FOR PASS8 */
! static int local_mode_sv;
  #endif
  
! #ifndef sgi
! static void ptyname ();
  #endif
  
  static void
  open_ttyp ()
  {
-   char nmbuf[20];
  #ifdef BSD42
    int word;
  #endif
--- 1498,1527 ----
  
  /** ttyp のオープン */
  
! /* Ways to get a pty:
! == Traditional
! 	Try opening each /dev/ptyXX and use the succeeded one
! == SGI IRIX
! 	use _getpty()
! == BSD? (USE_OPENPTY)
! 	use openpty()
! == STREAMS (Solaris) (USE_PTMX)
! 	use /dev/ptmx and ptsname() (see pts(7D) for EXAMPLE)
!  */
  
! #if !defined(sgi) && !defined(USE_PTMX)
! char tty_master[32];	/*VVVV overflow?*/
  #endif
+ char tty_slave [32];	/*VVVV overflow?*/
  
! #if defined(BSD43) || defined(DGUX)     /* FOR PASS8 */
! static int local_mode_sv;
  #endif
  
+ /* open slave side of pty to ttypfd */
  static void
  open_ttyp ()
  {
  #ifdef BSD42
    int word;
  #endif
***************
*** 1528,1545 ****
  #endif
  
  #ifdef sgi
!   if ((ttypfd = open (ttypnm, O_RDWR)) == ERROR)
!     {
! #else
!   ptyname (nmbuf, ttypnm, ptyno);
!   if ((ttypfd = open (nmbuf, O_RDWR, 0)) == ERROR)
      {
! #endif
        uum_err ("Can't open ttyp.");
      }
  #ifndef linux
!   chown (nmbuf, getuid (), getgid ());
!   chmod (nmbuf, 0622);
  #endif /* !linux */
  #ifdef BSD42
    ioctl (ttyfd, TIOCGETC, &tcharsv);
--- 1533,1559 ----
  #endif
  
  #ifdef sgi
!   if ((ttypfd = open (tty_slave, O_RDWR)) == ERROR)
! #else /*sgi*/
! #ifdef USE_PTMX	/*VVV ptmx*/
!     if ((ttypfd = open(tty_slave, O_RDWR)) == ERROR ||    /* open slave */
! 	 ioctl(ttypfd, I_PUSH, "ptem") == ERROR ||        /* push ptem */
! 	 ioctl(ttypfd, I_PUSH, "ldterm") == ERROR)        /* push ldterm */
! #else /* USE_PTMX */
! #if USE_OPENPTY
!   if (ttypfd < 0)	/* already open */
! #else /*USE_OPENPTY*/
!   if ((ttypfd = open (tty_slave, O_RDWR, 0)) == ERROR)
! #endif /*USE_OPENPTY*/
! #endif /* USE_PTMX */
! #endif /*sgi*/
      {
! perror(tty_slave);	/*VVV debug*/
        uum_err ("Can't open ttyp.");
      }
  #ifndef linux
!   chown (tty_slave, getuid (), getgid ());
!   chmod (tty_slave, 0622);
  #endif /* !linux */
  #ifdef BSD42
    ioctl (ttyfd, TIOCGETC, &tcharsv);
***************
*** 1664,1696 ****
  }
  
  /** pty のオープン */
  #ifdef sgi
  static void
  open_pty ()
  {
-   char nmbuf[20];
    char *tty_name_buff;
    tty_name_buff = _getpty (&ptyfd, O_RDWR | O_NDELAY, 0600, 0);
    if (tty_name_buff == 0)
      uum_err ("Can't get pty.");
!   strcpy (ttypnm, tty_name_buff);
    return;
- 
  }
! #else
  static void
  open_pty ()
  {
!   char nmbuf[20];
  #ifdef linux
    struct termio buf1;
  #endif
  
!   for (ptyno = 0; ptyno < 32; ptyno++)
      {
!       ptyname (nmbuf, ptynm, ptyno);
!       if ((ptyfd = open (nmbuf, O_RDWR, 0)) != ERROR)
          {
  #if defined(uniosu)
            if (ioctl (ptyfd, PIOCPKT, 1) < 0)
              {                   /* packet mode on */
--- 1678,1776 ----
  }
  
  /** pty のオープン */
+ /* allocate a new pty master into int ptyfd */
  #ifdef sgi
  static void
  open_pty ()
  {
    char *tty_name_buff;
+   extern char *_getpty (int *, int, mode_t, int);
    tty_name_buff = _getpty (&ptyfd, O_RDWR | O_NDELAY, 0600, 0);
    if (tty_name_buff == 0)
      uum_err ("Can't get pty.");
!   strcpy (tty_slave, tty_name_buff);
    return;
  }
! #else /*sgi*/
! #ifdef USE_PTMX
! static void
! open_pty ()
! {
!   char	*p;
!   extern char *ptsname();
!   ptyfd = open("/dev/ptmx", O_RDWR);   /* open master */
!   if (ptyfd < 0) {
!     uum_err("Can't get pty.");
!   }
!   grantpt(ptyfd);                      /* change permission of slave */
!   unlockpt(ptyfd);                     /* unlock slave */
! 
!   p = ptsname(ptyfd);	/* get name of slave */
!   strcpy(tty_slave, p);
!   /* you can't get path of the "master" by ttyname;
!    * only the open filedes ptyfd is available
!    */
!   /* strcpy(tty_master, "/dev/ptm/x"); */
!   return;
! }
! #else /* USE_PTMX */
! #if USE_OPENPTY
! static void
! open_pty ()
! {
!   if (openpty(&ptyfd, &ttypfd, tty_slave, NULL, NULL) == ERROR)
!     uum_err("Can't get pty.");
!   /* Note: slave tty is ALREADY OPEN as ttypfd */
!   strcpy(tty_master, ttyname(ptyfd));
! }
! #else /* USE_OPENPTY */
! /* Traditional searching in /dev/ttyXX */
  static void
  open_pty ()
  {
!   int ptyno;
  #ifdef linux
    struct termio buf1;
  #endif
+ 
+ #ifdef hpux
+ #define MAXPTYS (11*16)
+ #define PTYDEV "/dev/ptym/pty"
+ #define TTYDEV "/dev/pty/tty"
+ #else
+ #define MAXPTYS 32
+ #define PTYDEV "/dev/pty"
+ #define TTYDEV "/dev/tty"
+ #endif
  
!   for (ptyno = 0; ptyno < MAXPTYS; ptyno++)	/*VVV sysconf?*/
      {
! /*
!  * Change pseudo-devices.
!  * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
!  * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp)         1996/8/20
!  */
! #if (defined(BSD) && (BSD >= 199306))   /* 4.4BSD-Lite by Taoka */
! #define PTXNAME(b, PFX, no) \
!   sprintf ((b), PFX "%1c%1c", "pqrsPQRS"[((no) >> 5)], "0123456789abcdefghijklmnopqrstuv"[(no) & 0x1f])
! #else /* ! 4.4BSD-Lite */
! #ifdef hpux
! #define PTXNAME(b, PFX, no) \
!   sprintf ((b), PFX "%1c%1c", "zyxwvutsrqp"[(no)>>4], "fedcba9876543210"[(no)&0x0f])
! #else
! #define PTXNAME(b, PFX, no) \
!   sprintf ((b), PFX "%1c%1c", 'p' + ((no) >> 4), "0123456789abcdef"[(no) & 0x0f]);
! #endif /*hpux*/
! #endif /* ! 4.4BSD-Lite */
! #define PTMNAME(b, no) PTXNAME(b, PTYDEV, no)
! #define PTSNAME(b, no) PTXNAME(b, TTYDEV, no)
! 
!       PTMNAME(tty_master, ptyno);
! fprintf(stderr, "trying master <%s>\n", tty_master); /*VVV debug*/
!       if ((ptyfd = open (tty_master, O_RDWR, 0)) != ERROR)
          {
+ 	  PTSNAME(tty_slave, ptyno);
+ fprintf(stderr, "got master=%s slave=%s\n", tty_master, tty_slave); /*VVV debug*/
  #if defined(uniosu)
            if (ioctl (ptyfd, PIOCPKT, 1) < 0)
              {                   /* packet mode on */
***************
*** 1710,1716 ****
      }
    uum_err ("Can't get pty.");
  }
! #endif
  
  /** エラーだよ。さようなら。 */
  void
--- 1790,1798 ----
      }
    uum_err ("Can't get pty.");
  }
! #endif /* USE_OPENPTY */
! #endif /* USE_PTMX */
! #endif /*sgi*/
  
  /** エラーだよ。さようなら。 */
  void
***************
*** 1728,1735 ****
  static void
  do_end ()
  {
-   char nmbuf[20];
- 
    static int do_end_flg = 0;
    if (do_end_flg == 1)
      return;
--- 1810,1815 ----
***************
*** 1762,1786 ****
  #endif /* defined(uniosu) */
  
  #ifndef sgi
!   ptyname (nmbuf, ptynm, ptyno);
!   if (chown (nmbuf, 0, 0) == ERROR)
      {
        perror (prog);
      }
!   if (chmod (nmbuf, 0666) == ERROR)
      {
        perror (prog);
      }
  
!   ptyname (nmbuf, ttypnm, ptyno);
!   if (chown (nmbuf, 0, 0) == ERROR)
      {
        perror (prog);
      }
!   if (chmod (nmbuf, 0666) == ERROR)
      {
        perror (prog);
      }
  
  #if !(defined(BSD) && (BSD >= 199306))
    if (resetutmp (ttypfd) == ERROR)
--- 1842,1866 ----
  #endif /* defined(uniosu) */
  
  #ifndef sgi
! #ifndef USE_PTMX	/*VVV ptmx*/
!   if (chown (tty_master, 0, 0) == ERROR)
      {
        perror (prog);
      }
!   if (chmod (tty_master, 0666) == ERROR)
      {
        perror (prog);
      }
  
!   if (chown (tty_slave, 0, 0) == ERROR)
      {
        perror (prog);
      }
!   if (chmod (tty_slave, 0666) == ERROR)
      {
        perror (prog);
      }
+ #endif /* USE_PTMX */
  
  #if !(defined(BSD) && (BSD >= 199306))
    if (resetutmp (ttypfd) == ERROR)
***************
*** 1819,1825 ****
  {
    static unsigned char buf[BUFSIZ];
    int n;
!   int rfds;
  
    kk_restore_cursor ();
    clr_line_all ();
--- 1899,1905 ----
  {
    static unsigned char buf[BUFSIZ];
    int n;
!   fd_set rfds;
  
    kk_restore_cursor ();
    clr_line_all ();
***************
*** 1832,1839 ****
            write (ptyfd, buf, n);
          }
        rfds = sel_ptn;
!       select (20, &rfds, 0, 0, NULL);
!       if (rfds & pty_bit)
          {
            if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
              {
--- 1912,1919 ----
            write (ptyfd, buf, n);
          }
        rfds = sel_ptn;
!       select (20, &rfds, 0, 0, NULL);	/* should be using FD_SETSIZE */
!       if (FD_ISSET(ptyfd, &rfds))
          {
            if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
              {
***************
*** 1852,1858 ****
                  }
              }
          }
!       if (rfds & tty_bit)
          {
            if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
              {
--- 1932,1938 ----
                  }
              }
          }
!       if (FD_ISSET(ttyfd, &rfds))
          {
            if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
              {
***************
*** 1862,1887 ****
      }
  }
  #endif /* defined(uniosu) */
- 
- 
- #ifndef sgi
- static void
- ptyname (b, pty, no)
-      char *b, *pty;
-      int no;
- {
- /*
-  * Change pseudo-devices.
-  * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
-  * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp)         1996/8/20
-  */
- #if (defined(BSD) && (BSD >= 199306))   /* 4.4BSD-Lite by Taoka */
-   sprintf (b, "%s%1c%1c", pty, "pqrsPQRS"[(no >> 5)], ((no & 0x1f > 9) ? 'a' : '0') + (no & 0x1f));
- #else /* ! 4.4BSD-Lite */
-   sprintf (b, "%s%1c%1x", pty, 'p' + (no >> 4), no & 0x0f);
- #endif /* ! 4.4BSD-Lite */
- }
- #endif /* !sgi */
  
  /* Move to etc/xutoj.c
  int
--- 1942,1947 ----
Index: FreeWnn/Wnn/uum/setutmp.c
diff -c FreeWnn/Wnn/uum/setutmp.c:1.1.1.1 FreeWnn/Wnn/uum/setutmp.c:1.2
*** FreeWnn/Wnn/uum/setutmp.c:1.1.1.1	Sat Jun 22 22:26:21 2002
--- FreeWnn/Wnn/uum/setutmp.c	Fri Jul 11 21:05:19 2003
***************
*** 153,160 ****
    memset (&ut, 0, sizeof ut);
    if ((p = ttyname (ttyFd)) == NULL)
      return -1;
!   strncpy (ut.ut_line, strrchr (p, '/') + 1, 12);
!   strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8);
    ut.ut_time = time (0);
  #ifdef DGUX
    strncpy (ut.ut_id, &ut.ut_line[3], 4);
--- 153,162 ----
    memset (&ut, 0, sizeof ut);
    if ((p = ttyname (ttyFd)) == NULL)
      return -1;
! 
!   if (!strcmp(p, "/dev/")) p+=5;
!   strncpy(ut.ut_line, p, sizeof(ut.ut_line));
!   strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8); /*VVV should be sizeof(ut_user) */
    ut.ut_time = time (0);
  #ifdef DGUX
    strncpy (ut.ut_id, &ut.ut_line[3], 4);
***************
*** 212,219 ****
    memset (&ut, 0, sizeof ut);
    if ((p = ttyname (ttyFd)) == NULL)
      return -1;
!   strncpy (ut.ut_line, strrchr (p, '/') + 1, 12);
!   strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8);
    ut.ut_time = time (0);
  #ifdef DGUX
    strncpy (ut.ut_id, &ut.ut_line[3], 4);
--- 214,222 ----
    memset (&ut, 0, sizeof ut);
    if ((p = ttyname (ttyFd)) == NULL)
      return -1;
!   if (!strcmp(p, "/dev/")) p+=5;
!   strncpy (ut.ut_line, p, sizeof(ut.ut_line));
!   strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8); /*VVV sizeof*/
    ut.ut_time = time (0);
  #ifdef DGUX
    strncpy (ut.ut_id, &ut.ut_line[3], 4);
Index: FreeWnn/Wnn/uum/termio.c
diff -c FreeWnn/Wnn/uum/termio.c:1.1.1.1 FreeWnn/Wnn/uum/termio.c:1.2
*** FreeWnn/Wnn/uum/termio.c:1.1.1.1	Fri Jun 14 06:27:47 2002
--- FreeWnn/Wnn/uum/termio.c	Fri Jul 11 21:05:19 2003
***************