[PATCH 2/18] separate-console-handling.patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



===================================================================


ChangeSet@xxx, 2004-08-10 00:52:37-05:00, dtor_core@xxxxxxxxxxxxx
  Move console handling functions to console.c module.


 Makefile.in       |    4 
 console.c         |  330 +++++++++++++++++++++++++++++++++++++++++++
 gpm.c             |  408 +++++++++++++-----------------------------------------
 gpn.c             |  113 +-------------
 headers/console.h |   52 ++++++
 headers/gpmInt.h  |   12 -
 headers/message.h |    2 
 lib/liblow.c      |   29 +--
 mice.c            |   41 ++---
 report.c          |   57 +++----
 special.c         |    5 
 startup.c         |   10 -
 twiddler.c        |   16 --
 13 files changed, 574 insertions(+), 505 deletions(-)


===================================================================



diff -Nru a/src/Makefile.in b/src/Makefile.in
--- a/src/Makefile.in	2004-08-10 01:17:57 -05:00
+++ b/src/Makefile.in	2004-08-10 01:17:57 -05:00
@@ -14,7 +14,7 @@
 # Main portion: regular build rules
 
 GSRC = main.c gpm.c gpn.c mice.c special.c twiddler.c synaptics.c \
-       startup.c server_tools.c
+       startup.c server_tools.c console.c
 
 GOBJ = $(GSRC:.c=.o) report.o tools.o
 
@@ -153,7 +153,7 @@
 	$(CC) -I. @CPPFLAGS@ $(CPPFLAGS) @CFLAGS@ $(CFLAGS) -c -o $@.o $<
 	$(CC) @LDFLAGS@ $(LDFLAGS) -o $@ $@.o @LIBS@ $(LIBS) lib/libgpm.a
 
-prog/mouse-test:	mice.o twiddler.o synaptics.o
+prog/mouse-test:	mice.o twiddler.o synaptics.o console.o
 
 $(PROG):	@SHLIB@ lib/libgpm.a
 
diff -Nru a/src/console.c b/src/console.c
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/src/console.c	2004-08-10 01:17:57 -05:00
@@ -0,0 +1,330 @@
+/*
+ * console.c - GPM console and selection/paste handling
+ *
+ * Copyright (C) 1993        Andreq Haylett <ajh@xxxxxxxxxxxxx>
+ * Copyright (C) 1994-1999   Alessandro Rubini <rubini@xxxxxxxx>
+ * Copyright (C) 1998        Ian Zimmerman <itz@xxxxxxxxx>
+ * Copyright (c) 2001,2002   Nico Schottelius <nico-gpm@xxxxxxxxxxxxxxx>
+ * Copyright (c) 2003        Dmitry Torokhov <dtor@xxxxxxx>
+ *
+ *   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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ ********/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>        /* strerror(); ?!?  */
+#include <errno.h>
+#include <unistd.h>        /* select(); */
+#include <time.h>          /* time() */
+#include <sys/fcntl.h>     /* O_RDONLY */
+#include <sys/stat.h>      /* mkdir()  */
+#include <asm/types.h>     /* __u32 */
+
+#include <linux/vt.h>      /* VT_GETSTATE */
+#include <sys/kd.h>        /* KDGETMODE */
+#include <termios.h>       /* winsize */
+
+#include "headers/gpmInt.h"
+#include "headers/console.h"
+#include "headers/message.h"
+
+#ifndef HAVE___U32
+# ifndef _I386_TYPES_H /* /usr/include/asm/types.h */
+typedef unsigned int __u32;
+# endif
+#endif
+
+struct sel_options sel_opts = { 0, 0, DEF_PTRDRAG };
+struct gpm_console console = { 0, DEF_LUT, 0, 0 };
+
+static time_t last_selection_time;
+
+/*-------------------------------------------------------------------*/
+int open_console(int mode)
+{
+   int fd;
+
+   if ((fd = open(console.device, mode)) < 0)
+      gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN_CON);
+
+   return fd;
+}
+
+/*-------------------------------------------------------------------*/
+int is_text_console(void)
+{
+   int fd;
+   int kd_mode;
+
+   fd = open_console(O_RDONLY);
+   if (ioctl(fd, KDGETMODE, &kd_mode) < 0)
+      gpm_report(GPM_PR_OOPS, GPM_MESS_IOCTL_KDGETMODE);
+   close(fd);
+
+   return kd_mode == KD_TEXT;
+}
+
+/*-------------------------------------------------------------------*/
+void wait_text_console(void)
+{
+   do {
+      sleep(2);
+   } while (!is_text_console());
+}
+
+/*-------------------------------------------------------------------*/
+void refresh_console_size(void)
+{
+   struct winsize win;
+   int fd = open_console(O_RDONLY);
+
+   ioctl(fd, TIOCGWINSZ, &win);
+   close(fd);
+
+   if (!win.ws_col || !win.ws_row) {
+      gpm_report(GPM_PR_DEBUG, GPM_MESS_ZERO_SCREEN_DIM);
+      console.max_x = 80; console.max_y = 25;
+   } else {
+      console.max_x = win.ws_col; console.max_y = win.ws_row;
+   }
+   gpm_report(GPM_PR_DEBUG, GPM_MESS_SCREEN_SIZE, console.max_x, console.max_y);
+}
+
+/*-------------------------------------------------------------------*/
+int get_console_state(unsigned char *shift_state)
+{
+   struct vt_stat stat;
+   int fd;
+
+   fd = open_console(O_RDONLY);
+
+   *shift_state = 6; /* code for the ioctl */
+   if (ioctl(fd, TIOCLINUX, shift_state) < 0)
+      gpm_report(GPM_PR_OOPS, GPM_MESS_GET_SHIFT_STATE);
+
+   if (ioctl(fd, VT_GETSTATE, &stat) < 0)
+      gpm_report(GPM_PR_OOPS, GPM_MESS_GET_CONSOLE_STAT);
+
+   close(fd);
+
+   return stat.v_active;
+}
+
+/*-------------------------------------------------------------------*/
+int is_console_owner(int vc, uid_t uid)
+{
+   struct stat statbuf;
+   char  *tty;
+   int   rc;
+
+   tty = malloc(strlen(console.device) + Gpm_cnt_digits(vc) + sizeof(char));
+   if (!tty)
+      gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM);
+
+   strncpy(tty, console.device, strlen(console.device) - 1);
+   sprintf(&tty[strlen(console.device) - 1], "%d", vc);
+
+   rc = stat(tty, &statbuf);
+
+   free(tty);
+
+   if (rc == -1) {
+      gpm_report(GPM_PR_ERR, GPM_MESS_STAT_FAILS, tty);
+      return 0;
+   }
+
+   return uid == statbuf.st_uid;
+}
+
+/*-------------------------------------------------------------------*/
+/* octal digit */
+static int isodigit(const unsigned char c)
+{
+   return ((c & ~7) == '0');
+}
+
+/*-------------------------------------------------------------------*/
+/* routine to convert digits from octal notation (Andries Brouwer) */
+static int getsym(const unsigned char *p0, unsigned char *res)
+{
+   const unsigned char *p = p0;
+   char c;
+
+   c = *p++;
+   if (c == '\\' && *p) {
+      c = *p++;
+      if (isodigit(c)) {
+         c -= '0';
+         if (isodigit(*p)) c = 8*c + (*p++ - '0');
+         if (isodigit(*p)) c = 8*c + (*p++ - '0');
+      }
+   }
+   *res = c;
+   return (p - p0);
+}
+
+/*-------------------------------------------------------------------*/
+/* description missing! FIXME */
+void console_load_lut(void)
+{
+   extern int errno;
+   int i, c, fd;
+   unsigned char this, next;
+   static __u32 long_array[9] = {
+      0x05050505, /* ugly, but preserves alignment */
+      0x00000000, /* control chars     */
+      0x00000000, /* digits            */
+      0x00000000, /* uppercase and '_' */
+      0x00000000, /* lowercase         */
+      0x00000000, /* Latin-1 control   */
+      0x00000000, /* Latin-1 misc      */
+      0x00000000, /* Latin-1 uppercase */
+      0x00000000  /* Latin-1 lowercase */
+   };
+
+#define inwordLut (long_array+1)
+
+   for (i = 0; console.charset[i]; ) {
+      i += getsym(console.charset + i, &this);
+      if (console.charset[i] == '-' && console.charset[i + 1] != '\0')
+         i += getsym(console.charset + i + 1, &next) + 1;
+      else
+         next = this;
+      for (c = this; c <= next; c++)
+         inwordLut[c >> 5] |= 1 << (c & 0x1F);
+   }
+
+   fd = open_console(O_WRONLY);
+
+   if (ioctl(fd, TIOCLINUX, &long_array) < 0) { /* fd <0 is checked */
+      if (errno == EPERM && getuid())
+         gpm_report(GPM_PR_WARN, GPM_MESS_ROOT); /* why do we still continue?*/
+      else if (errno == EINVAL)
+         gpm_report(GPM_PR_OOPS, GPM_MESS_CSELECT);
+   }
+   close(fd);
+}
+
+/*-------------------------------------------------------------------*/
+static void selection_copy(int x1, int y1, int x2, int y2, int mode)
+{
+   /*
+    * The approach in "selection" causes a bus error when run under SunOS 4.1
+    * due to alignment problems...
+    */
+   unsigned char buf[6 * sizeof(short)];
+   unsigned short *arg = (unsigned short *)buf + 1;
+   int fd;
+
+   buf[sizeof(short) - 1] = 2;  /* set selection */
+
+   arg[0] = (unsigned short)x1;
+   arg[1] = (unsigned short)y1;
+   arg[2] = (unsigned short)x2;
+   arg[3] = (unsigned short)y2;
+   arg[4] = (unsigned short)mode;
+
+   if ((fd = open_console(O_WRONLY)) < 0)
+      gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN_CON);
+
+   gpm_report(GPM_PR_DEBUG, "ctl %i, mode %i", (int)*buf, arg[4]);
+   if (ioctl(fd, TIOCLINUX, buf + sizeof(short) - 1) < 0)
+      gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX);
+   close(fd);
+
+   if (mode < 3) {
+      sel_opts.aged = 0;
+      last_selection_time = time(0);
+   }
+}
+
+/*-------------------------------------------------------------------*/
+static void selection_paste(void)
+{
+   char c = 3;
+   int fd;
+
+   if (!sel_opts.aged &&
+      sel_opts.age_limit != 0 &&
+      last_selection_time + sel_opts.age_limit < time(0)) {
+      sel_opts.aged = 1;
+   }
+
+   if (sel_opts.aged)
+      gpm_report(GPM_PR_DEBUG, GPM_MESS_SKIP_PASTE);
+   else {
+      fd = open_console(O_WRONLY);
+      if (ioctl(fd, TIOCLINUX, &c) < 0)
+         gpm_report(GPM_PR_OOPS, GPM_MESS_IOCTL_TIOCLINUX);
+      close(fd);
+   }
+}
+
+/*-------------------------------------------------------------------*/
+void do_selection(Gpm_Event *event, int three_button_mode)
+{
+   static int x1 = 1, y1 = 1;
+   int x2, y2;
+
+   x2 = event->x; y2 = event->y;
+   switch (GPM_BARE_EVENTS(event->type)) {
+      case GPM_MOVE:
+         if (x2 < 1) x2++; else if (x2 > console.max_x) x2--;
+         if (y2 < 1) y2++; else if (y2 > console.max_y) y2--;
+         selection_copy(x2, y2, x2, y2, 3); /* just highlight the pointer */
+         break;
+
+      case GPM_DRAG:
+         if (event->buttons == GPM_B_LEFT) {
+            switch(event->margin) { /* fix margins */
+               case GPM_TOP: x2 = 1; y2++; break;
+               case GPM_BOT: x2 = console.max_x; y2--; break;
+               case GPM_RGT: x2--; break;
+               case GPM_LFT: y2 <= y1 ? x2++ : (x2 = console.max_x, y2--); break;
+               default: break;
+            }
+            selection_copy(x1, y1, x2, y2, event->clicks);
+            if (event->clicks >= sel_opts.ptrdrag && !event->margin) /* pointer */
+               selection_copy(x2, y2, x2, y2, 3);
+         } /* if */
+         break;
+
+      case GPM_DOWN:
+         switch (event->buttons) {
+            case GPM_B_LEFT:
+               x1 = x2; y1 = y2;
+               selection_copy(x1, y1, x2, y2, event->clicks); /* start selection */
+               break;
+
+            case GPM_B_MIDDLE:
+               selection_paste();
+               break;
+
+            case GPM_B_RIGHT:
+               if (three_button_mode == 1)
+                  selection_copy(x1, y1, x2, y2, event->clicks);
+               else
+                  selection_paste();
+               break;
+         }
+   } /* switch above */
+}
+
+/*-------------------------------------------------------------------*/
+void selection_disable_paste(void)
+{
+   sel_opts.aged = 1;
+}
+
diff -Nru a/src/gpm.c b/src/gpm.c
--- a/src/gpm.c	2004-08-10 01:17:57 -05:00
+++ b/src/gpm.c	2004-08-10 01:17:57 -05:00
@@ -28,7 +28,6 @@
 #include <unistd.h>        /* select(); */
 #include <signal.h>        /* SIGPIPE */
 #include <time.h>          /* time() */
