diff src/video/fbcon/SDL_fbevents.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
line wrap: on
line diff
--- a/src/video/fbcon/SDL_fbevents.c	Mon May 29 03:53:21 2006 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Mon May 29 04:04:35 2006 +0000
@@ -63,7 +63,7 @@
 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
 static SDLKey keymap[128];
 static Uint16 keymap_temp[128]; /* only used at startup */
-static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym);
+static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym);
 
 /* Ugh, we have to duplicate the kernel's keysym mapping code...
    Oh, it's not so bad. :-)
@@ -71,7 +71,7 @@
    FIXME: Add keyboard LED handling code
  */
 static void
-FB_vgainitkeymaps (int fd)
+FB_vgainitkeymaps(int fd)
 {
     struct kbentry entry;
     int map, i;
@@ -83,21 +83,21 @@
 
     /* Load all the keysym mappings */
     for (map = 0; map < NUM_VGAKEYMAPS; ++map) {
-        SDL_memset (vga_keymap[map], 0, NR_KEYS * sizeof (Uint16));
+        SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16));
         for (i = 0; i < NR_KEYS; ++i) {
             entry.kb_table = map;
             entry.kb_index = i;
-            if (ioctl (fd, KDGKBENT, &entry) == 0) {
+            if (ioctl(fd, KDGKBENT, &entry) == 0) {
                 /* fill keytemp. This replaces SDL_fbkeys.h */
                 if ((map == 0) && (i < 128)) {
                     keymap_temp[i] = entry.kb_value;
                 }
                 /* The "Enter" key is a special case */
                 if (entry.kb_value == K_ENTER) {
-                    entry.kb_value = K (KT_ASCII, 13);
+                    entry.kb_value = K(KT_ASCII, 13);
                 }
                 /* Handle numpad specially as well */
-                if (KTYP (entry.kb_value) == KT_PAD) {
+                if (KTYP(entry.kb_value) == KT_PAD) {
                     switch (entry.kb_value) {
                     case K_P0:
                     case K_P1:
@@ -113,34 +113,34 @@
                         vga_keymap[map][i] += '0';
                         break;
                     case K_PPLUS:
-                        vga_keymap[map][i] = K (KT_ASCII, '+');
+                        vga_keymap[map][i] = K(KT_ASCII, '+');
                         break;
                     case K_PMINUS:
-                        vga_keymap[map][i] = K (KT_ASCII, '-');
+                        vga_keymap[map][i] = K(KT_ASCII, '-');
                         break;
                     case K_PSTAR:
-                        vga_keymap[map][i] = K (KT_ASCII, '*');
+                        vga_keymap[map][i] = K(KT_ASCII, '*');
                         break;
                     case K_PSLASH:
-                        vga_keymap[map][i] = K (KT_ASCII, '/');
+                        vga_keymap[map][i] = K(KT_ASCII, '/');
                         break;
                     case K_PENTER:
-                        vga_keymap[map][i] = K (KT_ASCII, '\r');
+                        vga_keymap[map][i] = K(KT_ASCII, '\r');
                         break;
                     case K_PCOMMA:
-                        vga_keymap[map][i] = K (KT_ASCII, ',');
+                        vga_keymap[map][i] = K(KT_ASCII, ',');
                         break;
                     case K_PDOT:
-                        vga_keymap[map][i] = K (KT_ASCII, '.');
+                        vga_keymap[map][i] = K(KT_ASCII, '.');
                         break;
                     default:
                         break;
                     }
                 }
                 /* Do the normal key translation */
-                if ((KTYP (entry.kb_value) == KT_LATIN) ||
-                    (KTYP (entry.kb_value) == KT_ASCII) ||
-                    (KTYP (entry.kb_value) == KT_LETTER)) {
+                if ((KTYP(entry.kb_value) == KT_LATIN) ||
+                    (KTYP(entry.kb_value) == KT_ASCII) ||
+                    (KTYP(entry.kb_value) == KT_LETTER)) {
                     vga_keymap[map][i] = entry.kb_value;
                 }
             }
@@ -149,44 +149,44 @@
 }
 
 int
-FB_InGraphicsMode (_THIS)
+FB_InGraphicsMode(_THIS)
 {
     return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0));
 }
 
 int
-FB_EnterGraphicsMode (_THIS)
+FB_EnterGraphicsMode(_THIS)
 {
     struct termios keyboard_termios;
 
     /* Set medium-raw keyboard mode */
-    if ((keyboard_fd >= 0) && !FB_InGraphicsMode (this)) {
+    if ((keyboard_fd >= 0) && !FB_InGraphicsMode(this)) {
 
         /* Switch to the correct virtual terminal */
         if (current_vt > 0) {
             struct vt_stat vtstate;
 
-            if (ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) {
+            if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) {
                 saved_vt = vtstate.v_active;
             }
-            if (ioctl (keyboard_fd, VT_ACTIVATE, current_vt) == 0) {
-                ioctl (keyboard_fd, VT_WAITACTIVE, current_vt);
+            if (ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0) {
+                ioctl(keyboard_fd, VT_WAITACTIVE, current_vt);
             }
         }
 
         /* Set the terminal input mode */
-        if (tcgetattr (keyboard_fd, &saved_kbd_termios) < 0) {
-            SDL_SetError ("Unable to get terminal attributes");
+        if (tcgetattr(keyboard_fd, &saved_kbd_termios) < 0) {
+            SDL_SetError("Unable to get terminal attributes");
             if (keyboard_fd > 0) {
-                close (keyboard_fd);
+                close(keyboard_fd);
             }
             keyboard_fd = -1;
             return (-1);
         }
-        if (ioctl (keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) {
-            SDL_SetError ("Unable to get current keyboard mode");
+        if (ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) {
+            SDL_SetError("Unable to get current keyboard mode");
             if (keyboard_fd > 0) {
-                close (keyboard_fd);
+                close(keyboard_fd);
             }
             keyboard_fd = -1;
             return (-1);
@@ -197,59 +197,59 @@
             ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
         keyboard_termios.c_cc[VMIN] = 0;
         keyboard_termios.c_cc[VTIME] = 0;
-        if (tcsetattr (keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
-            FB_CloseKeyboard (this);
-            SDL_SetError ("Unable to set terminal attributes");
+        if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
+            FB_CloseKeyboard(this);
+            SDL_SetError("Unable to set terminal attributes");
             return (-1);
         }
         /* This will fail if we aren't root or this isn't our tty */
-        if (ioctl (keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) {
-            FB_CloseKeyboard (this);
-            SDL_SetError ("Unable to set keyboard in raw mode");
+        if (ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) {
+            FB_CloseKeyboard(this);
+            SDL_SetError("Unable to set keyboard in raw mode");
             return (-1);
         }
-        if (ioctl (keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) {
-            FB_CloseKeyboard (this);
-            SDL_SetError ("Unable to set keyboard in graphics mode");
+        if (ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) {
+            FB_CloseKeyboard(this);
+            SDL_SetError("Unable to set keyboard in graphics mode");
             return (-1);
         }
         /* Prevent switching the virtual terminal */
-        ioctl (keyboard_fd, VT_LOCKSWITCH, 1);
+        ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
     }
     return (keyboard_fd);
 }
 
 void
-FB_LeaveGraphicsMode (_THIS)
+FB_LeaveGraphicsMode(_THIS)
 {
-    if (FB_InGraphicsMode (this)) {
-        ioctl (keyboard_fd, KDSETMODE, KD_TEXT);
-        ioctl (keyboard_fd, KDSKBMODE, saved_kbd_mode);
-        tcsetattr (keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
+    if (FB_InGraphicsMode(this)) {
+        ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
+        ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode);
+        tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
         saved_kbd_mode = -1;
 
         /* Head back over to the original virtual terminal */
-        ioctl (keyboard_fd, VT_UNLOCKSWITCH, 1);
+        ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
         if (saved_vt > 0) {
-            ioctl (keyboard_fd, VT_ACTIVATE, saved_vt);
+            ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
         }
     }
 }
 
 void
-FB_CloseKeyboard (_THIS)
+FB_CloseKeyboard(_THIS)
 {
     if (keyboard_fd >= 0) {
-        FB_LeaveGraphicsMode (this);
+        FB_LeaveGraphicsMode(this);
         if (keyboard_fd > 0) {
-            close (keyboard_fd);
+            close(keyboard_fd);
         }
     }
     keyboard_fd = -1;
 }
 
 int
-FB_OpenKeyboard (_THIS)
+FB_OpenKeyboard(_THIS)
 {
     /* Open only if not already opened */
     if (keyboard_fd < 0) {
@@ -260,33 +260,33 @@
         /* Try to query for a free virtual terminal */
         tty0_fd = -1;
         for (i = 0; tty0[i] && (tty0_fd < 0); ++i) {
-            tty0_fd = open (tty0[i], O_WRONLY, 0);
+            tty0_fd = open(tty0[i], O_WRONLY, 0);
         }
         if (tty0_fd < 0) {
-            tty0_fd = dup (0);  /* Maybe stdin is a VT? */
+            tty0_fd = dup(0);   /* Maybe stdin is a VT? */
         }
-        ioctl (tty0_fd, VT_OPENQRY, &current_vt);
-        close (tty0_fd);
-        if ((geteuid () == 0) && (current_vt > 0)) {
+        ioctl(tty0_fd, VT_OPENQRY, &current_vt);
+        close(tty0_fd);
+        if ((geteuid() == 0) && (current_vt > 0)) {
             for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) {
                 char vtpath[12];
 
-                SDL_snprintf (vtpath, SDL_arraysize (vtpath), vcs[i],
-                              current_vt);
-                keyboard_fd = open (vtpath, O_RDWR, 0);
+                SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i],
+                             current_vt);
+                keyboard_fd = open(vtpath, O_RDWR, 0);
 #ifdef DEBUG_KEYBOARD
-                fprintf (stderr, "vtpath = %s, fd = %d\n",
-                         vtpath, keyboard_fd);
+                fprintf(stderr, "vtpath = %s, fd = %d\n",
+                        vtpath, keyboard_fd);
 #endif /* DEBUG_KEYBOARD */
 
                 /* This needs to be our controlling tty
                    so that the kernel ioctl() calls work
                  */
                 if (keyboard_fd >= 0) {
-                    tty0_fd = open ("/dev/tty", O_RDWR, 0);
+                    tty0_fd = open("/dev/tty", O_RDWR, 0);
                     if (tty0_fd >= 0) {
-                        ioctl (tty0_fd, TIOCNOTTY, 0);
-                        close (tty0_fd);
+                        ioctl(tty0_fd, TIOCNOTTY, 0);
+                        close(tty0_fd);
                     }
                 }
             }
@@ -295,31 +295,31 @@
             /* Last resort, maybe our tty is a usable VT */
             struct vt_stat vtstate;
 
-            keyboard_fd = open ("/dev/tty", O_RDWR);
+            keyboard_fd = open("/dev/tty", O_RDWR);
 
-            if (ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) {
+            if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) {
                 current_vt = vtstate.v_active;
             } else {
                 current_vt = 0;
             }
         }
 #ifdef DEBUG_KEYBOARD
-        fprintf (stderr, "Current VT: %d\n", current_vt);
+        fprintf(stderr, "Current VT: %d\n", current_vt);
 #endif
         saved_kbd_mode = -1;
 
         /* Make sure that our input is a console terminal */
         {
             int dummy;
-            if (ioctl (keyboard_fd, KDGKBMODE, &dummy) < 0) {
-                close (keyboard_fd);
+            if (ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0) {
+                close(keyboard_fd);
                 keyboard_fd = -1;
-                SDL_SetError ("Unable to open a console terminal");
+                SDL_SetError("Unable to open a console terminal");
             }
         }
 
         /* Set up keymap */
-        FB_vgainitkeymaps (keyboard_fd);
+        FB_vgainitkeymaps(keyboard_fd);
     }
     return (keyboard_fd);
 }
@@ -338,46 +338,46 @@
 } mouse_drv = MOUSE_NONE;
 
 void
-FB_CloseMouse (_THIS)
+FB_CloseMouse(_THIS)
 {
 #if SDL_INPUT_TSLIB
     if (ts_dev != NULL) {
-        ts_close (ts_dev);
+        ts_close(ts_dev);
         ts_dev = NULL;
         mouse_fd = -1;
     }
 #endif /* SDL_INPUT_TSLIB */
     if (mouse_fd > 0) {
-        close (mouse_fd);
+        close(mouse_fd);
     }
     mouse_fd = -1;
 }
 
 /* Returns processes listed in /proc with the desired name */
 static int
-find_pid (DIR * proc, const char *wanted_name)
+find_pid(DIR * proc, const char *wanted_name)
 {
     struct dirent *entry;
     int pid;
 
     /* First scan proc for the gpm process */
     pid = 0;
-    while ((pid == 0) && ((entry = readdir (proc)) != NULL)) {
-        if (isdigit (entry->d_name[0])) {
+    while ((pid == 0) && ((entry = readdir(proc)) != NULL)) {
+        if (isdigit(entry->d_name[0])) {
             FILE *status;
             char path[PATH_MAX];
             char name[PATH_MAX];
 
-            SDL_snprintf (path, SDL_arraysize (path), "/proc/%s/status",
-                          entry->d_name);
-            status = fopen (path, "r");
+            SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status",
+                         entry->d_name);
+            status = fopen(path, "r");
             if (status) {
                 name[0] = '\0';
-                fscanf (status, "Name: %s", name);
-                if (SDL_strcmp (name, wanted_name) == 0) {
-                    pid = SDL_atoi (entry->d_name);
+                fscanf(status, "Name: %s", name);
+                if (SDL_strcmp(name, wanted_name) == 0) {
+                    pid = SDL_atoi(entry->d_name);
                 }
-                fclose (status);
+                fclose(status);
             }
         }
     }
@@ -386,7 +386,7 @@
 
 /* Returns true if /dev/gpmdata is being written to by gpm */
 static int
-gpm_available (char *proto, size_t protolen)
+gpm_available(char *proto, size_t protolen)
 {
     int available;
     DIR *proc;
@@ -397,67 +397,66 @@
 
     /* Don't bother looking if the fifo isn't there */
 #ifdef DEBUG_MOUSE
-    fprintf (stderr, "testing gpm\n");
+    fprintf(stderr, "testing gpm\n");
 #endif
-    if (access (GPM_NODE_FIFO, F_OK) < 0) {
+    if (access(GPM_NODE_FIFO, F_OK) < 0) {
         return (0);
     }
 
     available = 0;
-    proc = opendir ("/proc");
+    proc = opendir("/proc");
     if (proc) {
         char raw_proto[10] = { '\0' };
         char repeat_proto[10] = { '\0' };
-        while (!available && (pid = find_pid (proc, "gpm")) > 0) {
-            SDL_snprintf (path, SDL_arraysize (path), "/proc/%d/cmdline",
-                          pid);
-            cmdline = open (path, O_RDONLY, 0);
+        while (!available && (pid = find_pid(proc, "gpm")) > 0) {
+            SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
+            cmdline = open(path, O_RDONLY, 0);
             if (cmdline >= 0) {
-                len = read (cmdline, args, sizeof (args));
+                len = read(cmdline, args, sizeof(args));
                 arg = args;
                 while (len > 0) {
-                    arglen = SDL_strlen (arg) + 1;
+                    arglen = SDL_strlen(arg) + 1;
 #ifdef DEBUG_MOUSE
-                    fprintf (stderr, "gpm arg %s len %d\n", arg, arglen);
+                    fprintf(stderr, "gpm arg %s len %d\n", arg, arglen);
 #endif
-                    if (SDL_strcmp (arg, "-t") == 0) {
+                    if (SDL_strcmp(arg, "-t") == 0) {
                         /* protocol string, keep it for later */
                         char *t, *s;
                         t = arg + arglen;
-                        s = SDL_strchr (t, ' ');
+                        s = SDL_strchr(t, ' ');
                         if (s)
                             *s = 0;
-                        SDL_strlcpy (raw_proto, t, SDL_arraysize (raw_proto));
+                        SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
                         if (s)
                             *s = ' ';
                     }
-                    if (SDL_strncmp (arg, "-R", 2) == 0) {
+                    if (SDL_strncmp(arg, "-R", 2) == 0) {
                         char *t, *s;
                         available = 1;
                         t = arg + 2;
-                        s = SDL_strchr (t, ' ');
+                        s = SDL_strchr(t, ' ');
                         if (s)
                             *s = 0;
-                        SDL_strlcpy (repeat_proto, t,
-                                     SDL_arraysize (repeat_proto));
+                        SDL_strlcpy(repeat_proto, t,
+                                    SDL_arraysize(repeat_proto));
                         if (s)
                             *s = ' ';
                     }
                     len -= arglen;
                     arg += arglen;
                 }
-                close (cmdline);
+                close(cmdline);
             }
         }
-        closedir (proc);
+        closedir(proc);
 
         if (available) {
-            if (SDL_strcmp (repeat_proto, "raw") == 0) {
-                SDL_strlcpy (proto, raw_proto, protolen);
+            if (SDL_strcmp(repeat_proto, "raw") == 0) {
+                SDL_strlcpy(proto, raw_proto, protolen);
             } else if (*repeat_proto) {
-                SDL_strlcpy (proto, repeat_proto, protolen);
+                SDL_strlcpy(proto, repeat_proto, protolen);
             } else {
-                SDL_strlcpy (proto, "msc", protolen);
+                SDL_strlcpy(proto, "msc", protolen);
             }
         }
     }
@@ -471,7 +470,7 @@
  *  device to see which mode it's actually in.
  */
 static int
-set_imps2_mode (int fd)
+set_imps2_mode(int fd)
 {
     /* If you wanted to control the mouse mode (and we do :)  ) ...
        Set IMPS/2 protocol:
@@ -485,7 +484,7 @@
     struct timeval tv;
     int retval = 0;
 
-    if (write (fd, &set_imps2, sizeof (set_imps2)) == sizeof (set_imps2)) {
+    if (write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2)) {
         /* Don't reset it, that'll clear IMPS/2 mode on some mice
            if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
            retval = 1;
@@ -494,13 +493,13 @@
     }
 
     /* Get rid of any chatter from the above */
-    FD_ZERO (&fdset);
-    FD_SET (fd, &fdset);
+    FD_ZERO(&fdset);
+    FD_SET(fd, &fdset);
     tv.tv_sec = 0;
     tv.tv_usec = 0;
-    while (select (fd + 1, &fdset, 0, 0, &tv) > 0) {
+    while (select(fd + 1, &fdset, 0, 0, &tv) > 0) {
         char temp[32];
-        read (fd, temp, sizeof (temp));
+        read(fd, temp, sizeof(temp));
     }
 
     return retval;
@@ -509,13 +508,13 @@
 
 /* Returns true if the mouse uses the IMPS/2 protocol */
 static int
-detect_imps2 (int fd)
+detect_imps2(int fd)
 {
     int imps2;
 
     imps2 = 0;
 
-    if (SDL_getenv ("SDL_MOUSEDEV_IMPS2")) {
+    if (SDL_getenv("SDL_MOUSEDEV_IMPS2")) {
         imps2 = 1;
     }
     if (!imps2) {
@@ -524,35 +523,35 @@
         struct timeval tv;
 
         /* Get rid of any mouse motion noise */
-        FD_ZERO (&fdset);
-        FD_SET (fd, &fdset);
+        FD_ZERO(&fdset);
+        FD_SET(fd, &fdset);
         tv.tv_sec = 0;
         tv.tv_usec = 0;
-        while (select (fd + 1, &fdset, 0, 0, &tv) > 0) {
+        while (select(fd + 1, &fdset, 0, 0, &tv) > 0) {
             char temp[32];
-            read (fd, temp, sizeof (temp));
+            read(fd, temp, sizeof(temp));
         }
 
         /* Query for the type of mouse protocol */
-        if (write (fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
+        if (write(fd, &query_ps2, sizeof(query_ps2)) == sizeof(query_ps2)) {
             Uint8 ch = 0;
 
             /* Get the mouse protocol response */
             do {
-                FD_ZERO (&fdset);
-                FD_SET (fd, &fdset);
+                FD_ZERO(&fdset);
+                FD_SET(fd, &fdset);
                 tv.tv_sec = 1;
                 tv.tv_usec = 0;
-                if (select (fd + 1, &fdset, 0, 0, &tv) < 1) {
+                if (select(fd + 1, &fdset, 0, 0, &tv) < 1) {
                     break;
                 }
             }
-            while ((read (fd, &ch, sizeof (ch)) == sizeof (ch)) &&
+            while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) &&
                    ((ch == 0xFA) || (ch == 0xAA)));
 
             /* Experimental values (Logitech wheelmouse) */
 #ifdef DEBUG_MOUSE
-            fprintf (stderr, "Last mouse mode: 0x%x\n", ch);
+            fprintf(stderr, "Last mouse mode: 0x%x\n", ch);
 #endif
             if ((ch == 3) || (ch == 4)) {
                 imps2 = 1;
@@ -563,28 +562,28 @@
 }
 
 int
-FB_OpenMouse (_THIS)
+FB_OpenMouse(_THIS)
 {
     int i;
     const char *mousedev;
     const char *mousedrv;
 
-    mousedrv = SDL_getenv ("SDL_MOUSEDRV");
-    mousedev = SDL_getenv ("SDL_MOUSEDEV");
+    mousedrv = SDL_getenv("SDL_MOUSEDRV");
+    mousedev = SDL_getenv("SDL_MOUSEDEV");
     mouse_fd = -1;
 
 #if SDL_INPUT_TSLIB
-    if (mousedrv && (SDL_strcmp (mousedrv, "TSLIB") == 0)) {
+    if (mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0)) {
         if (mousedev == NULL)
-            mousedev = SDL_getenv ("TSLIB_TSDEVICE");
+            mousedev = SDL_getenv("TSLIB_TSDEVICE");
         if (mousedev != NULL) {
-            ts_dev = ts_open (mousedev, 1);
-            if ((ts_dev != NULL) && (ts_config (ts_dev) >= 0)) {
+            ts_dev = ts_open(mousedev, 1);
+            if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
 #ifdef DEBUG_MOUSE
-                fprintf (stderr, "Using tslib touchscreen\n");
+                fprintf(stderr, "Using tslib touchscreen\n");
 #endif
                 mouse_drv = MOUSE_TSLIB;
-                mouse_fd = ts_fd (ts_dev);
+                mouse_fd = ts_fd(ts_dev);
                 return mouse_fd;
             }
         }
@@ -595,12 +594,12 @@
 
     /* ELO TOUCHSCREEN SUPPORT */
 
-    if (mousedrv && (SDL_strcmp (mousedrv, "ELO") == 0)) {
-        mouse_fd = open (mousedev, O_RDWR);
+    if (mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0)) {
+        mouse_fd = open(mousedev, O_RDWR);
         if (mouse_fd >= 0) {
-            if (eloInitController (mouse_fd)) {
+            if (eloInitController(mouse_fd)) {
 #ifdef DEBUG_MOUSE
-                fprintf (stderr, "Using ELO touchscreen\n");
+                fprintf(stderr, "Using ELO touchscreen\n");
 #endif
                 mouse_drv = MOUSE_ELO;
             }
@@ -622,56 +621,56 @@
         /* First try to use GPM in repeater mode */
         if (mouse_fd < 0) {
             char proto[10];
-            if (gpm_available (proto, SDL_arraysize (proto))) {
-                mouse_fd = open (GPM_NODE_FIFO, O_RDONLY, 0);
+            if (gpm_available(proto, SDL_arraysize(proto))) {
+                mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
                 if (mouse_fd >= 0) {
-                    if (SDL_strcmp (proto, "msc") == 0) {
+                    if (SDL_strcmp(proto, "msc") == 0) {
                         mouse_drv = MOUSE_MSC;
-                    } else if (SDL_strcmp (proto, "ps2") == 0) {
+                    } else if (SDL_strcmp(proto, "ps2") == 0) {
                         mouse_drv = MOUSE_PS2;
-                    } else if (SDL_strcmp (proto, "imps2") == 0) {
+                    } else if (SDL_strcmp(proto, "imps2") == 0) {
                         mouse_drv = MOUSE_IMPS2;
-                    } else if (SDL_strcmp (proto, "ms") == 0 ||
-                               SDL_strcmp (proto, "bare") == 0) {
+                    } else if (SDL_strcmp(proto, "ms") == 0 ||
+                               SDL_strcmp(proto, "bare") == 0) {
                         mouse_drv = MOUSE_MS;
-                    } else if (SDL_strcmp (proto, "bm") == 0) {
+                    } else if (SDL_strcmp(proto, "bm") == 0) {
                         mouse_drv = MOUSE_BM;
                     } else {
                         /* Unknown protocol... */
 #ifdef DEBUG_MOUSE
-                        fprintf (stderr,
-                                 "GPM mouse using unknown protocol = %s\n",
-                                 proto);
+                        fprintf(stderr,
+                                "GPM mouse using unknown protocol = %s\n",
+                                proto);
 #endif
-                        close (mouse_fd);
+                        close(mouse_fd);
                         mouse_fd = -1;
                     }
                 }
 #ifdef DEBUG_MOUSE
                 if (mouse_fd >= 0) {
-                    fprintf (stderr,
-                             "Using GPM mouse, protocol = %s\n", proto);
+                    fprintf(stderr,
+                            "Using GPM mouse, protocol = %s\n", proto);
                 }
 #endif /* DEBUG_MOUSE */
             }
         }
         /* Now try to use a modern PS/2 mouse */
         for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) {
-            mouse_fd = open (ps2mice[i], O_RDWR, 0);
+            mouse_fd = open(ps2mice[i], O_RDWR, 0);
             if (mouse_fd < 0) {
-                mouse_fd = open (ps2mice[i], O_RDONLY, 0);
+                mouse_fd = open(ps2mice[i], O_RDONLY, 0);
             }
             if (mouse_fd >= 0) {
                 /* rcg06112001 Attempt to set IMPS/2 mode */
-                set_imps2_mode (mouse_fd);
-                if (detect_imps2 (mouse_fd)) {
+                set_imps2_mode(mouse_fd);
+                if (detect_imps2(mouse_fd)) {
 #ifdef DEBUG_MOUSE
-                    fprintf (stderr, "Using IMPS2 mouse\n");
+                    fprintf(stderr, "Using IMPS2 mouse\n");
 #endif
                     mouse_drv = MOUSE_IMPS2;
                 } else {
 #ifdef DEBUG_MOUSE
-                    fprintf (stderr, "Using PS2 mouse\n");
+                    fprintf(stderr, "Using PS2 mouse\n");
 #endif
                     mouse_drv = MOUSE_PS2;
                 }
@@ -679,10 +678,10 @@
         }
         /* Next try to use a PPC ADB port mouse */
         if (mouse_fd < 0) {
-            mouse_fd = open ("/dev/adbmouse", O_RDONLY, 0);
+            mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);
             if (mouse_fd >= 0) {
 #ifdef DEBUG_MOUSE
-                fprintf (stderr, "Using ADB mouse\n");
+                fprintf(stderr, "Using ADB mouse\n");
 #endif
                 mouse_drv = MOUSE_BM;
             }
@@ -693,12 +692,12 @@
         if (mousedev == NULL) {
             mousedev = "/dev/mouse";
         }
-        mouse_fd = open (mousedev, O_RDONLY, 0);
+        mouse_fd = open(mousedev, O_RDONLY, 0);
         if (mouse_fd >= 0) {
             struct termios mouse_termios;
 
             /* Set the sampling speed to 1200 baud */
-            tcgetattr (mouse_fd, &mouse_termios);
+            tcgetattr(mouse_fd, &mouse_termios);
             mouse_termios.c_iflag = IGNBRK | IGNPAR;
             mouse_termios.c_oflag = 0;
             mouse_termios.c_lflag = 0;
@@ -708,18 +707,16 @@
             mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;
             mouse_termios.c_cflag |= CS8;
             mouse_termios.c_cflag |= B1200;
-            tcsetattr (mouse_fd, TCSAFLUSH, &mouse_termios);
-            if (mousedrv && (SDL_strcmp (mousedrv, "PS2") == 0)) {
+            tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);
+            if (mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0)) {
 #ifdef DEBUG_MOUSE
-                fprintf (stderr,
-                         "Using (user specified) PS2 mouse on %s\n",
-                         mousedev);
+                fprintf(stderr,
+                        "Using (user specified) PS2 mouse on %s\n", mousedev);
 #endif
                 mouse_drv = MOUSE_PS2;
             } else {
 #ifdef DEBUG_MOUSE
-                fprintf (stderr, "Using (default) MS mouse on %s\n",
-                         mousedev);
+                fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev);
 #endif
                 mouse_drv = MOUSE_MS;
             }
@@ -734,7 +731,7 @@
 static int posted = 0;
 
 void
-FB_vgamousecallback (int button, int relative, int dx, int dy)
+FB_vgamousecallback(int button, int relative, int dx, int dy)
 {
     int button_1, button_3;
     int button_state;
@@ -743,7 +740,7 @@
     Uint8 state;
 
     if (dx || dy) {
-        posted += SDL_PrivateMouseMotion (0, relative, dx, dy);
+        posted += SDL_PrivateMouseMotion(0, relative, dx, dy);
     }
 
     /* Swap button 1 and 3 */
@@ -753,7 +750,7 @@
     button |= (button_1 | button_3);
 
     /* See what changed */
-    button_state = SDL_GetMouseState (NULL, NULL);
+    button_state = SDL_GetMouseState(NULL, NULL);
     state_changed = button_state ^ button;
     for (i = 0; i < 8; ++i) {
         if (state_changed & (1 << i)) {
@@ -762,7 +759,7 @@
             } else {
                 state = SDL_RELEASED;
             }
-            posted += SDL_PrivateMouseButton (state, i + 1, 0, 0);
+            posted += SDL_PrivateMouseButton(state, i + 1, 0, 0);
         }
     }
 }
@@ -770,15 +767,15 @@
 /* Handle input from tslib */
 #if SDL_INPUT_TSLIB
 static void
-handle_tslib (_THIS)
+handle_tslib(_THIS)
 {
     struct ts_sample sample;
     int button;
 
-    while (ts_read (ts_dev, &sample, 1) > 0) {
+    while (ts_read(ts_dev, &sample, 1) > 0) {
         button = (sample.pressure > 0) ? 1 : 0;
         button <<= 2;           /* must report it as button 3 */
-        FB_vgamousecallback (button, 0, sample.x, sample.y);
+        FB_vgamousecallback(button, 0, sample.x, sample.y);
     }
     return;
 }
@@ -788,7 +785,7 @@
    Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
  */
 static void
-handle_mouse (_THIS)
+handle_mouse(_THIS)
 {
     static int start = 0;
     static unsigned char mousebuf[BUFSIZ];
@@ -804,7 +801,7 @@
     switch (mouse_drv) {
     case MOUSE_NONE:
         /* Ack! */
-        read (mouse_fd, mousebuf, BUFSIZ);
+        read(mouse_fd, mousebuf, BUFSIZ);
         return;
     case MOUSE_MSC:
         packetsize = 5;
@@ -822,12 +819,12 @@
         if (eloReadPosition
             (this, mouse_fd, &dx, &dy, &button, &realx, &realy)) {
             button = (button & 0x01) << 2;
-            FB_vgamousecallback (button, 0, dx, dy);
+            FB_vgamousecallback(button, 0, dx, dy);
         }
         return;                 /* nothing left to do */
     case MOUSE_TSLIB:
 #if SDL_INPUT_TSLIB
-        handle_tslib (this);
+        handle_tslib(this);
 #endif
         return;                 /* nothing left to do */
     default:
@@ -842,13 +839,13 @@
     }
 
     /* Read as many packets as possible */
-    nread = read (mouse_fd, &mousebuf[start], BUFSIZ - start);
+    nread = read(mouse_fd, &mousebuf[start], BUFSIZ - start);
     if (nread < 0) {
         return;
     }
     nread += start;
 #ifdef DEBUG_MOUSE
-    fprintf (stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
+    fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
 #endif
     for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) {
         switch (mouse_drv) {
@@ -900,10 +897,10 @@
             case 0x02:         /* DX = -1 */
                 break;
             case 0x0F:         /* DY = +1 (map button 4) */
-                FB_vgamousecallback (button | (1 << 3), 1, 0, 0);
+                FB_vgamousecallback(button | (1 << 3), 1, 0, 0);
                 break;
             case 0x01:         /* DY = -1 (map button 5) */
-                FB_vgamousecallback (button | (1 << 4), 1, 0, 0);
+                FB_vgamousecallback(button | (1 << 4), 1, 0, 0);
                 break;
             }
             break;
@@ -940,10 +937,10 @@
             dy = 0;
             break;
         }
-        FB_vgamousecallback (button, relative, dx, dy);
+        FB_vgamousecallback(button, relative, dx, dy);
     }
     if (i < nread) {
-        SDL_memcpy (mousebuf, &mousebuf[i], (nread - i));
+        SDL_memcpy(mousebuf, &mousebuf[i], (nread - i));
         start = (nread - i);
     } else {
         start = 0;
@@ -953,76 +950,76 @@
 
 /* Handle switching to another VC, returns when our VC is back */
 static void
-switch_vt_prep (_THIS)
+switch_vt_prep(_THIS)
 {
     SDL_Surface *screen = SDL_VideoSurface;
 
-    SDL_PrivateAppActive (0,
-                          (SDL_APPACTIVE | SDL_APPINPUTFOCUS |
-                           SDL_APPMOUSEFOCUS));
+    SDL_PrivateAppActive(0,
+                         (SDL_APPACTIVE | SDL_APPINPUTFOCUS |
+                          SDL_APPMOUSEFOCUS));
 
     /* Save the contents of the screen, and go to text mode */
-    wait_idle (this);
+    wait_idle(this);
     screen_arealen = ((screen->h + (2 * this->offset_y)) * screen->pitch);
-    screen_contents = (Uint8 *) SDL_malloc (screen_arealen);
+    screen_contents = (Uint8 *) SDL_malloc(screen_arealen);
     if (screen_contents) {
-        SDL_memcpy (screen_contents, screen->pixels, screen_arealen);
+        SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
     }
-    FB_SavePaletteTo (this, 256, screen_palette);
-    ioctl (console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
-    ioctl (keyboard_fd, KDSETMODE, KD_TEXT);
-    ioctl (keyboard_fd, VT_UNLOCKSWITCH, 1);
+    FB_SavePaletteTo(this, 256, screen_palette);
+    ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
+    ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
+    ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
 }
 static void
-switch_vt_done (_THIS)
+switch_vt_done(_THIS)
 {
     SDL_Surface *screen = SDL_VideoSurface;
 
     /* Restore graphics mode and the contents of the screen */
-    ioctl (keyboard_fd, VT_LOCKSWITCH, 1);
-    ioctl (keyboard_fd, KDSETMODE, KD_GRAPHICS);
-    ioctl (console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
-    FB_RestorePaletteFrom (this, 256, screen_palette);
+    ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
+    ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
+    ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
+    FB_RestorePaletteFrom(this, 256, screen_palette);
     if (screen_contents) {
-        SDL_memcpy (screen->pixels, screen_contents, screen_arealen);
-        SDL_free (screen_contents);
+        SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
+        SDL_free(screen_contents);
         screen_contents = NULL;
     }
 
     /* Get updates to the shadow surface while switched away */
     if (SDL_ShadowSurface) {
-        SDL_UpdateRect (SDL_ShadowSurface, 0, 0, 0, 0);
+        SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
     }
 
-    SDL_PrivateAppActive (1,
-                          (SDL_APPACTIVE | SDL_APPINPUTFOCUS |
-                           SDL_APPMOUSEFOCUS));
+    SDL_PrivateAppActive(1,
+                         (SDL_APPACTIVE | SDL_APPINPUTFOCUS |
+                          SDL_APPMOUSEFOCUS));
 }
 static void
-switch_vt (_THIS, unsigned short which)
+switch_vt(_THIS, unsigned short which)
 {
     struct vt_stat vtstate;
 
     /* Figure out whether or not we're switching to a new console */
-    if ((ioctl (keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
+    if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
         (which == vtstate.v_active)) {
         return;
     }
 
     /* New console, switch to it */
-    SDL_mutexP (hw_lock);
-    switch_vt_prep (this);
-    if (ioctl (keyboard_fd, VT_ACTIVATE, which) == 0) {
-        ioctl (keyboard_fd, VT_WAITACTIVE, which);
+    SDL_mutexP(hw_lock);
+    switch_vt_prep(this);
+    if (ioctl(keyboard_fd, VT_ACTIVATE, which) == 0) {
+        ioctl(keyboard_fd, VT_WAITACTIVE, which);
         switched_away = 1;
     } else {
-        switch_vt_done (this);
+        switch_vt_done(this);
     }
-    SDL_mutexV (hw_lock);
+    SDL_mutexV(hw_lock);
 }
 
 static void
-handle_keyboard (_THIS)
+handle_keyboard(_THIS)
 {
     unsigned char keybuf[BUFSIZ];
     int i, nread;
@@ -1030,7 +1027,7 @@
     int scancode;
     SDL_keysym keysym;
 
-    nread = read (keyboard_fd, keybuf, BUFSIZ);
+    nread = read(keyboard_fd, keybuf, BUFSIZ);
     for (i = 0; i < nread; ++i) {
         scancode = keybuf[i] & 0x7F;
         if (keybuf[i] & 0x80) {
@@ -1038,7 +1035,7 @@
         } else {
             pressed = SDL_PRESSED;
         }
-        TranslateKey (scancode, &keysym);
+        TranslateKey(scancode, &keysym);
         /* Handle Ctrl-Alt-FN for vt switch */
         switch (keysym.sym) {
         case SDLK_F1:
@@ -1053,23 +1050,23 @@
         case SDLK_F10:
         case SDLK_F11:
         case SDLK_F12:
-            if ((SDL_GetModState () & KMOD_CTRL) &&
-                (SDL_GetModState () & KMOD_ALT)) {
+            if ((SDL_GetModState() & KMOD_CTRL) &&
+                (SDL_GetModState() & KMOD_ALT)) {
                 if (pressed) {
-                    switch_vt (this, (keysym.sym - SDLK_F1) + 1);
+                    switch_vt(this, (keysym.sym - SDLK_F1) + 1);
                 }
                 break;
             }
             /* Fall through to normal processing */
         default:
-            posted += SDL_PrivateKeyboard (pressed, &keysym);
+            posted += SDL_PrivateKeyboard(pressed, &keysym);
             break;
         }
     }
 }
 
 void
-FB_PumpEvents (_THIS)
+FB_PumpEvents(_THIS)
 {
     fd_set fdset;
     int max_fd;
@@ -1079,40 +1076,40 @@
         if (switched_away) {
             struct vt_stat vtstate;
 
-            SDL_mutexP (hw_lock);
-            if ((ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
+            SDL_mutexP(hw_lock);
+            if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
                 vtstate.v_active == current_vt) {
                 switched_away = 0;
-                switch_vt_done (this);
+                switch_vt_done(this);
             }
-            SDL_mutexV (hw_lock);
+            SDL_mutexV(hw_lock);
         }
 
         posted = 0;
 
-        FD_ZERO (&fdset);
+        FD_ZERO(&fdset);
         max_fd = 0;
         if (keyboard_fd >= 0) {
-            FD_SET (keyboard_fd, &fdset);
+            FD_SET(keyboard_fd, &fdset);
             if (max_fd < keyboard_fd) {
                 max_fd = keyboard_fd;
             }
         }
         if (mouse_fd >= 0) {
-            FD_SET (mouse_fd, &fdset);
+            FD_SET(mouse_fd, &fdset);
             if (max_fd < mouse_fd) {
                 max_fd = mouse_fd;
             }
         }
-        if (select (max_fd + 1, &fdset, NULL, NULL, &zero) > 0) {
+        if (select(max_fd + 1, &fdset, NULL, NULL, &zero) > 0) {
             if (keyboard_fd >= 0) {
-                if (FD_ISSET (keyboard_fd, &fdset)) {
-                    handle_keyboard (this);
+                if (FD_ISSET(keyboard_fd, &fdset)) {
+                    handle_keyboard(this);
                 }
             }
             if (mouse_fd >= 0) {
-                if (FD_ISSET (mouse_fd, &fdset)) {
-                    handle_mouse (this);
+                if (FD_ISSET(mouse_fd, &fdset)) {
+                    handle_mouse(this);
                 }
             }
         }
@@ -1121,14 +1118,14 @@
 }
 
 void
-FB_InitOSKeymap (_THIS)
+FB_InitOSKeymap(_THIS)
 {
     int i;
 
     /* Initialize the Linux key translation table */
 
     /* First get the ascii keys and others not well handled */
-    for (i = 0; i < SDL_arraysize (keymap); ++i) {
+    for (i = 0; i < SDL_arraysize(keymap); ++i) {
         switch (i) {
             /* These aren't handled by the x86 kernel keymapping (?) */
         case SCANCODE_PRINTSCREEN:
@@ -1169,11 +1166,11 @@
             break;
             /* this should take care of all standard ascii keys */
         default:
-            keymap[i] = KVAL (vga_keymap[0][i]);
+            keymap[i] = KVAL(vga_keymap[0][i]);
             break;
         }
     }
-    for (i = 0; i < SDL_arraysize (keymap); ++i) {
+    for (i = 0; i < SDL_arraysize(keymap); ++i) {
         switch (keymap_temp[i]) {
         case K_F1:
             keymap[i] = SDLK_F1;
@@ -1348,7 +1345,7 @@
 }
 
 static SDL_keysym *
-TranslateKey (int scancode, SDL_keysym * keysym)
+TranslateKey(int scancode, SDL_keysym * keysym)
 {
     /* Set the keysym information */
     keysym->scancode = scancode;
@@ -1361,7 +1358,7 @@
         int map;
         SDLMod modstate;
 
-        modstate = SDL_GetModState ();
+        modstate = SDL_GetModState();
         map = 0;
         if (modstate & KMOD_SHIFT) {
             map |= (1 << KG_SHIFT);
@@ -1375,17 +1372,17 @@
         if (modstate & KMOD_RALT) {
             map |= (1 << KG_ALTGR);
         }
-        if (KTYP (vga_keymap[map][scancode]) == KT_LETTER) {
+        if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) {
             if (modstate & KMOD_CAPS) {
                 map ^= (1 << KG_SHIFT);
             }
         }
-        if (KTYP (vga_keymap[map][scancode]) == KT_PAD) {
+        if (KTYP(vga_keymap[map][scancode]) == KT_PAD) {
             if (modstate & KMOD_NUM) {
-                keysym->unicode = KVAL (vga_keymap[map][scancode]);
+                keysym->unicode = KVAL(vga_keymap[map][scancode]);
             }
         } else {
-            keysym->unicode = KVAL (vga_keymap[map][scancode]);
+            keysym->unicode = KVAL(vga_keymap[map][scancode]);
         }
     }
     return (keysym);