Index: configure.in
===================================================================
RCS file: /cvsroot/mlterm/mlterm/configure.in,v
retrieving revision 1.37
diff -u -r1.37 configure.in
--- configure.in	4 Oct 2003 10:59:11 -0000	1.37
+++ configure.in	11 Oct 2003 15:34:15 -0000
@@ -149,16 +149,29 @@
 AC_SUBST(IND_LIBS)
 AC_SUBST(IND_CFLAGS)
 
+AC_ARG_ENABLE(libspt,
+	[  --enable-libspt         libspt[disabled]],
+	libspt=$enable_libspt
+	LIBSPT_CFLAGS="`libspt-config --cflags` -DUSE_LIBSPT"
+	LIBSPT_LIBS="`libspt-config --libs`"
+	)
+AC_SUBST(LIBSPT_CFLAGS)
+AC_SUBST(LIBSPT_LIBS)
+
 AC_ARG_ENABLE(utmp,
 	[  --enable-utmp           utmp[default=disabled]],
 	utmp=$enable_utmp)
 if test "$utmp" = "yes" ; then
 	UTMP_CFLAGS="-DUSE_UTMP"
 	has_utmp=`grep utmp /etc/group 2>/dev/null`
-	if test "$has_utmp" ; then
-		INSTALL_OPT="-m 2755 -g utmp"
-	else
-		INSTALL_OPT="-m 4755 -o root"
+	if test "$libspt" = "yes" ; then
+		INSTALL_OPT="-m 755"
+ 	else
+		if test "$has_utmp" ; then
+			INSTALL_OPT="-m 2755 -g utmp"
+		else
+			INSTALL_OPT="-m 4755 -o root"
+		fi
 	fi
 else
 	INSTALL_OPT="-m 755"
Index: mlterm/Makefile.in
===================================================================
RCS file: /cvsroot/mlterm/mlterm/mlterm/Makefile.in,v
retrieving revision 1.15
diff -u -r1.15 Makefile.in
--- mlterm/Makefile.in	9 Aug 2003 15:31:49 -0000	1.15
+++ mlterm/Makefile.in	11 Oct 2003 15:34:16 -0000
@@ -17,7 +17,7 @@
 VPATH = $(top_srcdir)/mlterm
 
 CFLAGS = $(CFLAGS_LOCAL) @DEB_CFLAGS@ @KIK_CFLAGS@ @MKF_CFLAGS@ @FRIBIDI_CFLAGS@ @IND_CFLAGS@ \
-	@UTMP_CFLAGS@ @CFLAGS@ @CPPFLAGS@ -I/usr/local/include -DLIBEXECDIR=\"$(LIBEXECDIR)\"
+	@UTMP_CFLAGS@ @CFLAGS@ @LIBSPT_CFLAGS@ @CPPFLAGS@ -I/usr/local/include -DLIBEXECDIR=\"$(LIBEXECDIR)\"
 LIBS = $(LIBS_LOCAL)
 
 OBJ = ml_bidi.o ml_char.o ml_char_encoding.o ml_color.o ml_edit.o ml_edit_util.o ml_edit_scroll.o \
Index: mlterm/ml_pty.c
===================================================================
RCS file: /cvsroot/mlterm/mlterm/mlterm/ml_pty.c,v
retrieving revision 1.6
diff -u -r1.6 ml_pty.c
--- mlterm/ml_pty.c	16 May 2003 10:08:38 -0000	1.6
+++ mlterm/ml_pty.c	11 Oct 2003 15:34:16 -0000
@@ -15,6 +15,11 @@
 #include  <kiklib/kik_str.h>	/* strdup */
 #include  <kiklib/kik_pty.h>
 
+#ifdef USE_LIBSPT
+# include <libspt.h>
+# include <fcntl.h>
+#endif
+
 
 #if  0
 #define  __DEBUG