-#include <sys/param.h>
 #include <sys/fcntl.h>     /* O_RDONLY */
 #include <sys/wait.h>      /* wait()   */
 #include <sys/stat.h>      /* mkdir()  */
@@ -37,12 +36,9 @@
 #include <sys/socket.h>    /* socket() */
 #include <sys/un.h>        /* struct sockaddr_un */
 
-#include <linux/vt.h>      /* VT_GETSTATE */
-#include <sys/kd.h>        /* KDGETMODE */
-#include <termios.h>       /* winsize */
-
 #include "headers/gpmInt.h"
 #include "headers/message.h"
+#include "headers/console.h"
 
 /* who the f*** runs gpm without glibc? doesn't have dietlibc __socklent_t? */
 #if !defined(__GLIBC__)
@@ -78,27 +74,19 @@
 
 /* These are only the 'global' options */
 
-char *opt_lut=DEF_LUT;
 int opt_test=DEF_TEST;
-int opt_ptrdrag=DEF_PTRDRAG;
 int opt_double=0;
-int opt_aged = 0;
 char *opt_special=NULL; /* special commands, like reboot or such */
 int opt_rawrep=0;
 Gpm_Type *repeated_type=0;
 
 static int opt_resize=0; /* not really an option */
-struct winsize win;
-int maxx, maxy;
 int fifofd=-1;
 
 int eventFlag=0;
 Gpm_Cinfo *cinfo[MAX_VC+1];
 fd_set selSet, readySet, connSet;
 
-time_t last_selection_time;
-time_t opt_age_limit = 0;
-
 /* BRAINDEAD..ok not really, but got to leave anyway... FIXME */
 /* argc and argv for mice initialization */
 static int mouse_argc[3]; /* 0 for default (unused) and two mice */
@@ -144,155 +132,6 @@
 }
 
 /*-------------------------------------------------------------------*/
