[BRLTTY] patch against screen-4.0.3

Raoul MEGELAS rmgls at free.fr
Sat Aug 24 04:23:21 EDT 2013


Hi Dave and all,

this time my patch apply cleanly at least here with the macports distribution,
i am working on the FreeBSD screen port and post it if you find it useful.
As said it reimplements the shared memory from screen-4.0.1.

fell free to comment and commit if appropriate.

Best regards

Raoul
rmgls at free.fr

====================Patch-BRLTTY==========
--- Makefile.in.orig	2013-08-23 20:58:02.000000000 +0200
+++ Makefile.in	2013-08-23 20:58:28.000000000 +0200
@@ -48,6 +48,7 @@
 #	you still want to have a core. Use only for debugging.
 OPTIONS=
 #OPTIONS= -DDEBUG
+OPTIONS= -DIPC_EXPORT_IMAGE
 
 SHELL=/bin/sh
 
--- extern.h.orig	2013-08-23 07:19:26.000000000 +0200
+++ extern.h	2013-08-23 07:23:14.000000000 +0200
@@ -27,6 +27,15 @@
 #define __attribute__(x)
 #endif
 
+#ifdef IPC_EXPORT_IMAGE
+extern void SetWinImage __P((const char *, unsigned char *));
+extern void CopyWinImage __P((struct win *, unsigned char *));
+extern int IsInputLayer __P((struct layer *));
+extern int GetInputPosition __P((struct layer *));
+extern void CopyInputLine __P((struct layer *, char *, int));
+#endif /* extern.h IPC_EXPORT_IMAGE */
+
+
 /* screen.c */
 extern int   main __P((int, char **));
 extern sigret_t SigHup __P(SIGPROTOARG);
