Index: configure.in
===================================================================
RCS file: /cvs/freewnn/FreeWnn/configure.in,v
retrieving revision 1.39
diff -u -r1.39 configure.in
--- configure.in	11 Jun 2003 11:16:05 -0000	1.39
+++ configure.in	26 Apr 2004 03:24:50 -0000
@@ -365,9 +365,80 @@
 	sys/file.h sys/ioctl.h sys/time.h sys/types.h sys/param.h \
 	malloc.h strings.h memory.h \
 	curses.h ncurses.h sgtty.h term.h termio.h termios.h \
+	termcap.h sys/termio.h
 )
 
 dnl
+dnl Terminal library selection. (ported from vim6.1)
+dnl
+olibs="$LIBS"
+AC_MSG_CHECKING(--with-term-libs argument)
+AC_ARG_WITH(tlib,
+[  --with-term-libs=-lLIB    terminal library to be used ],)
+if test -n "$with_term_libs"; then
+  AC_MSG_RESULT($with_term_libs)
+  WNNTERM_LIB="$with_term_libs"
+else
+  AC_MSG_RESULT([automatic terminal library selection])
+  dnl  On HP-UX 10.10 termcap or termlib should be used instead of
+  dnl  curses, because curses is much slower.
+  dnl  Newer versions of ncurses are preferred over anything.
+  dnl  Older versions of ncurses have bugs, get a new one!
+  dnl  Digital Unix (OSF1) should use curses (Ronald Schild).
+  case "`uname -s 2>/dev/null`" in
+	OSF1)	tlibs="ncurses curses termlib termcap";;
+	*)	tlibs="ncurses termlib termcap curses";;
+  esac
+  for libname in $tlibs; do
+    AC_CHECK_LIB(${libname}, tgetent,,)
+    if test "x$olibs" != "x$LIBS"; then
+      dnl It's possible that a library is found but it doesn't work
+      dnl e.g., shared library that cannot be found
+      dnl compile and run a test program to be sure
+      dnl If we are cross compiling, skip this test.
+      AC_RUN_IFELSE([
+#ifdef HAVE_TERMCAP_H
+# include <termcap.h>
+#endif
+main() {char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(0); }],
+			  res="OK", res="FAIL", res="OK")
+      LIBS="$olibs"
+      if test "$res" = "OK"; then
+	WNNTERM_LIB="-l$libname"
+	break
+      fi
+      AC_MSG_RESULT($libname library is not usable)
+    fi
+  done
+fi
+have_terminfo=no
+if test "x$WNNTERM_LIB" != "x"; then
+  AC_MSG_CHECKING(whether we talk terminfo)
+  LIBS="$WNNTERM_LIB $olibs"
+  AC_RUN_IFELSE([
+#ifdef HAVE_TERMCAP_H
+# include <termcap.h>
+#endif
+main()
+{char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(!strcmp(s==0 ? "" : s, "1")); }],
+	[AC_MSG_RESULT([no -- we are in termcap land])],
+	[AC_MSG_RESULT([yes -- terminfo spoken here]);
+	have_terminfo=yes],
+	[if test "x$ac_cv_header_term_h" = xyes; then
+	    AC_MSG_RESULT([probably yes -- you have term.h])
+	    have_terminfo=yes
+	else
+	    AC_MSG_RESULT([probably no -- you don't have term.h])
+	fi])
+else
+  AC_MSG_RESULT(none found)
+fi
+if test "x$have_terminfo" = xyes; then
+    AC_DEFINE(HAVE_TERMINFO, 1, [Define when terminfo support found.])
+fi
+LIBS="$olibs"
+AC_SUBST(WNNTERM_LIB)
+
 dnl Checks for typedefs, structures, and compiler characteristics.
 dnl
 AC_TYPE_MODE_T
@@ -382,6 +453,11 @@
 # include <sys/types.h>
 #endif
 #include <sys/socket.h>])
+AC_CHECK_TYPES(union wait,,,[
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#include <sys/wait.h>])
 
 dnl
 dnl Checks for symbol
@@ -402,6 +478,7 @@
 AC_CHECK_FUNCS(getpgid getpgrp setpgrp wait3)
 AC_FUNC_GETPGRP
 AC_FUNC_SETPGRP
+AC_CHECK_FUNCS(setsid dup2 killpg)
 dnl FreeWnn do not use the 3rd parameter of wait3().
 dnl AC_FUNC_WAIT3
 
Index: makerule.mk.in
===================================================================
RCS file: /cvs/freewnn/FreeWnn/makerule.mk.in,v
retrieving revision 1.11
diff -u -r1.11 makerule.mk.in
--- makerule.mk.in	11 May 2003 18:22:57 -0000	1.11
+++ makerule.mk.in	26 Apr 2004 03:24:50 -0000
@@ -91,7 +91,7 @@
 
 CCOPTIONS = @CCOPTIONS@
 ALLDEFINES = $(INCLUDES) $(DEFINES)
-CFLAGS = @CFLAGS@ @CDEBUGFLAGS@ $(CCOPTIONS) @ipv6@ @DEFS@ $(ALLDEFINES)
+CFLAGS = @CFLAGS@ @CDEBUGFLAGS@ $(CCOPTIONS) @ipv6@ @DEFS@ -DCONFIG_TERMINFO $(ALLDEFINES)
 LIBS = @LIBS@
 LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES) $(DEPEND_DEFINES)
 LDOPTIONS = @CDEBUGFLAGS@ $(CCOPTIONS)
@@ -112,7 +112,7 @@
       WNNBINDIR = ${PREFIX}/bin
       WNNINCDIR = @includedir@
       WNNLIBDIR = @libdir@
-    WNNTERM_LIB = -ltermcap
+    WNNTERM_LIB = @WNNTERM_LIB@
 
   PUBDICPLUSSRC = $(IMTOP)/PubdicPlus
   WNNCONSDICSRC = $(IMTOP)/Wnn-consortium/dic
Index: Wnn/conv/cvt_read.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/conv/cvt_read.c,v
retrieving revision 1.7
diff -u -r1.7 cvt_read.c
--- Wnn/conv/cvt_read.c	3 Apr 2002 04:16:19 -0000	1.7
+++ Wnn/conv/cvt_read.c	26 Apr 2004 03:24:50 -0000
@@ -54,13 +54,7 @@
 #endif
 
 #include "cvt_head.h"
-
-#ifdef SYSVR2
-#ifdef TERMINFO
-#include <curses.h>
-#endif /* TERMINFO */
-#include <term.h>
-#endif
+#include "wnn_os.h"
 
 #define ENTRY_LEN 10            /* ¥³¥ó¥Ð¡¼¥ÈÉ½¤Î¥¨¥ó¥È¥êÌ¾¤ÎºÇÂçÄ¹ */
 
Index: Wnn/etc/xutoj.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/etc/xutoj.c,v
retrieving revision 1.7
diff -u -r1.7 xutoj.c
--- Wnn/etc/xutoj.c	24 Mar 2002 01:25:13 -0000	1.7
+++ Wnn/etc/xutoj.c	26 Apr 2004 03:24:51 -0000
@@ -313,6 +313,7 @@
         ESC_SWITCH:
           switch (*ec)
             {
+#if 0
             case LS1R:
               glr_mode[GR] = G1;
               break;
@@ -328,6 +329,7 @@
             case LS3R:
               glr_mode[GR] = G3;
               break;
+#endif
             default:
               ret = check_designate (ec, eend, &ret_buf);
               ec += ret;
Index: Wnn/include/commonhd.h
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/include/commonhd.h,v
retrieving revision 1.10
diff -u -r1.10 commonhd.h
--- Wnn/include/commonhd.h	30 May 2003 16:17:59 -0000	1.10
+++ Wnn/include/commonhd.h	26 Apr 2004 03:24:51 -0000
@@ -110,7 +110,7 @@
 #  define       TERMCAP
 # endif
 #else
-#if defined(SVR4) || defined(hpux)
+#if defined(SVR4) || defined(hpux) || defined(SYSV) || defined(USG)
 # ifndef        SYSVR2
 #  define       SYSVR2
 # endif
@@ -130,11 +130,21 @@
 # ifndef        TERMCAP
 #  define       TERMCAP
 # endif
-#endif /* defined(SVR4) || defined(hpux) */
+#endif /* defined(SVR4) || defined(hpux) || defined(SYSV) || defined(USG) */
 #endif /* DGUX */
 #endif /* sun */
 #endif /* luna */
 
+#ifdef CONFIG_TERMINFO
+# undef TERMCAP
+# undef TERMINFO
+# ifdef HAVE_TERMINFO
+#  define TERMINFO
+# else
+#  define TERMCAP
+# endif
+#endif
+
 #if defined(SVR4) || defined(hpux)
 #ifndef F_OK
 #define F_OK    0
Index: Wnn/include/wnn_os.h
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/include/wnn_os.h,v
retrieving revision 1.14
diff -u -r1.14 wnn_os.h
--- Wnn/include/wnn_os.h	8 Jun 2003 03:09:51 -0000	1.14
+++ Wnn/include/wnn_os.h	26 Apr 2004 03:24:51 -0000
@@ -49,10 +49,62 @@
 #  include <sys/param.h>
 #endif
 
+/* ncurses' term.h defines them to either 0 or 1! */
+#ifndef HAVE_TERMIOS_H
+#  define DONT_HAVE_TERMIOS_H
+#endif
+#ifndef HAVE_TERMIO_H
+#  define DONT_HAVE_TERMIO_H
+#endif
+#ifndef HAVE_SYS_TERMIO_H
+#  define DONT_HAVE_SYS_TERMIO_H
+#endif
+#ifndef HAVE_SGTTY_H
+#  define DONT_HAVE_SGTTY_H
+#endif
+
+#ifdef CONFIG_TERMINFO
+#  if defined(HAVE_TERMINFO)
+#    if defined(HAVE_CURSES_H)
+#      include <curses.h>
+#    elif defined(HAVE_NCURSES_H)
+#      include <ncurses.h>
+#    else
+#      error "no terminfo header"
+#    endif
+#    ifdef HAVE_TERM_H
+#      include <term.h>
+#    endif
+#  else /* !HAVE_TERMINFO */
+#    if defined(HAVE_TERMCAP_H)
+#       include <termcap.h>
+#    endif
+#  endif
+#endif
+
+#ifndef CONFIG_TERMINFO
 #ifdef TERMINFO
 #include <curses.h>
 #include <term.h>
 #endif
+#endif
+
+#ifdef DONT_HAVE_TERMIOS_H
+#  undef HAVE_TERMIOS_H
+#  undef DONT_HAVE_TERMIOS_H
+#endif
+#ifdef DONT_HAVE_TERMIO_H
+#  undef HAVE_TERMIO_H
+#  undef DONT_HAVE_TERMIO_H
+#endif
+#ifdef DONT_HAVE_SYS_TERMIO_H
+#  undef HAVE_SYS_TERMIO_H
+#  undef DONT_HAVE_SYS_TERMIO_H
+#endif
+#ifdef DONT_HAVE_SGTTY_H
+#  undef HAVE_SGTTY_H
+#  undef DONT_HAVE_SGTTY_H
+#endif
 
 /* strchr vs. index, etc. */
 #if (HAVE_MEMSET) && !(HAVE_BZERO)
@@ -135,16 +187,40 @@
 #define BINTSIZE               (sizeof(unsigend long) *8)
 #define SETSIZE         WNN_NFD
 #define SET_WIDTH       ((SETSIZE) + (BINTSIZE - 1U) / (BINTSIZE))
-typedef struct wnn_fd_set {
-  wnn_fd_mask fds_bits[SET_WIDTH];
+typedef struct fd_set {
+  fd_mask fds_bits[SET_WIDTH];
 }
 #define FD_SET(pos,array)  (array[pos/BINTSIZE] |= (1<<(pos%BINTSIZE)))
 #define FD_CLR(pos,array)  (array[pos/BINTSIZE] &= ~(1<<(pos%BINTSIZE)))
-#define FD_ISSET(pos,array)        (array[pos/BINTSIZE] &  (1<<(pos%BINTSIZ
-E)))
+#define FD_ISSET(pos,array)        (array[pos/BINTSIZE] &  (1<<(pos%BINTSIZE)))
 #define FD_ZERO(array)     (bzero (array, FD_SET_WIDTH))
 #endif /* !HAVE_FD_SET */
 
+#ifdef HAVE_KILLPG
+# define KILLPG(pgrp, sig) killpg(pgrp, sig)
+#else
+# define KILLPG(pgrp, sig) kill(-(pgrp), sig)
+#endif /* HAVE_KILLPG */
+
+#if defined(HAVE_GETPGID) /* SVR4 and most modern systems */
+# define GETPGID(pid) getpgid(pid)
+#elif defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) /* 4.3BSD */
+# define GETPGID(pid) getpgrp(pid)
+#elif defined(uniosu)
+# define GETPGID(pid) ngetpgrp(pid)
+#else
+/* no way to get process group id */
+#endif /* GETPGID */
+
+#if defined(HAVE_GETPGRP) && defined(GETPGRP_VOID) /* POSIX, SysV */
+# define GETMYPGRP() getpgrp()
+#elif defined(GETPGID)
+# define GETMYPGRP() GETPGID(getpid())
+#else
+/* probably some build error occured */
+# error "don't know how to get my process group id"
+#endif /* GETMYPGRP */
+
 
 /* function prototypes (temporal use. need reconstruction) */
 int get_short (short *sp, FILE *ifpter);	/* bdic.c */
Index: Wnn/uum/Makefile.in
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/Makefile.in,v
retrieving revision 1.11
diff -u -r1.11 Makefile.in
--- Wnn/uum/Makefile.in	22 Jun 2002 13:26:21 -0000	1.11
+++ Wnn/uum/Makefile.in	26 Apr 2004 03:24:51 -0000
@@ -33,16 +33,16 @@
 top_builddir = ../..
 
 INSTALL         = @INSTALL@ $(INSTALLFLAGS)
-LOCAL_INSTFLAGS = $(INSTUIDFLAGS) -o $(UUMOWNER)
+LOCAL_INSTFLAGS = -o $(UUMOWNER)
 
        UUMOWNER = root
-       INCLUDES = -I$(WNNINCLUDESRC) -I$(WNNROMKANSRC) -I$(TOP)
-        DEFINES = $(WNNDEFINES) $(WNNLANGDEF)
-LOCAL_LIBRARIES = $(WNNJLIB) $(WNNCONVLIB) @LIBS@
+       INCLUDES = -I$(WNNINCLUDESRC) -I$(WNNROMKANSRC) -I$(TOP) `libspt-config --cflags`
+        DEFINES = $(WNNDEFINES) $(WNNLANGDEF) -DUSE_LIBSPT
+LOCAL_LIBRARIES = $(WNNJLIB) $(WNNCONVLIB)
 
-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
+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       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
 
-OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       ttyfdslot.o setutmp.o redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
+OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
 
 SRC2= $(WNNETCSRC)/bcopy.c
 OBJ2= bcopy.o
@@ -61,7 +61,7 @@
 
 uum: $(OBJS) $(LOCAL_LIBRARIES)
 	$(RM) $@
-	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB)
+	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB) `libspt-config --libs` @LIBS@
 
 clean::
 	$(RM) uum