@@ -35,18 +40,57 @@
 {
 	ml_pty_t *  pty ;
 	pid_t  pid ;
+#ifdef	USE_LIBSPT
+	int r;
+#endif
 
 	if( ( pty = malloc( sizeof( ml_pty_t))) == NULL)
 	{
 		return  NULL ;
 	}
 	
+#ifdef	USE_LIBSPT
+	/* don't move them into kiklib because of the semantical difference */
+	if( spt_fork_pty( &pty->spth , &pty->master , &pty->slave , &pid ,
+#ifdef	USE_UTMP
+				host
+#else
+				NULL
+#endif
+				))
+	{
+		free( pty);
+		return NULL ;
+	}
+	if( pid == 0)
+	{
+		pty->spth = NULL; /* just in case */
+		dup2( pty->slave , 0);
+		dup2( pty->slave , 1);
+		dup2( pty->slave , 2);
+		if( pty->slave > STDERR_FILENO)
+		{
+			close( pty->slave);
+		}
+	}
+	else
+	{
+		if( spt_get_slavename(pty->spth, &pty->slave_name))
+		{
+			spt_close_pty(pty->spth);
+			free( pty);
+			return NULL ;
+		}
+		fcntl( pty->master, F_SETFL, O_NDELAY);
+	}
+#else	/* !USE_LIBSPT */
 	pid = kik_pty_fork( &pty->master , &pty->slave , &pty->slave_name) ;
 
 	if( pid == -1)
 	{
 		return  NULL ;
 	}
+#endif	/* !USE_LIBSPT */
 
 	if( pid == 0)
 	{
@@ -106,6 +150,7 @@
 
 	/* parent process */
 
+#ifndef	USE_LIBSPT
 #ifdef  USE_UTMP
 	if( ( pty->utmp = kik_utmp_new( pty->slave_name , host , pty->master)) == NULL)
 	{
@@ -114,6 +159,7 @@
 	#endif
 	}
 #endif
+#endif	/* !USE_LIBSPT */
 
 	pty->child_pid = pid ;
 	pty->buf = NULL ;
@@ -135,19 +181,31 @@
 	)
 {
 #ifdef  USE_UTMP
+#ifdef	USE_LIBSPT
+	spt_logout_utmp( pty->spth);
+#else
 	if( pty->utmp)
 	{
 		kik_utmp_delete( pty->utmp) ;
 	}
 #endif
+#endif
 
 #ifdef  __DEBUG
 	kik_debug_printf( "%d fd is closed\n" , pty->master) ;
 #endif
 
+#ifdef USE_LIBSPT
+	spt_close_pty( pty->spth);
+#else
 	close( pty->master) ;
+#endif
 	close( pty->slave) ;
+#ifdef USE_LIBSPT
+	spt_free_obj( pty->slave_name) ;
+#else
 	free( pty->slave_name) ;
+#endif
 		
 	free( pty) ;
 
Index: mlterm/ml_pty.h
===================================================================
RCS file: /cvsroot/mlterm/mlterm/mlterm/ml_pty.h,v
retrieving revision 1.3
diff -u -r1.3 ml_pty.h
--- mlterm/ml_pty.h	11 Feb 2003 03:34:00 -0000	1.3
+++ mlterm/ml_pty.h	11 Oct 2003 15:34:16 -0000
@@ -7,10 +7,13 @@
 
 
 #include  <kiklib/kik_types.h>		/* u_int/u_char/uid_t/gid_t */
-
+#ifdef	USE_LIBSPT
+struct spt_handle_tag;
+#else	/* !USE_LIBSPT */
 #ifdef  USE_UTMP
 #include  <kiklib/kik_utmp.h>
 #endif
+#endif	/* !USE_LIBSPT */
 
 
 typedef struct  ml_pty
@@ -20,9 +23,13 @@
 	char *  slave_name ;
 	pid_t  child_pid ;
 
+#ifdef	USE_LIBSPT
+	struct spt_handle_tag *spth;
+#else	/* !USE_LIBSPT */
 #ifdef  USE_UTMP
 	kik_utmp_t  utmp ;
 #endif
+#endif	/* !USE_LIBSPT */
 
 	/* model to be written */
 	u_char *  buf ;
Index: xwindow/Makefile.in
===================================================================
RCS file: /cvsroot/mlterm/mlterm/xwindow/Makefile.in,v
retrieving revision 1.23
diff -u -r1.23 Makefile.in
--- xwindow/Makefile.in	13 Sep 2003 09:47:35 -0000	1.23
+++ xwindow/Makefile.in	11 Oct 2003 15:34:16 -0000
@@ -35,13 +35,13 @@
 LMKF_DEB = -lmkf_deb
 
 CFLAGS=$(CFLAGS_LOCAL) @AA_CFLAGS@ @KIK_CFLAGS@ @MKF_CFLAGS@ @DEB_CFLAGS@ @FRIBIDI_CFLAGS@ @IND_CFLAGS@ \
-       @IMAGELIB_CFLAGS@ @XUTF8_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
+       @IMAGELIB_CFLAGS@ @XUTF8_CFLAGS@ @CFLAGS@ @LIBSPT_CFLAGS@ @CPPFLAGS@ \
 	-DLIBDIR=\"$(LIBDIR)\" -DSYSCONFDIR=\"$(SYSCONFDIR)\" \
 	-DLIBEXECDIR=\"$(LIBEXECDIR)\" -DDATADIR=\"$(DATADIR)\"\
 	-I$(top_srcdir)/mlterm -I${top_builddir}/xwindow -I/usr/X11R6/include -I/usr/local/include
 
 LIBS=$(LIBS_LOCAL) @IND_LIBS@ @FRIBIDI_LIBS@ @IMAGELIB_LIBS@ @AA_LIBS@ @X_EXTRA_LIBS@ @DL_LIBS@ \
-	-lX11 $(LMLTERM) $(LMKF) $(LKIK) \
+	-lX11 @LIBSPT_LIBS@ $(LMLTERM) $(LMKF) $(LKIK) \
 	-L/usr/X11R6/lib -L/usr/local/lib -R/usr/X11R6/lib -R/usr/local/lib
 
 PROG = mlterm
Index: xwindow/x_term_manager.c
===================================================================
RCS file: /cvsroot/mlterm/mlterm/xwindow/x_term_manager.c,v
retrieving revision 1.71
diff -u -r1.71 x_term_manager.c
--- xwindow/x_term_manager.c	15 Sep 2003 13:49:14 -0000	1.71
+++ xwindow/x_term_manager.c	11 Oct 2003 15:34:16 -0000
@@ -2726,6 +2726,7 @@
 				unlink( un_file) ;
 			}
 			
+			ml_term_manager_final ();
 			exit( 0) ;
 		}
 
