[gpm] failed to build gpm with clang

Alexander Kolesen kolesen.a@gmail.com
Sun Apr 3 19:11:11 CEST 2011


Hello.
I've tried to build gpm from git with clang, but it has failed, because
there is couple of nested functions in src/mice.c.
Unfortunately, clang doesn't support nested functions. And seems that
this feature will implemented not soon.

Could you please remove them? 
With attached patch gpm from git compiles fine with clang.
-------------- next part --------------
--- gpm.orig/src/mice.c	2011-04-03 19:33:44.000000000 +0300
+++ gpm/src/mice.c	2011-04-03 19:51:54.000000000 +0300
@@ -1748,8 +1748,9 @@ static Gpm_Type* I_logi(int fd, unsigned
    return type;
 }
 
-static Gpm_Type *I_wacom(int fd, unsigned short flags,
-                         struct Gpm_Type *type, int argc, char **argv)
+typedef char buff_t[50];
+
+static void reset_wacom(int fd)
 {
 /* wacom graphire tablet */
 #define UD_RESETBAUD     "\r$"      /* reset baud rate to default (wacom V) */
@@ -1760,8 +1761,6 @@ static Gpm_Type *I_wacom(int fd, unsigne
 #define UD_COORD         "~C\r"     /* Request max coordinates              */
 #define UD_STOP          "\nSP\r"   /* stop sending coordinates             */
 
-   void reset_wacom()
-   { 
       /* Init Wacom communication; this is modified from xf86Wacom.so module */
       /* Set speed to 19200 */
       setspeed (fd, 1200, 19200, 0, B19200|CS8|CREAD|CLOCAL|HUPCL);
@@ -1780,7 +1779,7 @@ static Gpm_Type *I_wacom(int fd, unsigne
       usleep(100000);
    }
 
-   int wait_wacom()
+static int wait_wacom(int fd)
    {
       /* 
        *  Wait up to 200 ms for Data from Tablet. 
@@ -1796,27 +1795,33 @@ static Gpm_Type *I_wacom(int fd, unsigne
       return((err>0)?1:err);
    }
 
-   char buffer[50], *p;
-
-   int RequestData(char *cmd)
+static int RequestData(char *cmd, int fd, char* buffer)
    {
       int err;
+    char *p;
       /* 
        * Send cmd if not null, and get back answer from tablet. 
        * Get Data to buffer until full or timeout.
        * Give back 0 for timeout and !0 for buffer full
        */
       if (cmd) write(fd,cmd,strlen(cmd));
-      memset(buffer,0,sizeof(buffer)); p=buffer;
-      err=wait_wacom();
-      while (err != -1 && err && (p-buffer)<(sizeof(buffer)-1)) {
-         p+= read(fd,p,(sizeof(buffer)-1)-(p-buffer));
-         err=wait_wacom();
+    memset(buffer,0,sizeof(buff_t)); p=buffer;
+    err=wait_wacom(fd);
+    while (err != -1 && err && (p-buffer)<(sizeof(buff_t)-1)) {
+        p+= read(fd,p,(sizeof(buff_t)-1)-(p-buffer));
+        err=wait_wacom(fd);
       }
       /* return 1 for buffer full */
-      return ((strlen(buffer) >= (sizeof(buffer)-1))? !0 :0);
+    return ((strlen(buffer) >= (sizeof(buff_t)-1))? !0 :0);
    }
 
+static Gpm_Type *I_wacom(int fd, unsigned short flags,
+                         struct Gpm_Type *type, int argc, char **argv)
+{
+
+
+   buff_t buffer;
+
    /*
     * We do both modes, relative and absolute, with the same function.
     * If WacomAbsoluteWanted is !0 then that function calculates
@@ -1835,13 +1840,13 @@ static Gpm_Type *I_wacom(int fd, unsigne
    };
    parse_argv(optioninfo, argc, argv); 
    type->absolute = WacomAbsoluteWanted;
-   reset_wacom();
+   reset_wacom(fd);
 
    /* "Flush" input queque */
-   while(RequestData(NULL)) ;
+   while(RequestData(NULL, fd, buffer)) ;
 
    /* read WACOM-ID */
-   RequestData(UD_FIRMID); 
+   RequestData(UD_FIRMID, fd, buffer); 
 
    /* Search for matching modell */
    for(WacomModell=0;
@@ -1862,7 +1867,7 @@ static Gpm_Type *I_wacom(int fd, unsigne
    
    /* read Wacom max size */
    if(WacomModell!=(-1) && (!wcmodell[WacomModell].maxX)) {
-      RequestData(UD_COORD);
+      RequestData(UD_COORD, fd, buffer);
       sscanf(buffer+2, "%d,%d", &wmaxx, &wmaxy);
       wmaxx = (wmaxx-wcmodell[WacomModell].border);
       wmaxy = (wmaxy-wcmodell[WacomModell].border);
@@ -2051,15 +2056,12 @@ static Gpm_Type *I_synps2(int fd, unsign
 }
 
 
-static Gpm_Type *I_summa(int fd, unsigned short flags,
-          struct Gpm_Type *type, int argc, char **argv) 
-{
-   void resetsumma()
+   static void resetsumma(int fd)
    {
       write(fd,0,1); /* Reset */
       usleep(400000); /* wait */
    }
-   int waitsumma()
+   static int waitsumma(int fd)
    {
       struct timeval timeout;
       fd_set readfds;
@@ -2069,6 +2071,11 @@ static Gpm_Type *I_summa(int fd, unsigne
       err = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
       return(err);
    }
+
+static Gpm_Type *I_summa(int fd, unsigned short flags,
+          struct Gpm_Type *type, int argc, char **argv) 
+{
+
    int err;
    char buffer[255];
    char config[5];
@@ -2088,7 +2095,7 @@ static Gpm_Type *I_summa(int fd, unsigne
 
    /* Set speed to 9600bps */
    setspeed (fd, 1200, 9600, 1, B9600|CS8|CREAD|CLOCAL|HUPCL|PARENB|PARODD);  
-   resetsumma(); 
+   resetsumma(fd); 
  
    write(fd, SS_PROMPT_MODE, strlen(SS_PROMPT_MODE));
   
@@ -2097,7 +2104,7 @@ static Gpm_Type *I_summa(int fd, unsigne
    if (summaid<0) { /* Summagraphics test */
       /* read the Summa Firm-ID */
       write(fd, SS_FIRMID, strlen(SS_FIRMID));
-      err=waitsumma();
+      err=waitsumma(fd);
       if (!((err == -1) || (!err))) {
          summaid=10; /* Original Summagraphics */
          read(fd, buffer, 255); /* Read Firm-ID */
@@ -2105,14 +2112,14 @@ static Gpm_Type *I_summa(int fd, unsigne
    }
   
    if (summaid<0) { /* Genius-test */
-      resetsumma();
+      resetsumma(fd);
       write(fd,GEN_MMSERIES,1); 
       write(fd,&GEN_MODELL,1); /* Read modell */
-      err=waitsumma();
+      err=waitsumma(fd);
       if (!((err == -1) || (!err))) { /* read Genius-ID */
-           err=waitsumma();
+           err=waitsumma(fd);
          if (!((err == -1) || (!err))) {
-            err=waitsumma();
+            err=waitsumma(fd);
             if (!((err == -1) || (!err))) {
                read(fd,&config,1);
                summaid=(config[0] & 224) >> 5; /* genius tablet-id (0-7)*/
@@ -2123,12 +2130,12 @@ static Gpm_Type *I_summa(int fd, unsigne
 
    /* unknown tablet ?*/
    if ((summaid<0) || (summaid==11)) { 
-      resetsumma(); 
+      resetsumma(fd); 
       write(fd, SS_BINARY_FMT SS_PROMPT_MODE, 3);
    }
 
    /* read tablet size */
-   err=waitsumma();  
+   err=waitsumma(fd);  
    if (!((err == -1) || (!err))) read(fd,buffer,sizeof(buffer));
    write(fd,SS_READCONFIG,1);
    read(fd,&config,5);


More information about the gpm mailing list