[38940] trunk/base/src/pextlib1.0

raimue at macports.org raimue at macports.org
Sun Aug 3 01:05:44 PDT 2008


Revision: 38940
          http://trac.macosforge.org/projects/macports/changeset/38940
Author:   raimue at macports.org
Date:     2008-08-03 01:05:42 -0700 (Sun, 03 Aug 2008)
Log Message:
-----------
pextlib1.0:
Add a wrapper for isatty(3). Add term_get_size to find the size of a connected
terminal for a channel using ioctl(2).

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/Makefile
    trunk/base/src/pextlib1.0/Pextlib.c

Added Paths:
-----------
    trunk/base/src/pextlib1.0/tty.c
    trunk/base/src/pextlib1.0/tty.h

Modified: trunk/base/src/pextlib1.0/Makefile
===================================================================
--- trunk/base/src/pextlib1.0/Makefile	2008-08-03 07:51:56 UTC (rev 38939)
+++ trunk/base/src/pextlib1.0/Makefile	2008-08-03 08:05:42 UTC (rev 38940)
@@ -1,7 +1,7 @@
 OBJS=		Pextlib.o strsed.o fgetln.o md5cmd.o setmode.o xinstall.o \
 		fs-traverse.o strcasecmp.o vercomp.o filemap.o \
 		sha1cmd.o compat.o curl.o rmd160cmd.o readline.o uid.o\
-		tracelib.o
+		tracelib.o tty.o
 SHLIB_NAME=	Pextlib${SHLIB_SUFFIX}
 INSTALLDIR= ${DESTDIR}${datadir}/macports/Tcl/pextlib1.0
 export MACOSX_DEPLOYMENT_TARGET=10.3

Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c	2008-08-03 07:51:56 UTC (rev 38939)
+++ trunk/base/src/pextlib1.0/Pextlib.c	2008-08-03 08:05:42 UTC (rev 38940)
@@ -114,6 +114,7 @@
 #include "readline.h"
 #include "uid.h"
 #include "tracelib.h"
+#include "tty.h"
 
 #if HAVE_CRT_EXTERNS_H
 #include <crt_externs.h>
@@ -1214,6 +1215,8 @@
 	Tcl_CreateObjCommand(interp, "gid_to_name", gid_to_nameCmd, NULL, NULL);
 	
 	Tcl_CreateObjCommand(interp, "tracelib", TracelibCmd, NULL, NULL);
+	Tcl_CreateObjCommand(interp, "isatty", IsattyCmd, NULL, NULL);
+	Tcl_CreateObjCommand(interp, "term_get_size", TermGetSizeCmd, NULL, NULL);
 
 	if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
 		return TCL_ERROR;

Added: trunk/base/src/pextlib1.0/tty.c
===================================================================
--- trunk/base/src/pextlib1.0/tty.c	                        (rev 0)
+++ trunk/base/src/pextlib1.0/tty.c	2008-08-03 08:05:42 UTC (rev 38940)
@@ -0,0 +1,124 @@
+/*
+ * tty.c
+ * $Id$
+ * Tcl wrappers for tty control functions
+ *
+ * Author: Rainer Mueller <raimue at macports.org>
+ *
+ * Copyright (c) 2008 Rainer Mueller <raimue at macports.org>
+ * 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 Apple Computer, Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <sys/ioctl.h>
+
+#include <tcl.h>
+
+int IsattyCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+	Tcl_Obj *tcl_result;
+        Tcl_Channel chan;
+        int dir;
+        int fd;
+	int rval;
+
+	if (objc != 2) {
+            Tcl_WrongNumArgs(interp, 1, objv, "channel");
+            return TCL_ERROR;
+	}
+
+        chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), &dir);
+        if (chan == NULL) {
+            Tcl_SetResult(interp, "no such channel", TCL_STATIC);
+            return TCL_ERROR;
+        }
+
+        if (Tcl_GetChannelHandle(chan,
+                dir & TCL_READABLE ? TCL_READABLE : TCL_WRITABLE,
+                (ClientData*) &fd) == TCL_ERROR) {
+            return TCL_ERROR;
+        }
+
+        rval = isatty(fd);
+
+	tcl_result = Tcl_NewIntObj(rval);
+	Tcl_SetObjResult(interp, tcl_result);
+
+	return TCL_OK;
+}
+
+int TermGetSizeCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+	Tcl_Obj *tcl_result;
+        Tcl_Channel chan;
+        int dir;
+	int fd;
+	Tcl_Obj *robjv[2];
+        struct winsize ws = {0, 0, 0, 0};
+
+	if (objc != 2) {
+		Tcl_WrongNumArgs(interp, 1, objv, "channel");
+		return TCL_ERROR;
+	}
+
+        chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), &dir);
+        if (chan == NULL) {
+            Tcl_SetResult(interp, "no such channel", TCL_STATIC);
+            return TCL_ERROR;
+        }
+
+        if (Tcl_GetChannelHandle(chan,
+                dir & TCL_READABLE ? TCL_READABLE : TCL_WRITABLE,
+                (ClientData*) &fd) == TCL_ERROR) {
+            return TCL_ERROR;
+        }
+
+        if (!isatty(fd)) {
+            Tcl_SetResult(interp, "channel is not connected to a tty", TCL_STATIC);
+            return TCL_ERROR;
+        }
+
+        if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1) {
+            Tcl_SetResult(interp, "ioctl failed", TCL_STATIC);
+            return TCL_ERROR;
+        }
+
+        robjv[0] = Tcl_NewIntObj(ws.ws_row);
+        robjv[1] = Tcl_NewIntObj(ws.ws_col);
+
+	tcl_result = Tcl_NewListObj(2, robjv);
+	Tcl_SetObjResult(interp, tcl_result);
+
+	return TCL_OK;
+}


Property changes on: trunk/base/src/pextlib1.0/tty.c
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/base/src/pextlib1.0/tty.h
===================================================================
--- trunk/base/src/pextlib1.0/tty.h	                        (rev 0)
+++ trunk/base/src/pextlib1.0/tty.h	2008-08-03 08:05:42 UTC (rev 38940)
@@ -0,0 +1,53 @@
+/*
+ * tty.h
+ * $Id$
+ * Tcl wrappers for tty control functions
+ *
+ * Author: Rainer Mueller <raimue at macports.org>
+ *
+ * Copyright (c) 2008 Rainer Mueller <raimue at macports.org>
+ * 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 Apple Computer, Inc. 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+ */
+
+#ifndef _PEXTLIB_TTY_H
+#define _PEXTLIB_TTY_H
+
+#include <tcl.h>
+
+/**
+ * A wrapper for isatty(3)
+ */
+int IsattyCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+
+/**
+ * Determines current size of tty
+ *
+ * @returns list with 2 elements, rows and columns
+ */
+int TermGetSizeCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+
+#endif /* _PEXTLIB_TTY_H */


Property changes on: trunk/base/src/pextlib1.0/tty.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080803/257dd73e/attachment.html 


More information about the macports-changes mailing list