? pty.m
Index: GNUmakefile
===================================================================
RCS file: /cvsroot/backbone/System/Applications/Terminal/GNUmakefile,v
retrieving revision 1.70
diff -u -r1.70 GNUmakefile
--- GNUmakefile	9 Nov 2004 22:30:32 -0000	1.70
+++ GNUmakefile	18 May 2005 04:42:13 -0000
@@ -25,7 +25,6 @@
 
 Terminal_OBJC_FILES = \
 	main.m \
-	\
 	Services.m \
 	ServicesPrefs.m \
 	ServicesParameterWindowController.m \
@@ -44,7 +43,7 @@
 	\
 	Label.m
 
-Terminal_LDFLAGS = -lutil
+Terminal_LDFLAGS =  -liconv
 
 Terminal_LOCALIZED_RESOURCE_FILES = Localizable.strings
 Terminal_LANGUAGES = English Swedish German French Spanish Hungarian Turkish \
Index: TerminalView.m
===================================================================
RCS file: /cvsroot/backbone/System/Applications/Terminal/TerminalView.m,v
retrieving revision 1.69
diff -u -r1.69 TerminalView.m
--- TerminalView.m	21 Jul 2004 01:12:17 -0000	1.69
+++ TerminalView.m	18 May 2005 04:42:16 -0000
@@ -12,19 +12,20 @@
 stupid but fast character cell display view.
 */
 
+#include <sys/types.h>
+
 #include <math.h>
 #include <unistd.h>
 
-#ifdef __NetBSD__
-#  include <sys/types.h>
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__sun)
 #  include <sys/ioctl.h>
 #  include <termios.h>
+#endif
+
+#ifdef __NetBSD__
 #  include <pcap.h>
 #else
 #ifdef freebsd
-#  include <sys/types.h>
-#  include <sys/ioctl.h>
-#  include <termios.h>
 #  include <libutil.h>
 #  include <pcap.h>
 #else
@@ -33,14 +34,12 @@
 #endif
 
 #include <sys/time.h>
-#include <sys/types.h>
 #include <unistd.h>
 #include <fcntl.h>
-#ifndef freebsd
-#ifndef __NetBSD__
+
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__sun)
 #  include <pty.h>
 #endif
-#endif
 
 #include <Foundation/NSBundle.h>
 #include <Foundation/NSDebug.h>
@@ -62,6 +61,14 @@
 
 #include "TerminalViewPrefs.h"
 
+#ifdef __sun
+/* These have to go after the objc runtime because 'STR' is #defined in
+   <sys/stropts.h> and used as a type name in the runtime. */
+#  include <sys/stat.h>
+#  include <sys/stropts.h>
+
+pid_t forkpty(int *amaster, char *name, struct termios *term, struct winsize *winp);
+#endif
 
 /* TODO */
 @interface NSView (unlockfocus)
@@ -1756,7 +1763,11 @@
 
 		if (cdirectory)
 			chdir(cdirectory);
+#ifndef __sun
 		putenv("TERM=linux");
+#else
+		putenv("TERM=xtermc");
+#endif
 		putenv("TERM_PROGRAM=GNUstep_Terminal");
 		execv(cpath,(char *const*)cargs);
 		fprintf(stderr,"Unable to spawn process '%s': %m!",cpath);
@@ -2166,3 +2177,87 @@
 
 @end
 
+#ifdef __sun
+/*	$NetBSD: pty.c,v 1.27 2004/11/25 02:49:46 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+pid_t
+forkpty(int *amaster, char *name, struct termios *term, struct winsize *winp)
+{
+	int master, slave, fd;
+	pid_t pid;
+	char *slavename;
+
+	if ((master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1)
+		return -1;
+
+	grantpt(master);
+	unlockpt(master);
+
+	switch (pid = fork()) {
+	case -1:
+		return -1;
+	case 0:
+		/*
+		 * child
+		 */
+		slavename = ptsname(master);
+		(void)close(master);
+		fd = open("/dev/tty", O_RDWR | O_NOCTTY);
+		if (fd >= 0) {
+			ioctl(fd, TIOCNOTTY, NULL);
+			close(fd);
+		}
+
+		if (setsid() < 0)
+			perror("setsid");
+		slave = open(slavename, O_RDWR);
+		ioctl(slave, I_PUSH, "ptem");
+		ioctl(slave, I_PUSH, "ldterm");
+		ioctl(slave, I_PUSH, "ttcompat");
+
+		if (winp)
+			(void)ioctl(slave, TIOCSWINSZ, winp);
+
+		dup2(slave, 0);
+		dup2(slave, 1);
+		dup2(slave, 2);
+		if (slave > 2)
+			close(slave);
+		return 0;
+	}
+	/*
+	 * parent
+	 */
+	*amaster = master;
+	return pid;
+}
+#endif