-/* The old console option is removed. We are taking stderr now
- * In the next update there should also be support for syslog
- ********************************************************************/
-
-static inline int open_console(const int mode)
-{
-   int fd;
-
-   if ((fd=open(option.consolename, mode)) < 0)
-      gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN_CON);
-   return fd;
-}
-
-/*-------------------------------------------------------------------*/
-static inline int wait_text(int *fdptr)
-{
-   int fd;
-   int kd_mode;
-
-   close(*fdptr);
-   do
-   {
-      sleep(2);
-      fd = open_console(O_RDONLY);
-      if (ioctl(fd, KDGETMODE, &kd_mode)<0)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_KDGETMODE);
-      close(fd);
-   }
-   while (kd_mode != KD_TEXT) ;
-
-   /* reopen, reinit (the function is only used if we have one mouse device) */
-   if ((*fdptr=open(opt_dev,O_RDWR))<0)
-      gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN,opt_dev);
-   if (m_type->init)
-      m_type=(m_type->init)(*fdptr, m_type->flags, m_type, mouse_argc[1],
-              mouse_argv[1]);
-   return (1);
-}
-
-/*-------------------------------------------------------------------*/
-static inline void selection_copy(int x1, int y1, int x2, int y2, int mode)
-{
-/*
- * The approach in "selection" causes a bus error when run under SunOS 4.1
- * due to alignment problems...
- */
-   unsigned char buf[6*sizeof(short)];
-   unsigned short *arg = (unsigned short *)buf + 1;
-   int fd;
-
-   buf[sizeof(short)-1] = 2;  /* set selection */
-
-   arg[0]=(unsigned short)x1;
-   arg[1]=(unsigned short)y1;
-   arg[2]=(unsigned short)x2;
-   arg[3]=(unsigned short)y2;
-   arg[4]=(unsigned short)mode;
-
-   if ((fd=open_console(O_WRONLY))<0)
-      gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN_CON);
-   /* FIXME: should be replaced with string constant (headers/message.h) */
-   gpm_report(GPM_PR_DEBUG,"ctl %i, mode %i",(int)*buf, arg[4]);
-   if (ioctl(fd, TIOCLINUX, buf+sizeof(short)-1) < 0)
-     gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX);
-   close(fd);
-
-   if (mode < 3) {
-      opt_aged = 0;
-      last_selection_time = time(0);
-   }
-}
-
-
-/*-------------------------------------------------------------------*/
-/* comment missing; FIXME */
-/*-------------------------------------------------------------------*/
-static inline void selection_paste(void)
-{
-   char c=3;
-   int fd;
-
-   if (!opt_aged && (0 != opt_age_limit) &&
-      (last_selection_time + opt_age_limit < time(0))) {
-      opt_aged = 1;
-   }
-
-   if (opt_aged) {
-      gpm_report(GPM_PR_DEBUG,GPM_MESS_SKIP_PASTE);
-      return;
-   } 
-
-   fd=open_console(O_WRONLY);
-   if(ioctl(fd, TIOCLINUX, &c) < 0)
-      gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX);
-   close(fd);
-}
-
-/*-------------------------------------------------------------------*/
-static  inline int do_selection(Gpm_Event *event)  /* returns 0, always */
-{
-   static int x1=1, y1=1, x2, y2;
-#define UNPOINTER() 0
-
-   x2=event->x; y2=event->y;
-   switch(GPM_BARE_EVENTS(event->type)) {
-      case GPM_MOVE:
-         if (x2<1) x2++; else if (x2>maxx) x2--;
-         if (y2<1) y2++; else if (y2>maxy) y2--;
-         selection_copy(x2,y2,x2,y2,3); /* just highlight pointer */
-         return 0;
-
-      case GPM_DRAG:
-         if (event->buttons==GPM_B_LEFT) {
-            if (event->margin) /* fix margins */
-               switch(event->margin) {
-                  case GPM_TOP: x2=1; y2++; break;
-                  case GPM_BOT: x2=maxx; y2--; break;
-                  case GPM_RGT: x2--; break;
-                  case GPM_LFT: y2<=y1 ? x2++ : (x2=maxx, y2--); break;
-               }
-            selection_copy(x1,y1,x2,y2,event->clicks);
-            if (event->clicks>=opt_ptrdrag && !event->margin) /* pointer */
-               selection_copy(x2,y2,x2,y2,3);
-         } /* if */
-         return 0;
-
-      case GPM_DOWN:
-         switch (event->buttons) {
-            case GPM_B_LEFT:
-               x1=x2; y1=y2;
-               selection_copy(x1,y1,x2,y2,event->clicks); /* start selection */
-               return 0;
-
-            case GPM_B_MIDDLE:
-               selection_paste();
-               return 0;
-
-            case GPM_B_RIGHT:
-               if (opt_three==1)
-                  selection_copy(x1,y1,x2,y2,event->clicks);
-               else
-                  selection_paste();
-               return 0;
-         }
-   } /* switch above */
-   return 0;
-}
-
-/*-------------------------------------------------------------------*/
 /* returns 0 if the event has not been processed, and 1 if it has */
 static inline int do_client(Gpm_Cinfo *cinfo, Gpm_Event *event)
 {
@@ -329,7 +168,7 @@
  * fetch the actual device data from the mouse device, dependent on
  * what Gpm_Type is being passed.
  *-------------------------------------------------------------------*/
-static inline char *getMouseData(int fd, Gpm_Type *type, int kd_mode)
+static inline char *getMouseData(int fd, Gpm_Type *type, int text_mode)
 {
    static unsigned char data[32]; /* quite a big margin :) */
    char *edata=data+type->packetlen;
@@ -344,7 +183,7 @@
       return NULL;
    }
 
-   if (kd_mode!=KD_TEXT && fifofd != -1 && opt_rawrep)
+   if (!text_mode && fifofd != -1 && opt_rawrep)
       write(fifofd, data, howmany);
 
    if ((data[0]&(m_type->proto)[0]) != (m_type->proto)[1]) {
@@ -367,7 +206,7 @@
    if((i=m_type->packetlen-howmany)) /* still to get */
       do {
          j = read(fd,edata-i,i); /* edata is pointer just after data */
-         if (kd_mode!=KD_TEXT && fifofd != -1 && opt_rawrep && j > 0)
+         if (!text_mode && fifofd != -1 && opt_rawrep && j > 0)
             write(fifofd, edata-i, j);
          i -= j;
       } while (i && j);
@@ -388,21 +227,48 @@
 
 static int statusX,statusY,statusB; /* to return info */
 static int statusC=0; /* clicks */
-void get_console_size(Gpm_Event *ePtr);
+
+/*-------------------------------------------------------------------*/
+void handle_console_resize(Gpm_Event *ePtr)
+{
+   int old_x, old_y;
+   int i;
+   struct mouse_features *which_mouse; /* local */
+
+   old_x = console.max_x; old_y = console.max_y;
+   refresh_console_size();
+   if (!old_x) { /* first invocation, place the pointer in the middle */
+      statusX = ePtr->x = console.max_x / 2;
+      statusY = ePtr->y = console.max_y / 2;
+   } else { /* keep the pointer in the same position where it was */
+      statusX = ePtr->x = ePtr->x * console.max_x / old_x;
+      statusY = ePtr->y = ePtr->y * console.max_y / old_y;
+   }
+
+   for (i=1; i <= 1+opt_double; i++) {
+      which_mouse=mouse_table+i; /* used to access options */
+      /*
+       * the following operation is based on the observation that 80x50
+       * has square cells. (An author-centric observation ;-)
+       */
+      opt_scaley = opt_scale * 50 * console.max_x / 80 / console.max_y;
+      gpm_report(GPM_PR_DEBUG, GPM_MESS_X_Y_VAL, opt_scale, opt_scaley);
+   }
+}
 
 /*-------------------------------------------------------------------
  * call getMouseData to get hardware device data, call mouse device's fun() 
  * to retrieve the hardware independent event data, then optionally repeat
  * the data via repeat_fun() to the repeater device
  *-------------------------------------------------------------------*/
-static inline int processMouse(int fd, Gpm_Event *event, Gpm_Type *type,
-                int kd_mode)
+static inline int processMouse(int fd, Gpm_Event *event, Gpm_Type *type, int text_mode)
 {
    char *data;
+   unsigned char shift_state;
+   static int last_active;
    static int fine_dx, fine_dy;
-   static int i, j, m;
+   static int i, m;
    static Gpm_Event nEvent;
-   static struct vt_stat stat;
    static struct timeval tv1={0,0}, tv2; /* tv1==0: first click is single */
    static struct timeval timeout={0,0};
    fd_set fdSet;
@@ -433,7 +299,7 @@
       FD_ZERO(&fdSet); FD_SET(fd,&fdSet); i=0;
 
       do { /* cluster loop */
-         if(((data=getMouseData(fd,m_type,kd_mode))==NULL)
+         if(((data=getMouseData(fd,m_type, text_mode))==NULL)
             || ((*(m_type->fun))(&nEvent,data)==-1) ) {
             if (!i) return 0;
             else break;
@@ -482,7 +348,7 @@
 
 /*....................................... we're a repeater, aren't we? */
 
-   if (kd_mode!=KD_TEXT) {
+   if (!text_mode) {
       if (fifofd != -1 && ! opt_rawrep) {
          if (m_type->absolute) { /* hof Wed Feb  3 21:43:28 MET 1999 */ 
             /* prepare the values from a absolute device for repeater mode */
@@ -495,7 +361,7 @@
             }
             rept1=rept2;
               
-            event->dy=event->dy*((win.ws_col/win.ws_row)+1);
+            event->dy = event->dy * ((console.max_x / console.max_y) + 1);
             event->x=nEvent.x; 
             event->y=nEvent.y;
          }
@@ -530,32 +396,17 @@
 
 /*....................................... fill missing fields */
 
-   event->x+=event->dx, event->y+=event->dy;
+   event->x += event->dx, event->y += event->dy;
    statusB=event->buttons;
 
-   i=open_console(O_RDONLY);
-   /* modifiers */
-   j = event->modifiers; /* save them */
-   event->modifiers=6; /* code for the ioctl */
-   if (ioctl(i,TIOCLINUX,&(event->modifiers))<0)
-      gpm_report(GPM_PR_OOPS,GPM_MESS_GET_SHIFT_STATE);
-   event->modifiers |= j; /* add mouse-specific bits */
-
-   /* status */
-   j = stat.v_active;
-   if (ioctl(i,VT_GETSTATE,&stat)<0) gpm_report(GPM_PR_OOPS,GPM_MESS_GET_CONSOLE_STAT);
-
-   /*
-    * if we changed console, request the current console size,
-    * as different consoles can be of different size
-    */
-   if (stat.v_active != j)
-      get_console_size(event);
-   close(i);
-
-   event->vc = stat.v_active;
+   event->vc = get_console_state(&shift_state);
+   if (event->vc != last_active) {
+      handle_console_resize(event);
+      last_active = event->vc;
+   }
+   event->modifiers |= shift_state;
 
-   if (oldB==event->buttons)
+   if (oldB == event->buttons)
       event->type = (event->buttons ? GPM_DRAG : GPM_MOVE);
    else
       event->type = (event->buttons > oldB ? GPM_DOWN : GPM_UP);
@@ -604,15 +455,27 @@
     */
 
    m = 0;
-   i = ((event->type&(GPM_DRAG|GPM_UP))!=0); /* i is boolean */
-
-   if (event->y>win.ws_row)  {event->y=win.ws_row+1-!i; i=0; m = GPM_BOT;}
-   else if (event->y<=0)     {event->y=1-i;             i=0; m = GPM_TOP;}
+   i = (event->type & (GPM_DRAG|GPM_UP)) != 0; /* i is boolean */
 
-   if (event->x>win.ws_col)  {event->x=win.ws_col+1-!i; if (!m) m = GPM_RGT;}
-   else if (event->x<=0)     {event->x=1-i;             if (!m) m = GPM_LFT;}
+   if (event->y > console.max_y) {
+      event->y = console.max_y + 1 - !i;
+      i = 0;
+      m = GPM_BOT;
+   } else if (event->y <= 0) {
+      event->y = 1 - i;
+      i = 0;
+      m = GPM_TOP;
+   }
+
+   if (event->x > console.max_x) {
+      event->x = console.max_x + 1 - !i;
+      if (!m) m = GPM_RGT;
+   } else if (event->x <= 0) {
+      event->x = 1 - i;
+      if (!m) m = GPM_LFT;
+   }
 
-   event->margin=m;
+   event->margin = m;
 
    gpm_report(GPM_PR_DEBUG,"M: %3i %3i (%3i %3i) - butt=%i vc=%i cl=%i",
                                        event->dx,event->dy,
@@ -654,12 +517,6 @@
    return 1;
 }
 
-static void disable_paste(int vc)
-{
-   opt_aged++;
-   gpm_report(GPM_PR_INFO,GPM_MESS_DISABLE_PASTE,vc);
-}
-
 /*-------------------------------------------------------------------*/
                                   /* returns -1 if closing connection */
 static inline int processRequest(Gpm_Cinfo *ci, int vc) 
@@ -668,7 +525,6 @@
    Gpm_Cinfo *cinfoPtr, *next;
    Gpm_Connect conn;
    static Gpm_Event event;
-   static struct vt_stat stat;
 
    gpm_report(GPM_PR_INFO,GPM_MESS_CON_REQUEST, ci->fd, vc);
    if (vc>MAX_VC) return -1;
@@ -713,15 +569,9 @@
    /* Aha, request for information (so-called snapshot) */
    switch(conn.vc) {
       case GPM_REQ_SNAPSHOT:
-         i=open_console(O_RDONLY);
-         ioctl(i,VT_GETSTATE,&stat);
-         event.modifiers=6; /* code for the ioctl */
-         if (ioctl(i,TIOCLINUX,&(event.modifiers))<0)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_GET_SHIFT_STATE);
-         close(i);
-         event.vc = stat.v_active;
+         event.vc = get_console_state(&event.modifiers);
          event.x=statusX;   event.y=statusY;
-         event.dx=maxx;     event.dy=maxy;
+         event.dx = console.max_x; event.dy = console.max_y;
          event.buttons= statusB;
          event.clicks=statusC;
          /* fall through */
@@ -733,7 +583,8 @@
          break;
 
       case GPM_REQ_NOPASTE:
-         disable_paste(vc);
+         selection_disable_paste();
+         gpm_report(GPM_PR_INFO, GPM_MESS_DISABLE_PASTE, vc);
          break;
    }
 
@@ -745,7 +596,6 @@
 {
    Gpm_Cinfo *info;
    Gpm_Connect *request;
-   Gpm_Cinfo *next;
    int vc, newfd;
 #if !defined(__GLIBC__)
    int len;
@@ -753,9 +603,11 @@
    size_t len; /* isn't that generally defined in C ???  -- nico */
 #endif /* __GLIBC__ */
    struct sockaddr_un addr; /* reuse this each time */
+#ifndef SO_PEERCRED
    struct stat statbuf;
+   time_t staletime;
+#endif
    uid_t uid;
-   char *tty = NULL;
 
 /*....................................... Accept */
 
@@ -823,33 +675,15 @@
       gpm_report(GPM_PR_DEBUG,GPM_MESS_PEER_SCK_UID, uid);
    }
 #endif
-   if (uid != 0) {
-      if(( tty =
-         malloc(strlen(option.consolename)+Gpm_cnt_digits(vc) + sizeof(char))) == NULL)
-            gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM);
-      
-      strncpy(tty,option.consolename,strlen(option.consolename)-1);
-      sprintf(&tty[strlen(option.consolename)-1],"%d",vc);
-
-      if(stat(tty, &statbuf) == -1) {
-         gpm_report(GPM_PR_ERR,GPM_MESS_STAT_FAILS,tty);
-         free(info);
-         free(tty);
-         close(newfd);
-         return -1;
-      }
-      if (uid != statbuf.st_uid) {
-         gpm_report(GPM_PR_WARN,GPM_MESS_FAILED_CONNECT, uid, tty); /*SUSPECT!*/
-         free(info);
-         free(tty);
-         close(newfd);
-         return -1;
-      }
-      free(tty); /* at least here it's not needed anymore */
+   if (uid != 0 && !is_console_owner(vc, uid)) {
+      gpm_report(GPM_PR_WARN, GPM_MESS_FAILED_CONNECT, uid, vc); /*SUSPECT!*/
+      free(info);
+      close(newfd);
+      return -1;
    }
 
    /* register the connection information in the right place */
-   info->next=next=cinfo[vc];
+   info->next=cinfo[vc];
    info->fd=newfd;
    cinfo[vc]=info;
    gpm_report(GPM_PR_DEBUG,GPM_MESS_LONG_STATUS,
@@ -866,44 +700,6 @@
 }
 
 /*-------------------------------------------------------------------*/
-void get_console_size(Gpm_Event *ePtr)
-{
-   int i, prevmaxx, prevmaxy;
-   struct mouse_features *which_mouse; /* local */
-
-   /* before asking the new console size, save the previous values */
-   prevmaxx = maxx; prevmaxy = maxy;
-
-   i=open_console(O_RDONLY);
-   ioctl(i, TIOCGWINSZ, &win);
-   close(i);
-   if (!win.ws_col || !win.ws_row) {
-      gpm_report(GPM_PR_DEBUG,GPM_MESS_ZERO_SCREEN_DIM);
-      win.ws_col=80; win.ws_row=25;
-   }
-   maxx=win.ws_col; maxy=win.ws_row;
-   gpm_report(GPM_PR_DEBUG,GPM_MESS_SCREEN_SIZE,maxx,maxy);
-
-   if (!prevmaxx) { /* first invocation, place the pointer in the middle */
-      statusX = ePtr->x = maxx/2;
-      statusY = ePtr->y = maxy/2;
-   } else { /* keep the pointer in the same position where it was */
-      statusX = ePtr->x = ePtr->x * maxx / prevmaxx;
-      statusY = ePtr->y = ePtr->y * maxy / prevmaxy;
-   } 
-
-   for (i=1; i <= 1+opt_double; i++) {
-      which_mouse=mouse_table+i; /* used to access options */
-     /*
-      * the following operation is based on the observation that 80x50
-      * has square cells. (An author-centric observation ;-)
-      */
-     opt_scaley=opt_scale*50*maxx/80/maxy;
-     gpm_report(GPM_PR_DEBUG,GPM_MESS_X_Y_VAL,opt_scale,opt_scaley);
-   }
-}
-
-/*-------------------------------------------------------------------*/
 static void gpm_killed(int signo)
 {
    if(signo==SIGWINCH) {
@@ -921,7 +717,7 @@
 {
    int ctlfd, newfd;
    struct sockaddr_un ctladdr;
-   int i, len, kd_mode, fd;
+   int i, len, text_mode, fd;
    struct timeval timeout;
    int maxfd=-1;
    int pending;
@@ -977,7 +773,7 @@
    /* needs to be 0777, so all users can _try_ to access gpm */
    chmod(GPM_NODE_CTL,0777);
 
-   get_console_size(&event); /* get screen dimensions */
+   handle_console_resize(&event); /* get screen dimensions */
 
 /*....................................... wait for mouse and connections */
 
@@ -1015,7 +811,7 @@
          } /* go on */
 
       if(opt_resize) { /* did the console resize? */
-         get_console_size(&event);
+         handle_console_resize(&event);
          opt_resize--;
          signal(SIGWINCH,gpm_killed); /* reinstall handler */
 
@@ -1042,19 +838,21 @@
       * Be sure to be in text mode. This used to be before select,
       * but actually it only matters if you have events.
       */
-      {
-      int fd = open_console(O_RDONLY);
-      if (ioctl(fd, KDGETMODE, &kd_mode) < 0)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_KDGETMODE);
-      close(fd);
-      if(kd_mode != KD_TEXT && !option.repeater) {
-         wait_text(&mouse_table[1].fd);
-         maxfd=max(maxfd,mouse_table[1].fd);
-         readySet=connSet;
-         FD_SET(mouse_table[1].fd,&readySet);
+      text_mode = is_text_console();
+      if (!text_mode && !option.repeater) {
+         close(mouse_table[i].fd);
+         wait_text_console();
+         /* reopen, reinit (the function is only used if we have one mouse device) */
+         if ((mouse_table[i].fd = open(opt_dev, O_RDWR)) < 0)
+            gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN,opt_dev);
+         if (m_type->init)
+            m_type->init(mouse_table[i].fd, m_type->flags, m_type, 
+                         mouse_argc[1], mouse_argv[1]);
+         maxfd = max(maxfd, mouse_table[1].fd);
+         readySet = connSet;
+         FD_SET(mouse_table[1].fd, &readySet);
          continue; /* reselect */
       }
-      }
 
 /*....................................... got mouse, process event */
 /*
@@ -1066,16 +864,16 @@
          which_mouse=mouse_table+i; /* used to access options */
          if (FD_ISSET(which_mouse->fd,&selSet)) {
             FD_CLR(which_mouse->fd,&selSet); pending--;
-            if (processMouse(which_mouse->fd, &event, m_type, kd_mode))
-               /* pass it to the client, if any
-                * or to the default handler, if any
+            if (processMouse(which_mouse->fd, &event, m_type, text_mode)) {
+               /* pass it to the client or to the default handler,
                 * or to the selection handler
-                */ /* FIXME -- check event.vc */
-               /* can't we please rewrite the following a bit nicer?*/
-               (cinfo[event.vc] && do_client(cinfo[event.vc], &event))
-               || (cinfo[0]        && do_client(cinfo[0],        &event))
-               ||  do_selection(&event);
+                */
+               if (event.vc > MAX_VC) event.vc = 0;
+               if (event.vc == 0 || !cinfo[event.vc] || !do_client(cinfo[event.vc], &event))
+                  if (!cinfo[0] || !do_client(cinfo[0], &event))
+                     do_selection(&event, opt_three);
             }
+         }
       }
 
       /*..................... got connection, process it */
diff -Nru a/src/gpn.c b/src/gpn.c
--- a/src/gpn.c	2004-08-10 01:17:57 -05:00
+++ b/src/gpn.c	2004-08-10 01:17:57 -05:00
@@ -30,119 +30,22 @@
 #include <ctype.h>         /* isdigit */
 #include <signal.h>
 #include <stdarg.h>        /* Log uses it */
-#include <errno.h>
 #include <unistd.h>        /* getopt(),symlink() */
-#include <sys/stat.h>      /* mkdir()  */
-#include <sys/param.h>
-#include <sys/time.h>      /* timeval */
-#include <sys/wait.h>      /* wait() */
-#include <sys/types.h>     /* socket() */
-#include <sys/socket.h>    /* socket() */
-#include <sys/un.h>        /* struct sockaddr_un */
-#include <asm/types.h>     /* __u32  */
-
-#ifdef	SIGTSTP		/* true if BSD system */
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#endif
-
-#ifndef HAVE___U32
-# ifndef _I386_TYPES_H /* /usr/include/asm/types.h */
-typedef unsigned int __u32;
-# endif
-#endif
 
 #include "headers/message.h"
 #include "headers/gpmInt.h"
 #include "headers/gpm.h"
-
-extern int errno;
-
-/*===================================================================*/
-/* octal digit */
-static int isodigit(const unsigned char c)
-{
-   return ((c & ~7) == '0');
-}
-
-/* routine to convert digits from octal notation (Andries Brouwer) */
-static int getsym(const unsigned char *p0, unsigned char *res)
-{
-   const unsigned char *p = p0;
-   char c;
-
-   c = *p++;
-   if (c == '\\' && *p) {
-      c = *p++;
-      if (isodigit(c)) {
-         c -= '0';
-         if (isodigit(*p)) c = 8*c + (*p++ - '0');
-         if (isodigit(*p)) c = 8*c + (*p++ - '0');
-      }
-   }
-   *res = c;
-   return (p - p0);
-}
-
-/* description missing! FIXME */
-int loadlut(char *charset)
-{
-   int i, c, fd;
-   unsigned char this, next;
-   static __u32 long_array[9]={
-      0x05050505, /* ugly, but preserves alignment */
-      0x00000000, /* control chars     */
-      0x00000000, /* digits            */
-      0x00000000, /* uppercase and '_' */
-      0x00000000, /* lowercase         */
-      0x00000000, /* Latin-1 control   */
-      0x00000000, /* Latin-1 misc      */
-      0x00000000, /* Latin-1 uppercase */
-      0x00000000  /* Latin-1 lowercase */
-   };
-
-
-#define inwordLut (long_array+1)
-
-   for (i=0; charset[i]; ) {
-      i += getsym(charset+i, &this);
-      if (charset[i] == '-' && charset[i + 1] != '\0')
-         i += getsym(charset+i+1, &next) + 1;
-      else
-         next = this;
-      for (c = this; c <= next; c++)
-         inwordLut[c>>5] |= 1 << (c&0x1F);
-   }
-  
-   if ((fd=open(option.consolename, O_WRONLY)) < 0) {
-      /* try /dev/console, if /dev/tty0 failed -- is that really senseful ??? */
-      free(option.consolename); /* allocated by main */
-      if((option.consolename=malloc(strlen(GPM_SYS_CONSOLE)+1)) == NULL)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM);
-      strcpy(option.consolename,GPM_SYS_CONSOLE);
-     
-      if ((fd=open(option.consolename, O_WRONLY)) < 0) gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN_CON);
-   }
-   if (ioctl(fd, TIOCLINUX, &long_array) < 0) { /* fd <0 is checked */
-      if (errno==EPERM && getuid())
-         gpm_report(GPM_PR_WARN,GPM_MESS_ROOT); /* why do we still continue?*/
-      else if (errno==EINVAL)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_CSELECT);
-   }
-   close(fd);
-
-   return 0;
-}
+#include "headers/console.h"
 
 /* usage: display for usage informations */
 int usage(char *whofailed)
 {
    if (whofailed) {
-      gpm_report(GPM_PR_ERR,GPM_MESS_SPEC_ERR,whofailed,option.progname);
+      gpm_report(GPM_PR_ERR, GPM_MESS_SPEC_ERR, whofailed, option.progname);
       return 1;
    }
-   printf(GPM_MESS_USAGE,option.progname, DEF_ACCEL, DEF_BAUD, DEF_SEQUENCE,
-   DEF_DELTA, DEF_TIME, DEF_LUT,DEF_SCALE, DEF_SAMPLE, DEF_TYPE);
+   printf(GPM_MESS_USAGE, option.progname, DEF_ACCEL, DEF_BAUD, DEF_SEQUENCE,
+          DEF_DELTA, DEF_TIME, DEF_LUT, DEF_SCALE, DEF_SAMPLE, DEF_TYPE);
    return 1;
 }
 
@@ -242,9 +145,9 @@
    while ((opt = getopt(argc, argv, options)) != -1) {
       switch (opt) {
          case 'a': opt_accel = atoi(optarg);             break;
-         case 'A': opt_aged++;
+         case 'A': sel_opts.aged = 1;
                    if (optarg)
-                     opt_age_limit = atoi(optarg);       break;
+                      sel_opts.age_limit = atoi(optarg); break;
          case 'b': opt_baud = atoi(optarg);              break;
          case 'B': opt_sequence = optarg;                break;
          case 'd': opt_delta = atoi(optarg);             break;
@@ -253,7 +156,7 @@
          case 'h': exit(usage(NULL));
          case 'i': opt_time=atoi(optarg);                break;
          case 'k': check_kill();                         break;
-         case 'l': opt_lut = optarg;                     break;
+         case 'l': console.charset = optarg;             break;
          case 'm': add_mouse(GPM_ADD_DEVICE,optarg);     
                    opt_dev = optarg;                     break; /* GO AWAY!*/
          case 'M': opt_double++; option.repeater++;
@@ -263,7 +166,7 @@
          case 'o': add_mouse(GPM_ADD_OPTIONS,optarg);
                    gpm_report(GPM_PR_DEBUG,"options: %s",optarg);
                    opt_options = optarg;                 break; /* GO AWAY */
-         case 'p': opt_ptrdrag = 0;                      break;
+         case 'p': sel_opts.ptrdrag = 0;                 break;
          case 'r':
             /* being called responsiveness, I must take the inverse */
             opt_scale=atoi(optarg);
diff -Nru a/src/headers/console.h b/src/headers/console.h
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/src/headers/console.h	2004-08-10 01:17:57 -05:00
@@ -0,0 +1,52 @@
+/*
+ * console.h - GPM console and selection/paste handling
+ *
+ * Copyright (C) 2003  Dmitry Torokhov <dtor@xxxxxxx>
+ *
+ *   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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ ********/
+
+#ifndef __GPM_CONSOLE_H_
+#define __GPM_CONSOLE_H_
+
+struct gpm_console {
+   char  *device;
+   char  *charset;
+   int   max_x, max_y;
+};
+
+struct sel_options {
+   int      aged;
+   int      age_limit;
+   int      ptrdrag;
+};
+
+struct Gpm_Event;
+
+extern struct sel_options sel_opts; /* only one exists */
+extern struct gpm_console console;  /* same */
+
+int   open_console(int mode);
+int   is_text_console(void);
+void  wait_text_console(void);
+void  refresh_console_size(void);
+int   is_console_owner(int vc, uid_t uid);
+int   get_console_state(unsigned char *shift_state);
+void  console_load_lut(void);
+
+void  do_selection(struct Gpm_Event *event, int three_button_mode);
+void  selection_disable_paste(void);
+
+#endif /* __GPM_CONSOLE_H_ */
diff -Nru a/src/headers/gpmInt.h b/src/headers/gpmInt.h
--- a/src/headers/gpmInt.h	2004-08-10 01:17:57 -05:00
+++ b/src/headers/gpmInt.h	2004-08-10 01:17:57 -05:00
@@ -164,9 +164,6 @@
 
 extern struct mouse_features mouse_table[3], *which_mouse; /*the current one*/
 
-// looks unused; delete
-//typedef struct Opt_struct_type {int a,B,d,i,p,r,V,A;} Opt_struct_type;
-
 /* this is not very clean, actually, but it works fine */
 #define opt_type     (which_mouse->opt_type)
 #define opt_dev      (which_mouse->opt_dev)
@@ -187,12 +184,9 @@
 
 /* the other variables */
 
-extern char *opt_lut;
-extern int opt_test, opt_ptrdrag;
+extern int opt_test;
 extern int opt_kill;
 extern int opt_kernel, opt_explicittype;
-extern int opt_aged;
-extern time_t opt_age_limit;
 extern char *opt_special;
 extern int opt_rawrep;
 extern int fifofd;
@@ -200,8 +194,6 @@
 
 extern Gpm_Type *repeated_type;
 extern Gpm_Type mice[];             /* where the hell are the descriptions...*/
-extern struct winsize win;
-extern int maxx, maxy;
 extern Gpm_Cinfo *cinfo[MAX_VC+1];
 
 /* new variables <CLEAN> */
@@ -224,14 +216,12 @@
    int run_status;            /* startup/daemon/debug */
    char *progname;            /* hopefully gpm ;) */
    struct micetab *micelist;  /* mice and their options */
-   char *consolename;         /* /dev/tty0 || /dev/vc/0 */
 };
 
 /* global variables */
 struct options option;        /* one should be enough for us */
 
 /* new variables </CLEAN> */
-
 
 /*....................................... Prototypes */
          /* server_tools.c */
diff -Nru a/src/headers/message.h b/src/headers/message.h
--- a/src/headers/message.h	2004-08-10 01:17:57 -05:00
+++ b/src/headers/message.h	2004-08-10 01:17:57 -05:00
@@ -196,7 +196,7 @@
 
 /* warnings */
 #define GPM_MESS_REQUEST_ON         "Request on vc %i > %i"
-#define GPM_MESS_FAILED_CONNECT     "Failed gpm connect attempt by uid %d for vc %s"
+#define GPM_MESS_FAILED_CONNECT     "Failed gpm connect attempt by uid %d for vc %d"
 #define GPM_MESS_ZERO_SCREEN_DIM    "zero screen dimension, assuming 80x25"
 #define GPM_MESS_STRANGE_DATA       "Data on strange file descriptor %d"
 #define GPM_MESS_RESIZING           "%s pid %i is resizing :-)"
diff -Nru a/src/lib/liblow.c b/src/lib/liblow.c
--- a/src/lib/liblow.c	2004-08-10 01:17:57 -05:00
+++ b/src/lib/liblow.c	2004-08-10 01:17:57 -05:00
@@ -80,6 +80,8 @@
 int gpm_consolefd=-1;  /* used to invoke ioctl() */
 int gpm_morekeys=0;
 
+static char *consolename;
+
 int gpm_convert_event(unsigned char *mdata, Gpm_Event *ePtr);
 
 /*----------------------------------------------------------------------------*
@@ -192,7 +194,6 @@
    char *tty = NULL;
    char *term = NULL;
    int i;
-   extern struct options option;
    static int checked_con = 0;
    struct sockaddr_un addr;
    struct winsize win;
@@ -214,7 +215,7 @@
 
    /* check whether we know what name the console is: what's with the lib??? */
    if(checked_con == 0) {
-      option.consolename = Gpm_get_console();
+      consolename = Gpm_get_console();
       checked_con++;
    }   
 
@@ -240,17 +241,17 @@
    if (new->next)
       conn->vc=new->next->info.vc; /* inherit */
    else {
-      if (!option.consolename) {
-         gpm_report(GPM_PR_ERR,"option.consolename null");
+      if (consolename) {
+         gpm_report(GPM_PR_ERR, "consolename is null");
          goto err;
-      }   
+      }
       conn->vc=0;                 /* default handler */
       if (flag > 0) {  /* forced vc number */
          conn->vc=flag;
-         if((tty = malloc(strlen(option.consolename)+Gpm_cnt_digits(flag))) == NULL)
+         if((tty = malloc(strlen(consolename)+Gpm_cnt_digits(flag))) == NULL)
             gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM);
-         memcpy(tty,option.consolename,strlen(option.consolename)-1);
-         sprintf(&tty[strlen(option.consolename)-1],"%i",flag);
+         memcpy(tty,consolename,strlen(consolename)-1);
+         sprintf(&tty[strlen(consolename)-1],"%i",flag);
       } else { /* use your current vc */ 
          if (isatty(0)) tty = ttyname(0);             /* stdin */
          if (!tty && isatty(1)) tty = ttyname(1);     /* stdout */
@@ -260,13 +261,13 @@
             goto err;
          }   
          /* do we really need this check ? */
-         if(strncmp(tty,option.consolename,strlen(option.consolename)-1)
-            || !isdigit(tty[strlen(option.consolename)-1])) {
-            gpm_report(GPM_PR_ERR,"strncmp/isdigit/option.consolename failed");
+         if(strncmp(tty,consolename,strlen(consolename)-1)
+            || !isdigit(tty[strlen(consolename)-1])) {
+            gpm_report(GPM_PR_ERR,"strncmp/isdigit/consolename failed");
             goto err;
          }
           
-         conn->vc=atoi(&tty[strlen(option.consolename)-1]);
+         conn->vc=atoi(&tty[strlen(consolename)-1]);
       }
 
       if (gpm_consolefd == -1)
@@ -372,11 +373,11 @@
   /*....................................... Error: free all memory */
    err:
    gpm_report(GPM_PR_ERR,"Oh, oh, it's an error! possibly I die! ");
-   while(gpm_stack) {
+   while (gpm_stack) {
       new=gpm_stack->next;
       free(gpm_stack);
       gpm_stack=new;
-   };
+   }
    if (gpm_fd>=0) close(gpm_fd);
    if (sock_name) {
       unlink(sock_name);
diff -Nru a/src/mice.c b/src/mice.c
--- a/src/mice.c	2004-08-10 01:17:57 -05:00
+++ b/src/mice.c	2004-08-10 01:17:57 -05:00
@@ -72,6 +72,7 @@
 
 
 #include "headers/gpmInt.h"
+#include "headers/console.h"
 #include "headers/twiddler.h"
 #include "headers/synaptics.h"
 #include "headers/message.h"
@@ -336,12 +337,12 @@
    x = ((data[2]<<7) | data[1])-SUMMA_BORDER;
    if (x<0) x=0;
    if (x>summamaxx) x=summamaxx;
-   state->x = (x * win.ws_col / summamaxx);
+   state->x = (x * console.max_x / summamaxx);
    realposx = (x * 16383 / summamaxx);
 
    y = ((data[4]<<7) | data[3])-SUMMA_BORDER;
    if (y<0) y=0; if (y>summamaxy) y=summamaxy;
-   state->y = 1 + y * (win.ws_row-1)/summamaxy;
+   state->y = 1 + y * (console.max_y-1)/summamaxy;
    realposy = y * 16383 / summamaxy;  
 
    state->buttons=
@@ -880,8 +881,8 @@
    if (WacomAbsoluteWanted) { /* Absolute Mode */
       if (x>wmaxx) x=wmaxx; if (x<0) x=0;
       if (y>wmaxy) y=wmaxy; if (y<0) y=0;
-      state->x  = (x * win.ws_col / wmaxx);
-      state->y  = (y * win.ws_row / wmaxy);
+      state->x  = (x * console.max_x / wmaxx);
+      state->y  = (y * console.max_y / wmaxy);
        
       realposx = (x / wmaxx); /* this two lines come from the summa driver. */
       realposy = (y / wmaxy); /* they seem to be buggy (always give zero).  */
@@ -891,8 +892,8 @@
       if( abs(x-ox)>(wmaxx/wcmodell[WacomModell].treshold) 
        || abs(y-oy)>(wmaxy/wcmodell[WacomModell].treshold) ) ox=x; oy=y;
 
-      state->dx= (x-ox) / (wmaxx / win.ws_col / wcmodell[WacomModell].treshold);
-      state->dy= (y-oy) / (wmaxy / win.ws_row / wcmodell[WacomModell].treshold);
+      state->dx= (x-ox) / (wmaxx / console.max_x / wcmodell[WacomModell].treshold);
+      state->dy= (y-oy) / (wmaxy / console.max_y / wcmodell[WacomModell].treshold);
    }
 
    ox=x; oy=y;    
@@ -934,12 +935,12 @@
    state->dx = 0; state->dy = 0;
 
    state->x = x < CAL_X_MIN ? 0
-     : x > CAL_X_MAX ? win.ws_col+1
-     : (long)(x-CAL_X_MIN) * (long)(win.ws_col-1) / CAL_X_SIZE+2;
+     : x > CAL_X_MAX ? console.max_x+1
+     : (long)(x-CAL_X_MIN) * (long)(console.max_x-1) / CAL_X_SIZE+2;
 
-   state->y = y < CAL_Y_MIN ? win.ws_row + 1
+   state->y = y < CAL_Y_MIN ? console.max_y + 1
      : y > CAL_Y_MAX ? 0
-     : (long)(CAL_Y_MAX-y) * (long)win.ws_row / CAL_Y_SIZE + 1;
+     : (long)(CAL_Y_MAX-y) * (long)console.max_y / CAL_Y_SIZE + 1;
 
    realposx = x < CAL_X_MIN ? 0
      : x > CAL_X_MAX ? 16384
@@ -1004,14 +1005,14 @@
    state->x = x < NCR_LEFT_X
              ? 0
              : x > NCR_RIGHT_X
-               ? win.ws_col+1
-               : (long)(x-NCR_LEFT_X) * (long)(win.ws_col-1) / NCR_DELTA_X+2;
+               ? console.max_x+1
+               : (long)(x-NCR_LEFT_X) * (long)(console.max_x-1) / NCR_DELTA_X+2;
 
    state->y = y < NCR_BOTTOM_Y
-             ? win.ws_row + 1
+             ? console.max_y + 1
              : y > NCR_TOP_Y
           ? 0
-          : (long)(NCR_TOP_Y-y) * (long)win.ws_row / NCR_DELTA_Y + 1;
+          : (long)(NCR_TOP_Y-y) * (long)console.max_y / NCR_DELTA_Y + 1;
 
    realposx = x < NCR_LEFT_X
              ? 0
@@ -1221,8 +1222,8 @@
    static int upx, upy;            /* keep track of last finger-up place */
    static struct timeval uptv, tv; /* time of last up, and down events */
 
-   #define REAL_TO_XCELL(x) (x * win.ws_col / 0x3FFF)
-   #define REAL_TO_YCELL(y) (y * win.ws_row / 0x3FFF)
+   #define REAL_TO_XCELL(x) (x * console.max_x / 0x3FFF)
+   #define REAL_TO_YCELL(y) (y * console.max_y / 0x3FFF)
 
    #define GET_TIME(tv) (gettimeofday(&tv, (struct timezone *)NULL))
    #define DIF_TIME(t1,t2) ((t2.tv_sec -t1.tv_sec) *1000+ \
@@ -1302,8 +1303,8 @@
    static struct timeval uptv, tv; /* time of last up, and down events */
    int timediff;
     
-   #define REAL_TO_XCELL(x) (x * win.ws_col / 0x3FFF)
-   #define REAL_TO_YCELL(y) (y * win.ws_row / 0x3FFF)
+   #define REAL_TO_XCELL(x) (x * console.max_x / 0x3FFF)
+   #define REAL_TO_YCELL(y) (y * console.max_y / 0x3FFF)
     
    #define GET_TIME(tv) (gettimeofday(&tv, (struct timezone *)NULL))
    #define DIF_TIME(t1,t2) ((t2.tv_sec -t1.tv_sec) *1000+ \
@@ -1456,11 +1457,11 @@
    int x, y, pressure;
 
    x = ((data[4] & 0x1f) << 12) | ((data[3] & 0x3f) << 6) | (data[2] & 0x3f);
-   state->x = x * win.ws_col / (wizardpad_width * 40);
+   state->x = x * console.max_x / (wizardpad_width * 40);
    realposx = x * 16383 / (wizardpad_width * 40);
 
    y = ((data[7] & 0x1f) << 12) | ((data[6] & 0x3f) << 6) | (data[5] & 0x3f);
-   state->y = win.ws_row - y * win.ws_row / (wizardpad_height * 40) - 1;
+   state->y = console.max_y - y * console.max_y / (wizardpad_height * 40) - 1;
    realposy = 16383 - y * 16383 / (wizardpad_height * 40) - 1;  
 
    pressure = ((data[9] & 0x0f) << 4) | (data[8] & 0x0f);
diff -Nru a/src/report.c b/src/report.c
--- a/src/report.c	2004-08-10 01:17:57 -05:00
+++ b/src/report.c	2004-08-10 01:17:57 -05:00
@@ -31,6 +31,7 @@
 
 #include "headers/gpmInt.h"
 #include "headers/message.h"
+#include "headers/console.h"
 
 /*
  * gpm_report
@@ -70,7 +71,7 @@
 
 void gpm_report(int line, char *file, int stat, char *text, ... )
 {
-   FILE *console = NULL;
+   FILE *f = NULL;
    va_list ap;
 
    va_start(ap,text);
@@ -138,11 +139,11 @@
                syslog(LOG_DAEMON | LOG_WARNING, GPM_STRING_WARN);
                vsyslog(LOG_DAEMON | LOG_WARNING, text, ap);
 #endif               
-               if((console = fopen(GPM_SYS_CONSOLE,"a")) != NULL) {
-                  fprintf(console,GPM_STRING_WARN);
-                  vfprintf(console,text,ap);
-                  fprintf(console,"\n");
-                  fclose(console);
+               if ((f = fopen(GPM_SYS_CONSOLE, "a")) != NULL) {
+                  fprintf(f, GPM_STRING_WARN);
+                  vfprintf(f, text, ap);
+                  fprintf(f, "\n");
+                  fclose(f);
                }   
                break;
  
@@ -151,18 +152,18 @@
                syslog(LOG_DAEMON | LOG_ERR, GPM_STRING_ERR);
                vsyslog(LOG_DAEMON | LOG_ERR, text, ap);
 #endif               
-               if((console = fopen(GPM_SYS_CONSOLE,"a")) != NULL) {
-                  fprintf(console,GPM_STRING_ERR);
-                  vfprintf(console,text,ap);
-                  fprintf(console,"\n");
-                  fclose(console);
+               if ((f = fopen(GPM_SYS_CONSOLE, "a")) != NULL) {
+                  fprintf(f, GPM_STRING_ERR);
+                  vfprintf(f, text, ap);
+                  fprintf(f, "\n");
+                  fclose(f);
                }
 
-               if((console = fopen(option.consolename,"a")) != NULL) {
-                  fprintf(console,GPM_STRING_ERR);
-                  vfprintf(console,text,ap);
-                  fprintf(console,"\n");
-                  fclose(console);
+               if ((f = fopen(console.device, "a")) != NULL) {
+                  fprintf(f, GPM_STRING_ERR);
+                  vfprintf(f, text, ap);
+                  fprintf(f, "\n");
+                  fclose(f);
                }
                break;
 
@@ -184,24 +185,24 @@
       case GPM_RUN_DEBUG:
          switch(stat) {
             case GPM_STAT_INFO:
-               console = stdout;
-               fprintf(console,GPM_STRING_INFO); break;
+               f = stdout;
+               fprintf(f, GPM_STRING_INFO); break;
             case GPM_STAT_WARN:
-               console = stderr;
-               fprintf(console,GPM_STRING_WARN); break;
+               f = stderr;
+               fprintf(f, GPM_STRING_WARN); break;
             case GPM_STAT_ERR:
-               console = stderr;
-               fprintf(console,GPM_STRING_ERR); break;
+               f = stderr;
+               fprintf(f, GPM_STRING_ERR); break;
             case GPM_STAT_DEBUG:
-               console = stderr;
-               fprintf(console,GPM_STRING_DEBUG); break;
+               f = stderr;
+               fprintf(f, GPM_STRING_DEBUG); break;
             case GPM_STAT_OOPS:
-               console = stderr;
-               fprintf(console,GPM_STRING_OOPS); break;
+               f = stderr;
+               fprintf(f, GPM_STRING_OOPS); break;
          }
 
-         vfprintf(console,text,ap);
-         fprintf(console,"\n");
+         vfprintf(f, text, ap);
+         fprintf(f, "\n");
          
          if(stat == GPM_STAT_OOPS) exit(1);
 
diff -Nru a/src/special.c b/src/special.c
--- a/src/special.c	2004-08-10 01:17:57 -05:00
+++ b/src/special.c	2004-08-10 01:17:57 -05:00
@@ -37,6 +37,7 @@
 #include <sys/param.h>
 
 #include "headers/gpmInt.h"
+#include "headers/console.h"
 
 /*
  * This function is only called at button press, to avoid unnecessary
@@ -78,7 +79,7 @@
     return 1;
 
   /* devfs change */
-  consolef=fopen(option.consolename,"w");
+  consolef = fopen(console.device, "w");
   if (!consolef) consolef=stderr;
   if (event->type & GPM_TRIPLE) /* just triggered: make noise and return */
     {
@@ -153,7 +154,7 @@
     case 0: /* child */
       close(0); close(1); close(2);
       open(GPM_NULL_DEV,O_RDONLY); /* stdin  */
-      open(option.consolename,O_WRONLY); /* stdout */
+      open(console.device, O_WRONLY); /* stdout */
       dup(1);                     /* stderr */
       for (i=3;i<OPEN_MAX; i++) close(i);
       execl("/bin/sh","sh","-c",command,(char *)NULL);
diff -Nru a/src/startup.c b/src/startup.c
--- a/src/startup.c	2004-08-10 01:17:57 -05:00
+++ b/src/startup.c	2004-08-10 01:17:57 -05:00
@@ -34,6 +34,7 @@
 
 #include "headers/gpmInt.h"
 #include "headers/message.h"
+#include "headers/console.h"
 
 /* what todo atexit */
 static void gpm_exited(void)
@@ -67,14 +68,14 @@
    option.run_status    = GPM_RUN_STARTUP;      /* 10,9,8,... let's go */
    option.autodetect    = 0;                    /* no mouse autodection */
    option.progname      = argv[0];              /* who we are */
-   option.consolename   = Gpm_get_console();    /* get consolename */
 
    /* basic2: are not necessary for oops()ing, if not root */
    option.no_mice       = 0;                    /* counts -m + -t */
    option.micelist      = NULL;                 /* no mice found yet */
    option.repeater      = 0;                    /* repeat data */
    option.repeater_type = NULL;                 /* type of */
-
+   
+   console.device       = Gpm_get_console();    /* get consolename */
 
    cmdline(argc, argv);                         /* parse command line */
 
@@ -87,8 +88,9 @@
    /****************** OLD CODE from gpn.c ***********************/
    
    openlog(option.progname, LOG_PID,
-                  option.run_status != GPM_RUN_DEBUG ? LOG_DAEMON : LOG_USER);
-   loadlut(opt_lut);
+           option.run_status != GPM_RUN_DEBUG ? LOG_DAEMON : LOG_USER);
+
+   console_load_lut();
 
    if (option.repeater) {
       if(mkfifo(GPM_NODE_FIFO,0666) && errno!=EEXIST)
diff -Nru a/src/twiddler.c b/src/twiddler.c
--- a/src/twiddler.c	2004-08-10 01:17:57 -05:00
+++ b/src/twiddler.c	2004-08-10 01:17:57 -05:00
@@ -54,6 +54,7 @@
 #include "headers/gpm.h"
 #include "headers/gpmInt.h"
 #include "headers/message.h"
+#include "headers/console.h"
 #include "headers/twiddler.h"
 
 
@@ -134,17 +135,6 @@
    int (*fun)(char *string);
 };
 
-
-/* The same silly function as in gpm.c */
-static inline int open_console(const int mode)
-{
-   int fd;
-   extern struct options option;
-   if ((fd=open(option.consolename, mode)) < 0) gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN,option.consolename);
-   return fd;
-}
-
-
 /*===================================================================*/
 /*              This part deals with pushing keys                  */
 
@@ -175,7 +165,7 @@
 int twiddler_exec(char *s)
 {
    int pid;
-   extern struct options option;
+
    switch(pid=fork()) {
       case -1: return -1;
       case 0:
@@ -184,7 +174,7 @@
          close(2); /* very rude! */
       
          open(GPM_NULL_DEV,O_RDONLY);
-         open(option.consolename,O_WRONLY);
+         open(console.device, O_WRONLY);
          dup(1);
          execl("/bin/sh", "sh", "-c", s, NULL);
          exit(1); /* shouldn't happen */
_______________________________________________
gpm mailing list
gpm@xxxxxxxxxxxxxx
http://lists.linux.it/listinfo/gpm

[Index of Archives]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Gimp]     [Yosemite News]