1. support for compiling under AIX
On 03/25/2011 10:25 PM, Ross Mohn wrote:
> I'm going to post a series of 6 patches for dvtm over the next several
> minutes. They all apply to the current HEAD of the dvtm git repository
> (committed 2011-01-07). I think I've teased them all apart pretty well
> so that each one is separate and complete.
>
> 1. support for compiling under AIX
> 2. support the 8 basic highlighted colors, plus a couple of color_hash fixes
> 3. fix a scrolling issue and add in "ESC #" to call interpret_esc_SCS()
> 4. support for "ESC 6 n", get cursor position, which calls a new
> function, send_curs()
> 5. support colorrules[] to match strings against window titles,
> applycolorrules(), and call madtty_set_dflt_colors()
> 6. support to backfill text from the buffer when a windows is resized
> with more rows
>
> Comments, testing, and bugfixes sincerely welcome!
>
> Cheers! -Ross
>
>
Index: madtty.c
===================================================================
--- madtty.c (.../vendor/current) (revision 47)
+++ madtty.c (.../trunk) (revision 47)
@@ -41,7 +41,7 @@
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include <util.h>
#endif
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(_AIX)
# include <alloca.h>
#endif
@@ -1306,6 +1348,10 @@
t->bell = !t->bell;
}
+#ifdef _AIX
+# include "forkpty-aix.c"
+#endif
+
pid_t madtty_forkpty(madtty_t *t, const char *p, const char *argv[], const
char *env[], int *pty)
{
struct winsize ws;
Index: config.h
===================================================================
--- config.h (.../vendor/current) (revision 47)
+++ config.h (.../trunk) (revision 47)
@@ -53,7 +59,7 @@
{ "[ ]", fullscreen },
};
-#define MOD CTRL('g')
+#define MOD CONTROL('g')
/* you can at most specifiy MAX_ARGS (2) number of arguments */
Key keys[] = {
Index: dvtm.c
===================================================================
--- dvtm.c (.../vendor/current) (revision 47)
+++ dvtm.c (.../trunk) (revision 47)
@@ -13,7 +13,11 @@
#define _GNU_SOURCE
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <sys/fcntl.h>
+#ifdef _AIX
+# include <fcntl.h>
+#else
+# include <sys/fcntl.h>
+#endif
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -57,10 +61,15 @@
Client *prev;
};
#define ALT(k) ((k) + (161 - 'a'))
-#ifndef CTRL
- #define CTRL(k) ((k) & 0x1F)
-#endif
+#define CONTROL(k) ((k) & 0x1F)
#define CTRL_ALT(k) ((k) + (129 - 'a'))
#define MAX_ARGS 2
@@ -568,7 +578,8 @@
static void
lock(const char *args[]) {
size_t len = 0, i = 0;
- char buf[16], *pass = buf, c;
+ char buf[16], *pass = buf;
+ int c;
erase();
curs_set(0);
@@ -966,13 +996,14 @@
keypress(int code) {
Client *c;
int len = 1;
+ int x;
char buf[8] = { '\e' };
if (code == '\e') {
/* pass characters following escape to the underlying app */
nodelay(stdscr, TRUE);
- while (len < sizeof(buf) - 1 && (buf[len] = getch()) != ERR)
- len++;
+ while (len < sizeof(buf) - 1 && (x = getch()) != ERR)
+ buf[len++] = x;
buf[len] = '\0';
nodelay(stdscr, FALSE);
}
Index: forkpty-aix.c
===================================================================
--- forkpty-aix.c (.../vendor/current) (revision 0)
+++ forkpty-aix.c (.../trunk) (revision 47)
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2009 Nicholas Marriott <[email protected]>
+ * Copyright (c) 2011 Ross Palmer Mohn <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* Open a pseudo-terminal. */
+static int
+openpty (int *amaster, int *aslave, char *name,
+ struct termios const *termp, struct winsize const *winp)
+{
+ int master;
+ char *slave_name;
+ int slave;
+
+ master = open ("/dev/ptc", O_RDWR | O_NOCTTY);
+ if (master < 0)
+ return -1;
+
+
+ if (grantpt (master))
+ goto fail;
+
+ if (unlockpt (master))
+ goto fail;
+
+ slave_name = ptsname (master);
+ if (slave_name == NULL)
+ goto fail;
+
+ slave = open (slave_name, O_RDWR | O_NOCTTY);
+ if (slave == -1)
+ goto fail;
+
+ /* XXX Should we ignore errors here? */
+ if (termp)
+ tcsetattr (slave, TCSAFLUSH, termp);
+ if (winp)
+ ioctl (slave, TIOCSWINSZ, winp);
+
+ *amaster = master;
+ *aslave = slave;
+ if (name != NULL)
+ strcpy (name, slave_name);
+
+ return 0;
+
+ fail:
+ close (master);
+ return -1;
+}
+
+/* Assign a given terminal as controlling terminal and as standard input,
+ standard output, standard error of the current process. */
+static int
+login_tty (int slave_fd)
+{
+ int i;
+
+ /* Create a new session. */
+ setsid ();
+
+ /* Make fd the controlling terminal for the current process.
+ On Solaris:
+ A terminal becomes the controlling terminal of a session
+ if it is being open()ed, at a moment when
+ 1. it is not already the controlling terminal of some session, and
+ 2. the process that open()s it is a session leader that does not have
+ a controlling terminal.
+ We assume condition 1, try to ensure condition 2, and then open() it.
+ */
+ for (i = 0; i < 3; i++)
+ if (i != slave_fd)
+ close (i);
+
+ char *slave_name;
+ int dummy_fd;
+
+ slave_name = ttyname (slave_fd);
+ if (slave_name == NULL)
+ return -1;
+ dummy_fd = open (slave_name, O_RDWR);
+ if (dummy_fd < 0)
+ return -1;
+ close (dummy_fd);
+
+ /* Assign fd to the standard input, standard output, and standard error of
+ the current process. */
+ for (i = 0; i < 3; i++)
+ if (slave_fd != i)
+ while (dup2 (slave_fd, i) == -1 && errno == EBUSY);
+// if (dup2 (slave_fd, i) < 0)
+// return -1;
+ if (slave_fd >= 3)
+ close (slave_fd);
+
+ return 0;
+}
+
+/* Fork a child process attached to the slave of a pseudo-terminal. */
+static int
+forkpty (int *amaster, char *name,
+ const struct termios *termp, const struct winsize *winp)
+{
+ int master, slave, pid;
+
+ if (openpty (&master, &slave, name, termp, winp) == -1)
+ return -1;
+
+ switch (pid = fork ())
+ {
+ case -1:
+ close (master);
+ close (slave);
+ return -1;
+
+ case 0:
+ /* Child. */
+ close (master);
+ if (login_tty (slave))
+ _exit (1);
+ return 0;
+
+ default:
+ /* Parent. */
+ *amaster = master;
+ close (slave);
+// sleep(1);
+ return pid;
+ }
+}