@@ -71,7 +71,7 @@
 install:: uum
 	@if [ -d $(DESTDIR)$(JWNNBINDIR) ]; then set +x; \
 	else (set -x; $(MKDIRHIER) $(DESTDIR)$(JWNNBINDIR)); fi
-	$(LIBTOOL) $(INSTALL) $(INSTALLFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) uum $(DESTDIR)$(JWNNBINDIR)/uum
+	$(LIBTOOL) $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) uum $(DESTDIR)$(JWNNBINDIR)/uum
 
 $(OBJ2) : $(SRC2)
 	$(CC) -c $(CFLAGS)  $(WNNETCSRC)/`basename $@ .o`.c
Index: Wnn/uum/header.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/header.c,v
retrieving revision 1.5
diff -u -r1.5 header.c
--- Wnn/uum/header.c	16 Sep 2001 11:42:58 -0000	1.5
+++ Wnn/uum/header.c	26 Apr 2004 03:24:51 -0000
@@ -30,9 +30,8 @@
  */
 
 #include <stdio.h>
-#include "jllib.h"
-#include "wnn_config.h"
 #include "commonhd.h"
+#include "wnn_config.h"
 #include "sdefine.h"
 #include "sheader.h"
 #include "buffer.h"
@@ -121,7 +120,7 @@
 short internal_code;
 short file_code;
 
-int (**code_trans) ();
+int (**code_trans) (char *x, char *y, int z);
 
 struct msg_cat *cd;
 