--- sched.c.orig	2013-08-23 07:47:01.000000000 +0200
+++ sched.c	2013-08-24 07:59:20.000000000 +0200
@@ -1,4 +1,3 @@
-
 /* Copyright (c) 1993-2002
  *      Juergen Weigert (jnweiger at immd4.informatik.uni-erlangen.de)
  *      Michael Schroeder (mlschroe at immd4.informatik.uni-erlangen.de)
@@ -36,8 +35,9 @@
 static struct event *tevs;
 static struct event *nextev;
 static int calctimeout;
-
 static struct event *calctimo __P((void));
+
+
 #if (defined(sgi) && defined(SVR4)) || defined(__osf__) || defined(M_UNIX)
 static int sgihack __P((void));
 #endif
@@ -111,6 +111,10 @@
   return min;
 }
 
+#ifdef IPC_EXPORT_IMAGE
+ extern struct win *windows;
+#endif /* IPC_EXPORT_IMAGE */
+ 
 void
 sched()
 {
@@ -122,6 +126,11 @@
 
   for (;;)
     {
+#ifdef IPC_EXPORT_IMAGE
+      /* export image from last used window which is on top of the list */
+      CopyWinImage( windows, shm );
+#endif /* IPC_EXPORT_IMAGE */
+
       if (calctimeout)
 	timeoutev = calctimo();
       if (timeoutev)
--- input.c	2013-08-23 07:56:56.000000000 +0200
+++ input.c	2013-08-23 07:43:20.000000000 +0200
@@ -28,6 +28,54 @@
 
 #define INPUTLINE (flayer->l_height - 1)
 
+
+#ifdef IPC_EXPORT_IMAGEs
+
+int
+IsInputLayer(l)
+struct layer *l;
+{
+  return l->l_layfn == &InpLf;
+}
+
+int
+GetInputPosition(l)
+struct layer *l;
+{
+  struct inpdata *inpdata = (struct inpdata *)l->l_data;
+  return inpdata->inpstringlen + inpdata->inp.pos;
+}
+void
+CopyInputLine(l, dest, width)
+struct layer *l;
+char *dest;
+int width;
+{
+  struct inpdata *inpdata = (struct inpdata *)l->l_data;
+  char *src;
+  int len;
+
+  for
+  ( 
+    src = inpdata->inpstring, len = inpdata->inpstringlen;
+    width && len;
+    *dest++ = *src++, len--, width--
+  );
+
+  if( !(inpdata->inpmode & INP_NOECHO) )
+    {
+      for
+      ( 
+        src = inpdata->inp.buf, len = inpdata->inp.len;
+        width && len;
+        *dest++ = *src++, len--, width--
+      );
+    }
+
+  while( width ) *dest++ = ' ', width--;
+}
+#endif	/* IPC_EXPORT_IMAGE */
+
 static void InpProcess __P((char **, int *));
 static void InpAbort __P((void));
 static void InpRedisplayLine __P((int, int, int, int));
--- screen.c	2003-09-08 16:26:41.000000000 +0200
+++ screen.c	2013-08-23 08:05:32.000000000 +0200
@@ -101,11 +101,57 @@
 
 #include "logfile.h"	/* islogfile, logfflush */
 
+#ifdef __APPLE__
+#include <vproc.h>
+#include <vproc_priv.h>
+#endif
+
 #ifdef DEBUG
 FILE *dfp;
 #endif
 
 
+#ifdef IPC_EXPORT_IMAGE
+#include <sys/ipc.h>
+#include <sys/shm.h>
+unsigned char *shm;
+#endif
+
+#ifdef IPC_EXPORT_IMAGE
+  {
+    const char *path;
+    key_t key;
+    int shmid;
+
+    /* allow for the header, text, attributes, and auxiliary data
+     * (assuming no screen will be bigger than 132x66)
+     */
+    size_t size = 18000; /*  */
+
+    path = getenv("HOME");
+    if (!path || !*path) path = "/";
+    if ((key = ftok(path, 'b')) == -1) key = 0XBACD072F;
+
+    shmid = shmget( key, size, IPC_CREAT | S_IRWXU );
+    if( shmid < 0 )
+      {
+        Panic( errno, "shmget" );
+        /* NOTREACHED */
+      }
+
+    shm = shmat( shmid, 0, 0);
+    if ( shm == (void*)-1 )
+      {
+        Panic( errno, "shmat" );
+        /* NOTREACHED */
+      }
+
+    /* put valid data into the image */
+    SetWinImage( "screen is initializing...", shm );
+  }
+#endif IPC_EXPORT_IMAGE
+
+
 extern char Term[], screenterm[], **environ, Termcap[];
 int force_vt = 1;
 int VBellWait, MsgWait, MsgMinWait, SilenceWait;
@@ -929,6 +975,16 @@
 	Panic(0, "No $SCREENDIR with multi screens, please.");
 #endif
     }
+#ifdef __APPLE__
+    else if (!multi && real_uid == eff_uid) {
+      static char DarwinSockDir[PATH_MAX];
+      if (confstr(_CS_DARWIN_USER_TEMP_DIR, DarwinSockDir, sizeof(DarwinSockDir))) {
+       strlcat(DarwinSockDir, ".screen", sizeof(DarwinSockDir));
+       SockDir = DarwinSockDir;
+      }
+    }
+#endif /* __APPLE__ */
+
 #ifdef MULTIUSER
   if (multiattach)
     {
@@ -1211,6 +1267,11 @@
   freopen("/dev/null", "w", stderr);
   debug("-- screen.back debug started\n");
 
+#ifdef __APPLE__
+       if (_vprocmgr_detach_from_console(0) != NULL)
+               errx(1, "can't detach from console");
+#endif
+
   /* 
    * This guarantees that the session owner is listed, even when we
    * start detached. From now on we should not refer to 'LoginName'
--- window.c	2013-08-23 08:08:19.000000000 +0200
+++ window.c	2013-08-23 08:21:07.000000000 +0200
@@ -92,6 +92,136 @@
 
 static int  OpenDevice __P((char **, int, int *, char **));
 static int  ForkWindow __P((struct win *, char **, char *));
+
+#ifdef IPC_EXPORT_IMAGE
+
+void
+SetWinImage( msg, dest )
+const char *msg;
+unsigned char *dest;
+{
+  unsigned char *d = dest;
+
+  *d++ = 80;   /* screen width */
+  *d++ = 1;    /* screen height */
+  *d++ = 0;    /* cursor column */
+  *d++ = 0;    /* cursor row */
+
+  {
+    size_t count = dest[0] * dest[1];
+
+    memset( d, ' ', count );
+    strcpy( d, msg );
+    d[strlen(d)] = ' ';
+    d += count;
+
+    memset( d, 0X07, count );
+    d += count;
+  }
+
+  *d++ = 0;    /* window number */
+  *d++ = 0;    /* flags */
+}
+
+
+void
+CopyWinImage( p, dest )
+struct win *p;
+unsigned char *dest;
+{
+  register unsigned char *s, *d = dest, *m;
+  register int x, y;
+  struct display *display = p->w_lastdisp;
+  int st = (display && D_status) ? 1 : 0;
+  int in = IsInputLayer(p->w_savelayer) ? 1 : 0;
+
+  if( p && p->w_mlines )
+    {
+      *d++ = p->w_width;                        /* screen width */
+      *d++ = p->w_height + (st | in);                  /* screen height */
+      *d++ = st? D_status_len:                  /* cursor column */
+             in? GetInputPosition(p->w_savelayer):
+                 p->w_x;
+      *d++ = (st || in)? p->w_height: p->w_y;       /* cursor row */
+
+      /* copy window image to buffer */
+      for( y = 0; y < p->w_height; y++ )
+        {
+          s = p->w_mlines[y].image;
+          x = p->w_width;
+          for( ; x; *d++ = *s++, x-- );
+        }
+
+      /* copy status line to buffer */
+      if( st )
+        {
+          s = D_status_lastmsg;
+          x = p->w_width;
+          for( ; *s && x; *d++ = *s++, x-- );
+          for( ; x; *d++ = ' ', x-- );
+        }
+      else if (in)
+        {
+          CopyInputLine(p->w_savelayer, d, p->w_width);
+          d += p->w_width;
+        }
+
+      /* copy attributes from window image to buffer */
+#ifdef COLOR
+      for( y = 0; y < p->w_height; y++ )
+        {
+          struct mline *ml = &p->w_mlines[y];
+          x = 0;
+          for( ; x<p->w_width; x++ )
+            {
+              static const unsigned char tr[] =
+                {
+                  0X0, 0X4, 0X2, 0X6, 0X1, 0X5, 0X3, 0X7,
+                  0X8, 0XC, 0XA, 0XE, 0X9, 0XD, 0XB, 0XF
+                };
+
+              struct mchar mc;
+              int fg;
+              int bg;
+
+              copy_mline2mchar( &mc, ml, x );
+              fg = rend_getfg(&mc);
+              bg = rend_getbg(&mc);
+
+              fg = fg? tr[coli2e(fg) & 0XF]: 0X7;
+              bg = bg? tr[coli2e(bg) & 0XF]: 0X0;
+              *d++ = fg | (bg << 4);
+            }
+        }
+
+      if( st || in )
+        {
+          memset(d, (st ? 0X70 : 0X07), p->w_width);
+          d += p->w_width;
+        }
+#else /* COLOR */
+      {
+        int count = dest[0] * dest[1];
+        memset(d, 0X07, count);
+        d += count;
+      }
+#endif /* COLOR */
+
+      *d++ = p->w_number;  /* window number */
+
+      *d = 0;  /* flags */
+      if (p->w_cursorkeys) *d |= 0X01; /* cursor keys are in application mode */
+      if (p->w_keypad) *d |= 0X02; /* keypad is in application mode */
+      d++;
+    }
+  else
+    {
+      /* no window pointer */
+      SetWinImage( "no active scren", dest );
+    }
+}
+#endif	/* IPC_EXPORT_IMAGE */
+
 #ifdef ZMODEM
 static void zmodem_found __P((struct win *, int, char *, int));
 static void zmodem_fin __P((char *, int, char *));


More information about the BRLTTY mailing list