@@ -131,7 +130,7 @@
 
 FuncDataBase function_db[] = {
 #ifdef JAPANESE
-  {"ja_JP",
+  {WNN_J_LANG,
    {NULL, NULL, call_t_redraw_move_normal,
     call_t_redraw_move_1_normal, call_t_redraw_move_2_normal,
     call_t_print_l_normal, NULL, char_len_normal, char_q_len_normal,
@@ -151,7 +150,7 @@
    },
 #endif /* JAPANESE */
 #ifdef CHINESE
-  {"zh_CN",                     /* Simplified Chinese */
+  {WNN_C_LANG,                  /* Simplified Chinese */
    {print_out_yincod, input_yincod, call_t_redraw_move_yincod,
     call_t_redraw_move_1_yincod, call_t_redraw_move_2_yincod,
     call_t_print_l_yincod, redraw_when_chmsig_yincod, char_len_yincod,
@@ -170,7 +169,7 @@
    {
     NULL, NULL, NULL, NULL, NULL, NULL}
    },
-  {"zh_TW",                     /* Traditional Chinese */
+  {WNN_T_LANG,                  /* Traditional Chinese */
    {print_out_yincod, input_yincod, call_t_redraw_move_yincod,
     call_t_redraw_move_1_yincod, call_t_redraw_move_2_yincod,
     call_t_print_l_yincod, redraw_when_chmsig_yincod, char_len_yincod,
Index: Wnn/uum/jhlp.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/jhlp.c,v
retrieving revision 1.15
diff -u -r1.15 jhlp.c
--- Wnn/uum/jhlp.c	11 May 2003 18:25:29 -0000	1.15
+++ Wnn/uum/jhlp.c	26 Apr 2004 03:24:51 -0000
@@ -43,7 +43,6 @@
 #if STDC_HEADERS
 #  include <stdlib.h>
 #  include <string.h>
-#  include <err.h>
 #else
 #  if HAVE_STRINGS_H
 #    include <strings.h>
@@ -81,21 +80,28 @@
 #       include <sys/wait.h>
 #endif /* HAVE_WAIT3 */
 
-#ifdef BSD42
-#       include <sgtty.h>
-#endif /* BSD42 */
+#ifdef USE_LIBSPT
+# include <libspt.h>
+#endif
 
-#ifdef SYSVR2
-#ifdef TERMINFO
-#       include <curses.h>
-#endif /* TERMINFO */
-#       include <term.h>
-#endif /* SYSVR2 */
-#if defined(SVR4) || defined(hpux) || defined(sgi)
-#include <sys/termio.h>
+#if defined(HAVE_TERMIOS_H)
+# include <termios.h>
+# define USE_TERMIOS
+#elif defined(HAVE_TERMIO_H)
+# include <termio.h>
+# define USE_TERMIO
+#elif defined(HAVE_SYS_TERMIO_H)
+# include <sys/termio.h>
+# define USE_TERMIO
+#elif defined(HAVE_SGTTY_H)
+# include <sgtty.h>
+# define USE_SGTTY
+#else
+# error "No termio header."
 #endif
+
 #ifdef linux
-#include <termios.h>
+/* # define USE_LINUX_TERM */ /* for ancient(?) Linux */
 #endif
 
 #ifdef nec_ews_svr2
@@ -125,6 +131,10 @@
 
 int child_id;
 char *prog;
+#ifdef USE_LIBSPT
+spt_handle *spth = NULL;
+int need_utmp_clear = 0;
+#endif
 
 extern char *optarg;
 extern int optind;
@@ -136,6 +146,7 @@
 
 static RETSIGTYPE terminate_handler ();
 static void do_end (), open_pty (), open_ttyp (), do_main (), exec_cmd (), parse_options (), setsize (), get_rubout (), usage (), change_size (), default_usage ();
+static void j_term_save (), j_term_restore (), j_term_p_init (int);
 
 /** ¥á¥¤¥ó */
 int
@@ -296,17 +307,6 @@
       exit (1);
     }
 
-
-#if defined(BSD42) && !defined(DGUX)
-#if !(defined(BSD) && (BSD >= 199306))
-  if (saveutmp () < 0)
-    {
-      puts ("Can't save utmp\n");
-    }
-#endif
-#endif /* BSD42 */
-
-
   if (optind)
     {
       optind--;
@@ -327,6 +327,8 @@
       argv[1] = NULL;
     }
 
+  j_term_save ();
+  /* do_end() is allowed after here */
   save_signals ();
 
 #ifdef TERMCAP
@@ -357,24 +359,13 @@
     }
 #endif /* TERMCAP */
 
+  ttyfd = 0;
   open_pty ();
-#ifndef linux
+#ifndef USE_LINUX_TERM
   open_ttyp ();
 #endif
   exec_cmd (argv);
 
-  /*
-     close(0);
-     close(1);
-     close(2);
-     if((ttyfd = open("/dev/tty", O_RDWR | O_NDELAY, 0)) != 0) {
-     err("Can't open /dev/tty.");
-     }
-     dup(0);
-     dup(0);
-   */
-
-  ttyfd = 0;
   get_rubout ();
 
   switch (init_uum ())
@@ -683,19 +674,24 @@
 
 /** tty ¤ËÂÐ¤¹¤ë ioctl ¤Î¥»¥Ã¥È */
 
-#ifdef BSD42
+#ifdef USE_SGTTY
+#if defined(BSD43) || defined(DGUX) /* should be "defined(LPASS8)"? */
+#  define SET_PASS8
+#endif
 struct sgttyb savetmio;
-/*
-  struct sgttyb ttyb =
-  { B9600, B9600, 0x7f, 0x15, EVENP | ODDP | ECHO | CRMOD };
-  int local_mode = LCRTBS | LCRTERA | LCRTKIL | LCTLECH | LPENDIN | LDECCTQ;
-*/
+struct sgttyb ttyb_def =
+{ B9600, B9600, 0x7f, 0x15, EVENP | ODDP | ECHO | CRMOD };
+int local_mode_def = LCRTBS | LCRTERA | LCRTKIL | LCTLECH | LPENDIN | LDECCTQ;
 
 /* added later */
 struct tchars tcharsv;
 struct ltchars ltcharsv;
 struct sgttyb ttyb;
 int local_mode;
+#ifdef SET_PASS8
+static int local_mode_sv;
+#endif
+
 
 static void
 get_rubout ()
@@ -723,28 +719,128 @@
   buf.sg_flags |= RAW;
   buf.sg_flags &= ~ECHO;
   ioctl (ttyfd, TIOCSETP, &buf);
+#ifdef SET_PASS8
+  ioctl (ttyfd, TIOCLSET, &local_mode);
+#endif
 
   return 0;
 }
-#endif /* BSD42 */
 
-#ifdef SYSVR2
-#define UNDEF_STTY 0xff
+static void
+j_term_save ()
+{
+  ioctl (ttyfd, TIOCGETC, &tcharsv);
+  ioctl (ttyfd, TIOCGLTC, &ltcharsv);
+  if (ioctl (ttyfd, TIOCGETP, &ttyb))
+    ttyb = ttyb_def;
+  savetmio = ttyb;
+#ifdef SET_PASS8
+  if (ioctl (ttyfd, TIOCLGET, &local_mode_sv))
+    local_mode_sv = local_mode_def;
+  local_mode = local_mode_sv | LPASS8;  /* set PASS8 */
+#else /* !SET_PASS8 */
+  if (ioctl (ttyfd, TIOCLGET, &local_mode))
+    local_mode = local_mode_def;
+#endif /* !SET_PASS8 */
+}
 
-struct termio savetmio;
-struct termio terms = {
-  IGNBRK | ICRNL | IXON,        /* c_iflag */
-  ONLCR | OPOST,                /* c_oflag */
-  B9600 | CS8 | CSTOPB | CREAD | CLOCAL,        /* c_cflag */
-  ISIG | ICANON | ECHO | ECHOE | ECHOK, /* c_lflag */
-  0,                            /* c_line */
-  {0x3, 0x1c, 0x8, 0x15, 0x4, 0, 0, 0}  /* c_cc */
-};
+static void
+j_term_restore ()
+{
+  ioctl (ttyfd, TIOCSETP, &savetmio);
+#ifdef SET_PASS8
+  ioctl (ttyfd, TIOCLSET, &local_mode_sv);
+#endif /* SET_PASS8 */
+}
+
+static void
+j_term_p_init (ttypfd)
+  int ttypfd;
+{
+  int word;
+  ioctl (ttypfd, TIOCSETC, &tcharsv);
+  ioctl (ttypfd, TIOCSLTC, &ltcharsv);
+  ioctl (ttypfd, TIOCSETP, &ttyb);
+  ioctl (ttypfd, TIOCLSET, &local_mode);
+  if (pty_c_flag == J_JIS)
+    {
+      word = LCTLECH;
+      ioctl (ttypfd, TIOCLBIC, &word);
+    }
+}
+#endif /* USE_SGTTY */
+
+#if defined(USE_TERMIO) || defined(USE_TERMIOS)
+
+#ifdef USE_TERMIOS
+# define TERMIO termios
+# define GET_TERMATTR(fd, tio) tcgetattr(fd, tio)
+# define SET_TERMATTR(fd, tio) tcsetattr(fd, TCSADRAIN, tio)
+# define UNDEF_STTY _POSIX_VDISABLE
+# define SET_ATTR_ERROR "error in tcsetattr.\n"
+#else
+# define TERMIO termio
+# define GET_TERMATTR(fd, tio) ioctl(fd, TCGETA, tio)
+# ifdef TCSETAW
+#  define SET_TERMATTR(fd, tio) ioctl(fd, TCSETAW, tio)
+# else
+#  define SET_TERMATTR(fd, tio) ioctl(fd, TCSETA, tio)
+# endif
+# define UNDEF_STTY 0xff
+# define SET_ATTR_ERROR "error in ioctl TCSETA.\n"
+#endif
+#ifdef CERASE
+# define WNN_CERASE CERASE
+#elif defined(CDEL)
+# define WNN_CERASE CDEL
+#else
+# define WNN_CERASE 0x7f
+#endif
+
+struct TERMIO savetmio;
+
+static void
+set_default_termio (terms)
+  struct TERMIO *terms;
+{
+  bzero (terms, sizeof *terms);
+  terms->c_iflag = IGNBRK | ICRNL | IXON;
+  terms->c_oflag = OPOST;
+#ifdef ONLCR
+  terms->c_oflag |= ONLCR;
+#endif
+  terms->c_cflag = CS8 | CSTOPB | CREAD | CLOCAL;
+#ifndef USE_TERMIOS
+  terms->c_cflag |= B9600;
+#endif
+  terms->c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK;
+#ifdef USE_TERMIOS
+  terms->c_cc[VINTR] = 0x3;
+  terms->c_cc[VQUIT] = 0x1c;
+  terms->c_cc[VERASE] = 0x8;
+  terms->c_cc[VKILL] = 0x15;
+  terms->c_cc[VEOF] = 0x4;
+  terms->c_cc[VEOL] = _POSIX_VDISABLE;
+#ifdef VEOL2
+  terms->c_cc[VEOL2] = _POSIX_VDISABLE;
+#endif
+  cfsetospeed (terms, B9600);
+  cfsetispeed (terms, B9600);
+#else
+  terms->c_line = 0;
+  terms->c_cc[0] = 0x3;
+  terms->c_cc[1] = 0x1c;
+  terms->c_cc[2] = 0x8;
+  terms->c_cc[3] = 0x15;
+  terms->c_cc[4] = 0x4;
+  terms->c_cc[5] = 0;
+  terms->c_cc[6] = 0;
+  terms->c_cc[7] = 0;
+#endif
+}
 
 #if defined(uniosu)
 struct jtermio savejtmio;
-struct jtermio savejtmiottyp;
-struct auxtermio saveauxterm;
 struct auxtermio auxterm = {
   0,                            /* -tostop */
   {0x1a, 0, 0, 0, 0, 0, 0, 0}   /* c_cc2 */
@@ -767,48 +863,56 @@
 int
 j_term_init ()
 {
-  struct termio buf1;
+  struct TERMIO buf1;
 #if defined(uniosu)
   struct jtermio buf2;
 #endif /* defined(uniosu) */
 
   buf1 = savetmio;
-#ifdef linux
+#ifdef USE_LINUX_TERM
   buf1.c_lflag &= ~(ECHONL | ECHOK | ECHOE | ECHO | XCASE | ICANON | ISIG);
   buf1.c_iflag = 0;
   buf1.c_oflag &= ~OPOST;
   buf1.c_cflag |= CS8;
   buf1.c_cc[VMIN] = 1;          /* cf. ICANON */
   buf1.c_cc[VTIME] = 0;
-#else /* linux */
-  buf1.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IUCLC | IXON);
+#else /* !USE_LINUX_TERM */
+  buf1.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+#ifdef IUCLC
+  buf1.c_iflag &= IUCLC;
+#endif
   if (flow_control)
     {
       buf1.c_iflag |= IXON;
     }
-  buf1.c_lflag &= ~(ECHONL | ECHOK | ECHOE | ECHO | XCASE | ICANON | ISIG);
+  buf1.c_lflag &= ~(ECHONL | ECHOK | ECHOE | ECHO | ICANON | ISIG);
+#ifdef XCASE
+  buf1.c_lflag &= XCASE;
+#endif
   buf1.c_oflag = OPOST;
-  buf1.c_cc[VINTR] = CDEL;
-  buf1.c_cc[VQUIT] = CDEL;
-  buf1.c_cc[VERASE] = CDEL;
-  buf1.c_cc[VKILL] = CDEL;
+#ifdef USE_TERMIOS
+  buf1.c_cc[VMIN] = 1;          /* cf. ICANON */
+  buf1.c_cc[VTIME] = 0;
+  cfsetispeed(&buf1, cfgetispeed(&savetmio));
+  cfsetospeed(&buf1, cfgetospeed(&savetmio));
+#else /* !USE_TERMIOS */
   buf1.c_cc[VEOF] = 1;          /* cf. ICANON */
   buf1.c_cc[VEOL] = 0;
-#endif /* linux */
-  if (ioctl (ttyfd, TCSETA, &buf1) == -1)
+  /* not needed? cf.ISIG*/
+  buf1.c_cc[VINTR] = WNN_CERASE;
+  buf1.c_cc[VQUIT] = WNN_CERASE;
+  buf1.c_cc[VERASE] = WNN_CERASE;
+  buf1.c_cc[VKILL] = WNN_CERASE;
+#endif /* !USE_TERMIOS */
+#endif /* !USE_LINUX_TERM */
+  if (SET_TERMATTR (ttyfd, &buf1) < 0)
     {
-      fprintf (stderr, "error in ioctl TCSETA.\n");
+      fprintf (stderr, SET_ATTR_ERROR);
       exit (1);
     }
 
 #if defined(uniosu)
-  if (ioctl (ttyfd, JTERMGET, &buf2) < 0)
-    {
-      fprintf (stderr, "error in ioctl JTERMGET in j_term_init.\n");
-      exit (1);
-    }
-  savejtmio = buf2;
-
+  buf2 = savejtmio;
   buf2.j_flg = CONVTOEXT | WNN_EXIST;
   buf2.j_level = jterm;
   switch (jcode_set)
@@ -855,7 +959,121 @@
 
   return 0;
 }
-#endif /* SYSVR2 */
+
+static void
+j_term_save ()
+{
+  if (GET_TERMATTR (ttyfd, &savetmio) < 0)
+    {
+      set_default_termio (&savetmio);
+    }
+#if defined(uniosu)
+  if (ioctl (ttyfd, JTERMGET, &savejtmio) < 0)
+    {
+      fprintf (stderr, "uum: error in ioctl JTERMGET in open_ttyp.\n");
+      exit (1);
+    }
+#endif /* defined(uniosu) */
+}
+
+static void
+j_term_restore ()
+{
+  if (SET_TERMATTR (ttyfd, &savetmio) < 0)
+    {
+      fprintf (stderr, SET_ATTR_ERROR);
+      exit (1);
+    }
+
+#if defined(uniosu)
+  if (ioctl (ttyfd, JTERMSET, &savejtmio) < 0)
+    {
+      fprintf (stderr, "error in ioctl JTERMSET.\n");
+      exit (1);
+    }
+#endif /* defined(uniosu) */
+}
+
+static void
+j_term_p_init (ttypfd)
+  int ttypfd;
+{
+  struct TERMIO buf1;
+#if defined(uniosu)
+  struct TERMIO buf2;
+#endif
+  buf1 = savetmio;
+#ifdef DGUX                     /* copied from JLS5.4.2 */
+  /* should clear on all platforms? */
+  buf1.c_iflag &= ~ISTRIP;
+#endif /* DGUX */
+#ifdef nec_ews_svr2
+  buf1.c_line = JAPANLD;
+#endif
+#ifdef USE_TERMIOS
+  cfsetispeed(&buf1, cfgetispeed(&savetmio));
+  cfsetospeed(&buf1, cfgetospeed(&savetmio));
+#endif
+  if (SET_TERMATTR (ttypfd, &buf1) < 0)
+    {
+      fprintf (stderr, SET_ATTR_ERROR);
+      exit (1);
+    }
+#if defined(uniosu)
+  buf2 = savejtmio;
+  buf2.j_flg = CONVTOEXT | KANJIINPUT;  /* kanji input & output ok */
+  buf2.j_level = jterm;
+  switch (jcode_set)
+    {
+    case 0:
+      buf2.j_ecode = JIS;
+      break;
+    case 1:
+      buf2.j_ecode = SJIS;
+      break;
+    case 2:
+      buf2.j_ecode = UJIS;
+      break;
+    default:
+      fprintf (stderr, "uum: kanji code set not supported in terminfo.\n");
+      exit (1);
+    }
+
+  if (jis_kanji_in)
+    {
+      strcpy (buf2.j_jst, jis_kanji_in);
+      buf2.j_jstl = strlen (jis_kanji_in);
+    }
+  if (jis_kanji_out)
+    {
+      strcpy (buf2.j_jend, jis_kanji_out);
+      buf2.j_jendl = strlen (jis_kanji_out);
+    }
+  if (jgaiji_start_address)
+    {
+      *(short *) buf2.j_gcsa = jgaiji_start_address;
+    }
+  if (jgaiji_disp)
+    {
+      strcpy (buf2.j_gdsp, jgaiji_disp);
+      buf2.j_gdspl = strlen (jgaiji_disp);
+    }
+
+  if (ioctl (ttypfd, JTERMSET, &buf2) < 0)
+    {
+      fprintf (stderr, "error in ioctl JTERMSET.\n");
+      exit (1);
+    }
+
+  if (ioctl (ttypfd, TIOCSETAUX, &auxterm) < 0)
+    {
+      fprintf (stderr, "error in ioctl TIOCSETAUX.\n");
+      exit (1);
+    }
+
+#endif /* defined(uniosu) */
+}
+#endif /* USE_TERMIO || USE_TERMIOS */
 
 /** signal SIGCHLD ¤ò¼õ¤±¤¿¸å¤Î½èÍý¤ò¤¹¤ë¡£*/
 /* *INDENT-OFF* */
@@ -864,33 +1082,21 @@
 /* *INDENT-ON* */
 {
 #ifdef HAVE_WAIT3
-#ifdef linux
-  int status;
-#else
+#if !defined(_POSIX_VERSION) && defined(HAVE_UNION_WAIT) /* older way */
   union wait status;
+#else /* POSIX */
+  int status;
 #endif
   int pid;
 
-/*
- * 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 ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id)
     {
       if (WIFSTOPPED (status))
         {
 #ifdef SIGCONT
           kill (pid, SIGCONT);
-#ifndef SYSVR2
-          /* pid = getpgrp (pid); */
-          pid = getpgrp ();
-          killpg (pid, SIGCONT);
-#else
-#if defined(uniosu)
-          pid = ngetpgrp (pid);
-          kill (pid, SIGCONT);
-#endif
+#ifdef GETPGID
+	  KILLPG (GETPGID (pid), SIGCONT);
 #endif
 #endif
         }
@@ -901,6 +1107,10 @@
           /*
              printf("\r\n£õ£õ£í¤ò½ª¤ï¤ê¤Þ¤¹¡£\r\n");
            */
+#ifdef USE_LIBSPT
+	  if (spth)
+	    spt_utmp_set_exit (spth, *(int *)&status);
+#endif
           epilogue ();
           do_end ();
         }
@@ -958,10 +1168,8 @@
 
 /** ¥á¥¤¥ó¥ë¡¼¥× */
 
-int sel_ptn;
-int pty_bit;
-int tty_bit;
-int ptyfd;
+fd_set sel_ptn;
+int ptyfd = -1;
 
 static void
 do_main ()
@@ -980,9 +1188,8 @@
       do_end ();
     }
 
-  pty_bit = 1 << ptyfd;
-  tty_bit = 1 << ttyfd;
-  sel_ptn = pty_bit | tty_bit;
+  FD_SET(ptyfd, &sel_ptn);
+  FD_SET(ttyfd, &sel_ptn);
 
   if (henkan_off_flag == 0)
     {
@@ -994,13 +1201,7 @@
 
       ml = kk ();
 
-/*
-      if (!((ml < 2) && ((return_buf[0] <= ' ') || (return_buf[0] == 0x7f)))) {
-*/
       make_history (return_buf, ml);
-/*
-      }
-*/
       ml = (*code_trans[(internal_code << 2) | pty_c_flag]) (buf, return_buf, sizeof (w_char) * ml);
       if (ml > 0)
         write (ptyfd, buf, ml);
@@ -1055,8 +1256,8 @@
   static unsigned char *bufend = outbuf;
   static unsigned char *bufstart = outbuf;
   int n;
-  int rfds;
-  int i, j, mask;
+  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 
@@ -1097,7 +1298,7 @@
       time_out.tv_sec = 0;
       time_out.tv_usec = 200 * 1000;    /* 200 msec ´ÖÂÔ¤Ä¤Î¤À¥¾! */
       for (rfds = sel_ptn;
-#ifdef linux
+#ifdef USE_LINUX_TERM
            (sel_ret = select (20, &rfds, 0, 0, NULL)) < 0 && errno == EINTR;
 #else
            (sel_ret = select (20, &rfds, 0, 0, &time_out)) < 0 && errno == EINTR;
@@ -1114,12 +1315,9 @@
               return (*bufstart++);
             }
           return (0xff);
-/*
-            continue;
-*/
         }
 
-      if (rfds & pty_bit)
+      if (FD_ISSET(ptyfd, &rfds))
         {
           if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
             {
@@ -1151,13 +1349,13 @@
                       p += j;
                       i -= j;
                     }
-                  mask = 1 << ttyfd;
+		  FD_SET(ttyfd, &mask);
                   select (32, 0, &mask, 0, 0);
                 }
               pop_cursor ();
             }
         }
-      if (rfds & tty_bit)
+      if (FD_ISSET(ttyfd, &rfds))
         {
           if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
             {
@@ -1202,12 +1400,12 @@
      int jflg;                  /* jtermio ¤Î j_flg ¤ÎÊÑ´¹¥Õ¥é¥°¤¬¥ª¥Õ¤Î»þ 0 ¥ª¥ó¤Î»þ 1 */
 {
   struct jtermio jbuf1;
-  struct termio frombuf;
-  struct termio tobuf;
+  struct TERMIO frombuf;
+  struct TERMIO tobuf;
   int i;
 
-  ioctl (ptyfd, TCGETA, &frombuf);
-  ioctl (ttyfd, TCGETA, &tobuf);
+  GET_TERMATTR (ptyfd, &frombuf);
+  GET_TERMATTR (ttyfd, &frombuf);
 
   if ((i = (frombuf.c_iflag & IXON)) != (tobuf.c_iflag & IXON))
     {
@@ -1244,7 +1442,7 @@
     }
   tobuf.c_cflag = (tobuf.c_cflag & ~CBAUD) | (frombuf.c_cflag & CBAUD);
 
-  ioctl (ttyfd, TCSETA, &tobuf);        /* set again */
+  SET_TERMATTR (ttyfd, &tobuf);		/* set again */
 
   ioctl (ptyfd, JTERMGET, &jbuf1);      /* about Japanease */
 
@@ -1270,27 +1468,73 @@
 
 /** »Ò¥×¥í¥»¥¹¤òµ¯¤³¤¹¡£*/
 
-int ttypfd;
+int ttypfd = -1;
 
 static void
 exec_cmd (argv)
      char **argv;
 {
   int i;
+#if defined(USE_LIBSPT) && !defined(USE_LINUX_TERM)
+  int r;
+  const char *ttynm;
+#elif !defined(HAVE_SETSID) || defined(USE_LINUX_TERM)
 #ifdef BSD42
   int pid;
 #endif
-#ifdef linux
+#ifdef USE_LINUX_TERM
   struct winsize win;
   extern Term_RowWidth, crow;
 #endif
-#if defined(SYSVR2) && !defined(linux)
-  setpgrp ();
-  close (open (ttyname (ttypfd), O_WRONLY, 0));
+#endif /* (!USE_LIBSPT && !HAVE_SETSID) || USE_LINUX_TERM */
+
+  child_id = fork ();
+  if (child_id < 0)
+    uum_err ("cannot fork.");
+  if (!child_id)
+    {
+      /* --- start changing controlling tty --- */
+#if defined(USE_LIBSPT) && !defined(USE_LINUX_TERM)
+#if defined(SIGWINCH) && defined(TIOCSWINSZ)
+      struct winsize win;
+      if (ioctl (ttyfd, TIOCGWINSZ, &win) == 0)
+	ioctl (ttypfd, TIOCSWINSZ, &win);
+#endif /* SIGWINCH && TIOCSWINSZ */
+      spt_detach_handle (spth);
+      spth = NULL;
+      if (spt_detach_ctty () || spt_set_ctty2 (ttypfd))
+	{
+	  uum_err ("cannot change controlling tty.");
+	}
+
+#elif defined(HAVE_SETSID) && !defined(USE_LINUX_TERM) /* !USE_LIBSPT */
+
+      int fd;
+#if defined(SIGWINCH) && defined(TIOCSWINSZ)
+      struct winsize win;
+      if (ioctl (ttyfd, TIOCGWINSZ, &win) == 0)
+	ioctl (ttypfd, TIOCSWINSZ, &win);
+#endif /* SIGWINCH && TIOCSWINSZ */
+      setsid ();
+#ifdef TIOCSCTTY
+      ioctl (ttypfd, TIOCSCTTY, 0);
+#else
+      close (open (ttyname (ttypfd), O_WRONLY, 0));
+#endif
+      if ((fd = open("/dev/tty", O_WRONLY)) < 0)
+	{
+          uum_err ("cannot change controlling tty.");
+	}
+      close (fd);
+      /* disable utmp logging for now */
+
+#else /* (!USE_LIBSPT && !HAVE_SETSID) || USE_LINUX_TERM */
+
+#if defined(SYSVR2) && !defined(USE_LINUX_TERM)
+      setpgrp ();
+      close (open (ttyname (ttypfd), O_WRONLY, 0));
 #endif /* SYSVR2 */
 
-  if (!(child_id = fork ()))
-    {
 #ifdef BSD42
 #ifdef TIOCNOTTY
       /* set notty */
@@ -1315,25 +1559,25 @@
       setpgrp (0, pid);
 #endif /* BSD42 */
 
-#if !(defined(BSD) && (BSD >= 199306))
-      if (setutmp (ttypfd) == ERROR)
-        {
-          puts ("Can't set utmp.");
-        }
-#endif
-
-#ifdef linux
+#ifdef USE_LINUX_TERM
       setsid ();
       open_ttyp ();
       close (ptyfd);
       ioctl (ttyfd, TIOCGWINSZ, &win);
       ioctl (ttypfd, TCSETA, &savetmio);
+#endif
+#endif /* (!USE_LIBSPT && !HAVE_SETSID) || USE_LINUX_TERM */
+      /* --- finish changing controlling tty --- */
+
+#ifndef USE_LINUX_TERM
+      setgid (getgid ());
+      setuid (getuid ());
+#endif
+#ifdef HAVE_DUP2
       dup2 (ttypfd, 0);
       dup2 (ttypfd, 1);
       dup2 (ttypfd, 2);
-#else /* linux */
-      setgid (getgid ());
-      setuid (getuid ());
+#else /* !HAVE_DUP2 */
       close (0);
       close (1);
       close (2);
@@ -1341,7 +1585,7 @@
         {
           uum_err ("redirection fault.");
         }
-#endif /* linux */
+#endif /* !HAVE_DUP2 */
       for (i = WNN_NFD - 1; i > 2; i--)
         {
           close (i);
@@ -1359,11 +1603,7 @@
       signal (SIGTTOU, SIG_IGN);
 #endif
 
-/*      if (setutmp(0) == ERROR) {
-            err("Can't set utmp.");
-        } 
-*/
-#ifdef linux
+#ifdef USE_LINUX_TERM
       crow = win.ws_row = Term_RowWidth = win.ws_row - conv_lines;
       ioctl (ttyfd, TIOCSWINSZ, &win);
       setgid (getgid ());
@@ -1372,6 +1612,28 @@
       execvp (cmdnm, argv);
       uum_err ("exec fault.");
     }
+  /* parent */
+#ifdef USE_LIBSPT
+  ttynm = ttyname (0);
+  if (ttynm)
+    {
+      ttynm = strchr (ttynm + 1, '/');
+      if (ttynm && ttynm[1])
+	{
+	  spt_utmp_set_host (spth, ttynm + 1);
+	}
+    }
+  spt_utmp_set_pid (spth, child_id);
+  r = spt_login_utmp (spth);
+  if (!r)
+    {
+      need_utmp_clear = 1;
+    }
+  else
+    {
+      spt_perror ("exec_cmd (login_utmp)", r);
+    }
+#endif
 }
 
 #if !(HAVE_SETENV)
@@ -1442,7 +1704,7 @@
   return (0);
 }
 
-static int
+static void
 set_euc_term (ttyfd)
      int ttyfd;
 {
@@ -1460,9 +1722,9 @@
   if (euc_set (&eucioc, ttyfd) != 0)
     {
       fprintf (stderr, "eucwidth set failed\n");
-      return (1);
+      return;
     }
-  return (0);
+  return;
 }
 
 #endif /* SVR4 */
@@ -1483,14 +1745,62 @@
   buf.c_oflag = 0;
   if (ioctl (ttypfd, TCJSETA, &buf) < 0)
     {
-      fprintf (stderr, "error in ioctl TCSETA.\n");
+      fprintf (stderr, "error in ioctl TCJSETA.\n");
       exit (1);
     }
 }
 #endif /* nec_ews_svr2 */
 
+#ifdef sony
+static void
+set_sony_jterm(ttyfd, ttypfd)
+int ttyfd, ttypfd;
+{
+#ifdef TIOCKGET
+  int tmode, jmode = 0;
+  struct jtchars jtc;
+
+  if (ioctl(ttyfd, TIOCKGET, &tmode) < 0) {
+    fprintf(stderr, "error in ioctl TIOCKGET.\n");
+    exit(1);
+  }
+  jmode = tmode;
+  tmode &= ~(KM_SYSCODE | KM_TTYPE);
+  switch (pty_c_flag) {
+  case J_EUJIS:
+    tmode |= KM_EUC | KM_SYSEUC;
+    break;
+  case J_JIS:
+    tmode |= KM_ASCII;
+    break;
+  case J_SJIS:
+    tmode |= KM_SJIS | KM_SYSSJIS;
+    break;
+  }
+  if (ioctl(ttypfd, TIOCKSET, &tmode) < 0) {
+    fprintf(stderr, "error in ioctl TIOCKSET.\n");
+    exit(1);
+  }
+#endif /* TIOCKGET */
+
+#ifdef TIOCKGETC    
+  if ((jmode & KM_TTYPE) == KM_JIS) {
+    ioctl(ttyfd, TIOCKGETC, &jtc);
+    jtc.t_ascii = 'B';
+    jtc.t_kanji = 'B';
+    if (ioctl(ttypfd, TIOCKSETC, &jtc) < 0) {
+      fprintf(stderr, "error in ioctl TIOCKSETC.\n");
+      exit(1);
+    }
+  }
+#endif
+}
+#endif /* sony */
+
 /** ttyp ¤Î¥ª¡¼¥×¥ó */
 
+#ifndef USE_LIBSPT
+#define MAXPTYNO (0x10 * (('z' - 'p' + 1) + ('Z' - 'P' + 1)))
 int ptyno;
 char *ptynm = "/dev/pty";
 #ifdef sgi
@@ -1500,29 +1810,20 @@
 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
+#endif /* !USE_LIBSPT */
 
 static void
 open_ttyp ()
 {
   char nmbuf[20];
-#ifdef BSD42
-  int word;
-#endif
-#if defined(SYSVR2) && !defined(linux)
-  struct termio buf1;
-#endif
-#if defined(uniosu)
-  struct jtermio buf2;
-#endif
 
-#ifdef sgi
+#ifdef USE_LIBSPT
+  if ((ttypfd = spt_open_slave(spth)) == ERROR)
+    {
+#elif defined(sgi)
   if ((ttypfd = open (ttypnm, O_RDWR)) == ERROR)
     {
 #else
@@ -1532,134 +1833,58 @@
 #endif
       uum_err ("Can't open ttyp.");
     }
-#ifndef linux
+#if !defined(USE_LINUX_TERM) && !defined(USE_LIBSPT)
   chown (nmbuf, getuid (), getgid ());
   chmod (nmbuf, 0622);
-#endif /* !linux */
-#ifdef BSD42
-  ioctl (ttyfd, TIOCGETC, &tcharsv);
-  ioctl (ttyfd, TIOCGLTC, &ltcharsv);
-  ioctl (ttyfd, TIOCGETP, &ttyb);
-  savetmio = ttyb;
-#if defined(BSD43) || defined(DGUX)
-  ioctl (ttyfd, TIOCLGET, &local_mode_sv);
-  local_mode = local_mode_sv | LPASS8;  /* set PASS8 */
-  ioctl (ttyfd, TIOCLSET, &local_mode);
-#else /* defined(BSD43) || defined(DGUX) */
-  ioctl (ttyfd, TIOCLGET, &local_mode);
-#endif /* defined(BSD43) || defined(DGUX) */
-
-  ioctl (ttypfd, TIOCSETC, &tcharsv);
-  ioctl (ttypfd, TIOCSLTC, &ltcharsv);
-  ioctl (ttypfd, TIOCSETP, &ttyb);
-  ioctl (ttypfd, TIOCLSET, &local_mode);
-#ifdef notdef
-  pid = getpid ();
-  ioctl (ttypfd, TIOCSPGRP, &pid);
+#endif /* !USE_LINUX_TERM && !USE_LIBSPT */
+#if defined(USE_LIBSPT)
+  spt_init_slavefd(spth, ttypfd);
+#elif defined(I_PUSH) && defined(SVR4)
+  ioctl(ttypfd, I_PUSH, "ptem");
+  ioctl(ttypfd, I_PUSH, "ldterm");
+  ioctl(ttypfd, I_PUSH, "ttcompat");
 #endif
-  if (pty_c_flag == J_JIS)
-    {
-      word = LCTLECH;
-      ioctl (ttypfd, TIOCLBIC, &word);
-    }
-#endif /* BSD42 */
-#if defined(SYSVR2) && !defined(linux)
-  if (ioctl (ttyfd, TCGETA, &buf1) == -1)
-    {
-      buf1 = terms;
-    }
-  savetmio = buf1;
-#ifdef DGUX                     /* copied from JLS5.4.2 */
-  buf1.c_iflag &= ~ISTRIP;
-#endif /* DGUX */
-#ifdef nec_ews_svr2
-  buf1.c_line = JAPANLD;
+	
+  /*
+   * We save terminal settings in main() instead of here.
+   * When USE_LINUX_TERM open_ttyp() is invoked from child!
+   */
+#ifndef USE_LINUX_TERM
+  j_term_p_init (ttypfd);
 #endif
-  if (ioctl (ttypfd, TCSETA, &buf1) < 0)
-    {
-      fprintf (stderr, "error in ioctl TCSETA.\n");
-      exit (1);
-    }
-#if defined(uniosu)
-  if (ioctl (ttyfd, JTERMGET, &buf2) < 0)
-    {
-      fprintf (stderr, "uum: error in ioctl JTERMGET in open_ttyp.\n");
-      exit (1);
-    }
-  savejtmiottyp = buf2;
-  buf2.j_flg = CONVTOEXT | KANJIINPUT;  /* kanji input & output ok */
-  buf2.j_level = jterm;
-  switch (jcode_set)
-    {
-    case 0:
-      buf2.j_ecode = JIS;
-      break;
-    case 1:
-      buf2.j_ecode = SJIS;
-      break;
-    case 2:
-      buf2.j_ecode = UJIS;
-      break;
-    default:
-      fprintf (stderr, "uum: kanji code set not supported in terminfo.\n");
-      exit (1);
-    }
 
-  if (jis_kanji_in)
-    {
-      strcpy (buf2.j_jst, jis_kanji_in);
-      buf2.j_jstl = strlen (jis_kanji_in);
-    }
-  if (jis_kanji_out)
-    {
-      strcpy (buf2.j_jend, jis_kanji_out);
-      buf2.j_jendl = strlen (jis_kanji_out);
-    }
-  if (jgaiji_start_address)
-    {
-      *(short *) buf2.j_gcsa = jgaiji_start_address;
-    }
-  if (jgaiji_disp)
-    {
-      strcpy (buf2.j_gdsp, jgaiji_disp);
-      buf2.j_gdspl = strlen (jgaiji_disp);
-    }
-
-  if (ioctl (ttypfd, JTERMSET, &buf2) < 0)
-    {
-      fprintf (stderr, "error in ioctl JTERMSET.\n");
-      exit (1);
-    }
-
-  if (ioctl (ttypfd, TIOCSETAUX, &auxterm) < 0)
-    {
-      fprintf (stderr, "error in ioctl TIOCSETAUX.\n");
-      exit (1);
-    }
+#ifdef TIOCSSIZE
+    pty_rowcol.ts_lines = crow; /* instead of lines */
+    pty_rowcol.ts_cols = maxlength; /* instead of columns */
+    ioctl(ttypfd, TIOCSSIZE, &pty_rowcol);
+#endif /* TIOCSSIZE */
 
-/*
-    pid = getpid();
-*/
-#endif /* defined(uniosu) */
+#ifdef SVR4
+  set_euc_term(ttypfd);
+#endif
 
 #if defined(nec_ews_svr2)
   set_jterm (ttyfd, ttypfd);
 #endif
 
-/*
-    setpgrp();
-    close(open(ttyname(ttypfd), O_WRONLY, 0));
-*/
-#endif /* defined(SYSVR2) && !defined(linux) */
-#ifdef TIOCSSIZE
-  pty_rowcol.ts_lines = crow;   /* instead of lines */
-  pty_rowcol.ts_cols = maxlength;       /* instead of columns */
-  ioctl (ttypfd, TIOCSSIZE, &pty_rowcol);
-#endif /* TIOCSSIZE */
+#ifdef sony
+  set_sony_jterm(ttyfd, ttypfd);
+#endif
+
 }
 
 /** pty ¤Î¥ª¡¼¥×¥ó */
-#ifdef sgi
+#if defined(USE_LIBSPT)
+static void
+open_pty ()
+{
+  int r;
+  r = spt_open_pty(&spth, &ptyfd, NULL, NULL);
+  if (r != SPT_E_NONE && r != SPT_E_CHOWN_FAIL)
+    uum_err ("Can't get pty.");
+  return;
+}
+#elif defined(sgi)
 static void
 open_pty ()
 {
@@ -1677,11 +1902,8 @@
 open_pty ()
 {
   char nmbuf[20];
-#ifdef linux
-  struct termio buf1;
-#endif
 
-  for (ptyno = 0; ptyno < 32; ptyno++)
+  for (ptyno = 0; ptyno < MAXPTYNO; ptyno++)
     {
       ptyname (nmbuf, ptynm, ptyno);
       if ((ptyfd = open (nmbuf, O_RDWR, 0)) != ERROR)
@@ -1693,14 +1915,7 @@
               exit (1);
             }
 #endif
-#ifdef linux
-          if (ioctl (0, TCGETA, &buf1) == -1)
-            {
-              buf1 = terms;
-            }
-          savetmio = buf1;
-#endif
-          return;
+	  return;
         }
     }
   uum_err ("Can't get pty.");
@@ -1723,7 +1938,11 @@
 static void
 do_end ()
 {
+#ifdef USE_LIBSPT
+  int r;
+#else
   char nmbuf[20];
+#endif
 
   static int do_end_flg = 0;
   if (do_end_flg == 1)
@@ -1733,30 +1952,9 @@
   signal (SIGCHLD, SIG_DFL);
   fcntl (ttyfd, F_SETFL, 0);
 
-#ifdef BSD42
-  ioctl (ttyfd, TIOCSETP, &savetmio);
-#endif /* BSD42 */
-#if defined(BSD43) || defined(DGUX)
-  ioctl (ttyfd, TIOCLSET, &local_mode_sv);
-#endif /* BSD43 */
-
-#ifdef SYSVR2
-  if (ioctl (ttyfd, TCSETA, &savetmio) < 0)
-    {
-      fprintf (stderr, "error in ioctl TCSETA.\n");
-      exit (1);
-    }
-#endif /* SYSVR2 */
-
-#if defined(uniosu)
-  if (ioctl (ttyfd, JTERMSET, &savejtmio) < 0)
-    {
-      fprintf (stderr, "error in ioctl JTERMSET.\n");
-      exit (1);
-    }
-#endif /* defined(uniosu) */
+  j_term_restore ();
 
-#ifndef sgi
+#if !defined(USE_LIBSPT) && !defined(sgi)
   ptyname (nmbuf, ptynm, ptyno);
   if (chown (nmbuf, 0, 0) == ERROR)
     {
@@ -1777,33 +1975,20 @@
       perror (prog);
     }
 
-#if !(defined(BSD) && (BSD >= 199306))
-  if (resetutmp (ttypfd) == ERROR)
-    {
-      printf ("Can't reset utmp.");
-    }
-#endif
-#ifdef TIOCSSIZE
-  pty_rowcol.ts_lines = 0;
-  pty_rowcol.ts_cols = 0;
-  ioctl (ttypfd, TIOCSSIZE, &pty_rowcol);
-#endif /* TIOCSSIZE */
-#endif /* !sgi */
+#endif /* !USE_LIBSPT && !sgi */
   close (ttyfd);
+#ifdef USE_LIBSPT
+  if (spth && need_utmp_clear && (r = spt_logout_utmp(spth)))
+    spt_perror(NULL, r);
+  if (spth && (r = spt_close_pty(spth)))
+    spt_perror(NULL, r);
+#else
   close (ptyfd);
+#endif
 
   chdir ("/tmp");               /* to avoid making too many mon.out files */
 
-
-#ifdef BSD42
-  killpg (child_id, SIGHUP);
-/*    killpg(getpgrp(),SIGHUP);  */
-#endif
-#ifdef SYSVR2
-/*    kill(0, SIGHUP); */
-  kill (-child_id, SIGHUP);
-#endif /* SYSVR2 */
-
+  KILLPG (child_id, SIGHUP);
   exit (0);
 }
 
@@ -1814,7 +1999,7 @@
 {
   static unsigned char buf[BUFSIZ];
   int n;
-  int rfds;
+  fd_set rfds;
 
   kk_restore_cursor ();
   clr_line_all ();
@@ -1828,7 +2013,7 @@
         }
       rfds = sel_ptn;
       select (20, &rfds, 0, 0, NULL);
-      if (rfds & pty_bit)
+      if (FD_ISSET(ptyfd, &rfds))
         {
           if ((n = read (ptyfd, buf, BUFSIZ)) <= 0)
             {
@@ -1847,7 +2032,7 @@
                 }
             }
         }
-      if (rfds & tty_bit)
+      if (FD_ISSET(ttyfd, &rfds))
         {
           if ((n = read (ttyfd, buf, BUFSIZ)) > 0)
             {
@@ -1859,11 +2044,10 @@
 #endif /* defined(uniosu) */
 
 
-#ifndef sgi
+#if !defined(USE_LIBSPT) && !defined(sgi)
 static void
 ptyname (b, pty, no)
      char *b, *pty;
-     int no;
 {
 /*
  * Change pseudo-devices.
@@ -1871,23 +2055,21 @@
  * 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));
+  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);
+  if (no < 0x10 * ('z' - 'p' + 1))
+    {
+      sprintf(b, "%s%1c%1x", pty, 'p' + (no >> 4), no & 0x0f);
+    }
+  else
+    {
+      no -= 0x10 * ('z' - 'p' + 1);
+      sprintf(b, "%s%1c%1x", pty, 'P' + (no >> 4), no & 0x0f);
+    }
 #endif /* ! 4.4BSD-Lite */
 }
-#endif /* !sgi */
-
-/* Move to etc/xutoj.c
-int
-through(x, y, z)
-char *x, *y;
-int z;
-{
-    bcopy(y, x, z);
-    return z;
-}
-*/
+#endif /* !USE_LIBSPT && !sgi */
 
 static void
 default_usage ()
@@ -1917,8 +2099,7 @@
 save_signals ()
 {
   sigpipe = signal (SIGPIPE, SIG_IGN);
-/*     sighup  = signal(SIGHUP,  SIG_IGN); /88/12/27*/
-#ifdef linux                    /* XXX */
+#ifdef USE_LINUX_TERM			    /* XXX */
   sighup = signal (SIGHUP, SIG_IGN);
 #endif
   sighup = signal (SIGHUP, terminate_handler);
@@ -1955,6 +2136,7 @@
 #endif /* SIGTSTP */
 }
 
+/* should be "defined(SIGWINCH)"? */
 #if defined(BSD43) || defined(DGUX)
 static void
 setsize ()
@@ -2003,7 +2185,7 @@
       if ((i = win.ws_row) != 0)
         {
           crow = Term_RowWidth = i - conv_lines;
-#ifdef linux
+#ifdef TIOCSWINSZ
           win.ws_row = crow;
 #endif
         }
@@ -2011,9 +2193,9 @@
         {
           maxlength = Term_LineWidth = i;
         }
-#ifdef linux
+#ifdef TIOCSWINSZ
       ioctl (ttypfd, TIOCSWINSZ, &win);
-#else /* linux */
+#else /* !TIOCSWINSZ */
 #ifdef  TIOCSSIZE
       pty_rowcol.ts_lines = crow;       /* instead of lines */
       pty_rowcol.ts_cols = maxlength;   /* instead of columns */
@@ -2023,14 +2205,10 @@
       {
         int grp;
         ioctl (ptyfd, TIOCGPGRP, &grp);
-#ifdef SVR4
-        kill (-grp, SIGWINCH);
-#else
-        killpg (grp, SIGWINCH);
-#endif
+	KILLPG (grp, SIGWINCH);
       }
 #endif /* sun */
-#endif /* linux */
+#endif /* !TIOCSWINSZ */
 
       set_scroll_region (0, crow - 1);
       if (henkan_off_flag)
@@ -2055,3 +2233,7 @@
     }
 }
 #endif /* SIGWINCH */
+/*
+ * vim: set cinoptions={.5s,\:.5s,+.5s,t0,g0,^-2,e-2,n-2,p.5s,(0,=.5s:
+ * vim: set formatoptions=mMcroql cindent shiftwidth=4:
+ */
Index: Wnn/uum/printf.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/printf.c,v
retrieving revision 1.3
diff -u -r1.3 printf.c
--- Wnn/uum/printf.c	14 Jun 2001 18:16:07 -0000	1.3
+++ Wnn/uum/printf.c	26 Apr 2004 03:24:51 -0000
@@ -33,7 +33,6 @@
 #include "commonhd.h"
 #include "sdefine.h"
 #include "sheader.h"
-#include "jllib.h"
 
 extern int cursor_colum;
 
Index: Wnn/uum/sheader.h
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/sheader.h,v
retrieving revision 1.13
diff -u -r1.13 sheader.h
--- Wnn/uum/sheader.h	11 May 2003 18:29:24 -0000	1.13
+++ Wnn/uum/sheader.h	26 Apr 2004 03:24:51 -0000
@@ -209,9 +209,6 @@
 extern void FPRINTF ();
 extern void PRINTF ();
 
-/* ttyfdslot.c */
-extern int  ttyfdslot (int fd);
-
 /* to be classified */
 extern void b_s_off_raw (void);
 extern void b_s_on_raw (void);
@@ -310,11 +307,9 @@
 extern int ren_henkan0 ();
 extern void reset_bold ();
 extern void reset_cursor_status ();
-extern int resetutmp ();
 extern void restore_cursor_raw ();
 extern void ring_bell ();
 extern void save_cursor_raw ();
-extern int saveutmp ();
 extern void scroll_up ();
 extern int select_jikouho1 ();
 extern int select_line_element ();
@@ -330,7 +325,6 @@
 extern void set_keypad_on ();
 extern void set_keypad_off ();
 extern void set_scroll_region ();
-extern int setutmp ();
 extern int st_colum ();
 extern void t_cont_line_note_delete ();
 extern int t_delete_char ();
Index: Wnn/uum/termcap.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/termcap.c,v
retrieving revision 1.6
diff -u -r1.6 termcap.c
--- Wnn/uum/termcap.c	13 Jun 2002 21:27:47 -0000	1.6
+++ Wnn/uum/termcap.c	26 Apr 2004 03:24:51 -0000
@@ -47,17 +47,9 @@
 #endif /* STDC_HEADERS */
 #include <sys/errno.h>
 #include <sys/ioctl.h>
-#if HAVE_CURSES_H
-#  include <curses.h>
-#elif HAVE_NCURSES_H
-#  include <ncurses.h>
-#endif /* HAVE_CURSES_H */
-#if HAVE_TERM_H
-#  include <term.h>
-#endif
 
 #include "commonhd.h"
-
+#include "wnn_os.h"
 #include "sdefine.h"
 #include "sheader.h"
 
@@ -371,6 +363,14 @@
                   params[i] += nextch;
                 }
               break;
+            case 'p': /* our terminal library is terminfo in fact */
+	      /* skip this */
+              if (!(nextch = *++pt))
+                {
+                  fprintf (stderr, "Unexpected EOL in cs string.\n");
+                  return NULL;
+                }
+              break;
             case 'r':
               {
                 int temp;
Index: Wnn/uum/termio.c
===================================================================
RCS file: /cvs/freewnn/FreeWnn/Wnn/uum/termio.c,v
retrieving revision 1.4
diff -u -r1.4 termio.c
--- Wnn/uum/termio.c	13 Jun 2002 21:27:47 -0000	1.4
+++ Wnn/uum/termio.c	26 Apr 2004 03:24:51 -0000
@@ -40,11 +40,10 @@
 #include "commonhd.h"
 #include "sdefine.h"
 #include "sheader.h"
+#include "wnn_os.h"
 
 #ifdef TERMINFO
 #include <stdio.h>
-#include <curses.h>
-#include <term.h>
 #ifdef putchar
 #undef putchar
 #endif
@@ -69,7 +68,6 @@
   int status;
   int k;
   char lcode[10];
-  char termchar[20];
   char errprefix[1024] = "error";
 
   /* for convert_key --- added by Nide 10/3 */
@@ -86,16 +84,9 @@
     }
   strcpy (Term_Name, cp);
 
-  if ((strlen (Term_Name) > 2) && (strcmp (Term_Name + (strlen (Term_Name) - 2), "-j") == 0))
-    {
-      fprintf (stderr, MSG_GET (4));
-      /*
-         fprintf(stderr,"Uum:£õ£õ£í¤«¤é£õ£õ£í¤Ï¤ª¤³¤»¤Þ¤»¤ó¡£\n");
-       */
-      return (-1);
-    }
   setupterm (0, 1, &status);
-  reset_shell_mode ();
+  /* This seems needless and causes hangs on Solaris8 + ncurses */
+  /* reset_shell_mode (); */
   if (status != 1)
     {
       return (-1);
@@ -112,18 +103,6 @@
       fprintf (stderr, "Your terminal is not strong enough. Goodbye !\n");
       return (-1);
     }
-  termchar[0] = 0;
-  strcat (termchar, cp);
-  strcat (termchar, "-j");
-  if (setenv ("TERM", termchar, 1) != 0)
-    {
-#if HAVE_SNPRINTF
-      snprintf (errprefix, sizeof (errprefix),
-		"error at %s (%d)", __FILE__, __LINE__); 
-#endif /* HAVE_SNPRINTF */
-      perror (errprefix);
-      exit (1);
-    }
 
   sprintf (lcode, "%d", lines - conv_lines);
   if (setenv ("LINES", lcode, 1) != 0)
@@ -190,7 +169,8 @@
 set_scroll_region (start, end)
      int start, end;
 {
-  tputs (tparm (change_scroll_region, start, end), 1, putchar);
+  tputs (tparm (change_scroll_region, start, end, 4, 5, 6, 7, 8, 9, 10),
+	  1, putchar);
 }
 
 void
@@ -218,7 +198,7 @@
 throw_cur_raw (col, row)
      int col, row;
 {
-  tputs (tparm (cursor_address, row, col), 1, putchar);
+  tputs (tparm (cursor_address, row, col, 4, 5, 6, 7, 8, 9, 10), 1, putchar);
 }
 
 void
Index: cWnn/uum/Makefile.in
===================================================================
RCS file: /cvs/freewnn/FreeWnn/cWnn/uum/Makefile.in,v
retrieving revision 1.9
diff -u -r1.9 Makefile.in
--- cWnn/uum/Makefile.in	14 Aug 2001 13:43:22 -0000	1.9
+++ cWnn/uum/Makefile.in	26 Apr 2004 03:24:52 -0000
@@ -35,15 +35,15 @@
 INSTALL      = @INSTALL@
 
        UUMOWNER = root
-       INCLUDES = -I$(CWNNINCLUDESRC) -I$(CWNNROMKANSRC) -I$(TOP)
-        DEFINES = $(CWNNDEFINES) $(CWNNLANGDEF)
-LOCAL_INSTFLAGS = $(INSTUIDFLAGS) -o $(UUMOWNER)
+       INCLUDES = -I$(CWNNINCLUDESRC) -I$(CWNNROMKANSRC) -I$(TOP) `libspt-config --cflags`
+        DEFINES = $(CWNNDEFINES) $(CWNNLANGDEF) -DUSE_LIBSPT
+LOCAL_INSTFLAGS = -o $(UUMOWNER)
 LOCAL_LIBRARIES = $(CWNNJLIB) $(CWNNCONVLIB)
 
 HDRS= buffer.h cvtcode.h sdefine.h sheader.h
-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
+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       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
 
-OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       ttyfdslot.o setutmp.o redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
+OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
 
 SRC2= $(CWNNETCSRC)/bcopy.c
 OBJ2= bcopy.o
@@ -62,7 +62,7 @@
 
 cuum: $(OBJS) $(LOCAL_LIBRARIES)
 	$(RM) $@
-	$(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB)
+	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB) `libspt-config --libs` @LIBS@
 
 clean::
 	$(RM) cuum
@@ -426,7 +426,7 @@
 install:: cuum
 	@if [ -d $(DESTDIR)$(CWNNBINDIR) ]; then set +x; \
 	else (set -x; $(MKDIRHIER) $(DESTDIR)$(CWNNBINDIR)); fi
-	$(INSTALL) $(INSTALLFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) cuum $(DESTDIR)$(CWNNBINDIR)/cuum
+	$(LIBTOOL) $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) cuum $(DESTDIR)$(CWNNBINDIR)/cuum
 
 $(OBJ2) : $(SRC2)
 	$(CC) -c $(CFLAGS)  $(CWNNETCSRC)/`basename $@ .o`.c
Index: kWnn/uum/Makefile.in
===================================================================
RCS file: /cvs/freewnn/FreeWnn/kWnn/uum/Makefile.in,v
retrieving revision 1.9
diff -u -r1.9 Makefile.in
--- kWnn/uum/Makefile.in	14 Aug 2001 13:43:23 -0000	1.9
+++ kWnn/uum/Makefile.in	26 Apr 2004 03:24:52 -0000
@@ -35,15 +35,15 @@
 INSTALL      = @INSTALL@
 
        UUMOWNER = root
-       INCLUDES = -I$(KWNNINCLUDESRC) -I$(KWNNROMKANSRC) -I$(TOP)
-        DEFINES = $(KWNNDEFINES) $(KWNNLANGDEF)
-LOCAL_INSTFLAGS = $(INSTUIDFLAGS) -o $(UUMOWNER)
+       INCLUDES = -I$(KWNNINCLUDESRC) -I$(KWNNROMKANSRC) -I$(TOP) `libspt-config --cflags`
+        DEFINES = $(KWNNDEFINES) $(KWNNLANGDEF) -DUSE_LIBSPT
+LOCAL_INSTFLAGS = -o $(UUMOWNER)
 LOCAL_LIBRARIES = $(KWNNJLIB) $(KWNNCONVLIB)
 
 HDRS= buffer.h cvtcode.h sdefine.h sheader.h
-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
+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       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
 
-OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       ttyfdslot.o setutmp.o redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
+OBJ1= epilogue.o header.o kensaku.o kuten.o jis_in.o       prologue.o touroku.o jikouho.o jutil.o w_string.o       printf.o termio.o hinsi.o termcap.o       redraw.o history.o key_bind.o       screen.o basic_op.o uif.o cursor.o jhlp.o       select_ele.o inspect.o wnnrc_op.o functions.o
 
 SRC2= $(KWNNETCSRC)/bcopy.c
 OBJ2= bcopy.o
@@ -62,7 +62,7 @@
 
 kuum: $(OBJS) $(LOCAL_LIBRARIES)
 	$(RM) $@
-	$(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB)
+	$(LIBTOOL) $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBRARIES) $(WNNTERM_LIB) `libspt-config --libs` @LIBS@
 
 clean::
 	$(RM) kuum
@@ -426,7 +426,7 @@
 install:: kuum
 	@if [ -d $(DESTDIR)$(KWNNBINDIR) ]; then set +x; \
 	else (set -x; $(MKDIRHIER) $(DESTDIR)$(KWNNBINDIR)); fi
-	$(INSTALL) $(INSTALLFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) kuum $(DESTDIR)$(KWNNBINDIR)/kuum
+	$(LIBTOOL) $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) $(INSTPGMFLAGS) $(LOCAL_INSTFLAGS) kuum $(DESTDIR)$(KWNNBINDIR)/kuum
 
 $(OBJ2) : $(SRC2)
 	$(CC) -c $(CFLAGS)  $(KWNNETCSRC)/`basename $@ .o`.c
