Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/eesh


Modified Files:
        E.h Makefile.am comms.c main.c 
Removed Files:
        globals.c memory.c setup.c 


Log Message:
Trim eesh.
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/eesh/E.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- E.h 31 May 2004 19:47:33 -0000      1.18
+++ E.h 1 Jul 2004 09:27:30 -0000       1.19
@@ -35,18 +35,6 @@
 #include <stdarg.h>
 #include <string.h>
 #include <fcntl.h>
-#include <dirent.h>
-#include <signal.h>
-#include <time.h>
-#include <math.h>
-#include <pwd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
 
 #if HAVE_STRDUP
 #define USE_LIBC_STRDUP  1     /* Use libc strdup if present */
@@ -88,22 +76,6 @@
 }
 Client;
 
-typedef struct _root
-{
-   Window              win;
-   Visual             *vis;
-   int                 depth;
-   Colormap            cmap;
-   int                 scr;
-   int                 w, h;
-   Window              focuswin;
-}
-Root;
-
-void               *Emalloc(int size);
-void               *Erealloc(void *ptr, int size);
-void                Efree(void *ptr);
-
 void               *FindItem(const char *name, int id, int find_by, int type);
 void                AddItem(void *item, const char *name, int id, int type);
 void               *RemoveItem(char *name, int id, int find_by, int type);
@@ -111,42 +83,19 @@
 char              **ListItems(int *num, int type);
 void              **ListItemTypeID(int *num, int type, int id);
 
-void                SetupX(void);
-
-void                CommsSetup(void);
-void                CommsFindCommsWindow(void);
+Window              CommsSetup(void);
+Window              CommsFindCommsWindow(void);
 void                CommsSend(Client * c, const char *s);
 char               *CommsGet(Client ** c, XEvent * ev);
 Client             *MakeClient(Window win);
 void                ListFreeClient(void *ptr);
 void                DeleteClient(Client * c);
-void                HandleComms(XEvent * ev);
+int                 HandleComms(XEvent * ev);
 
-#if defined(__FILE__) && defined(__LINE__)
-#define Efree(x) \
-{ \
-  if (x) \
-    __Efree(x); \
-  else \
-    Alert("%s:%d:  Attempt to free a NULL pointer\n", __FILE__, __LINE__); \
-}
-#define Emalloc(x) \
-__Emalloc(x)
-#define Erealloc(x, y) \
-__Erealloc(x, y)
-#else
-#define Efree(x) \
-{ \
-  if (x) \
-    __Efree(x); \
-  else \
-    Alert("??:??:  Attempt to free a NULL pointer\n"); \
-}
-#define Emalloc(x) \
-__Emalloc(x)
-#define Erealloc(x, y) \
-__Erealloc(x, y)
-#endif
+#define Ecalloc     calloc
+#define Emalloc     malloc
+#define Efree       free
+#define Erealloc    realloc
 
 #if USE_LIBC_STRDUP
 #define Estrdup(s) ((s) ? strdup(s) : NULL)
@@ -154,10 +103,6 @@
 char               *Estrdup(const char *s);
 #endif
 
-void               *__Emalloc(int size);
-void               *__Erealloc(void *ptr, int size);
-void                __Efree(void *ptr);
-
 #define FILEPATH_LEN_MAX 4096
 /* This turns on E's internal stack tracking system for  coarse debugging */
 /* and being able to trace E for profiling/optimisation purposes (which */
@@ -220,11 +165,5 @@
 
 void                Alert(const char *fmt, ...);
 
-void                EDisplayMemUse(void);
-
 extern Display     *disp;
 extern List         lists;
-extern Window       comms_win;
-extern Window       my_win;
-extern Root         root;
-extern char        *display_name;
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/eesh/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- Makefile.am 8 May 2004 21:39:37 -0000       1.11
+++ Makefile.am 1 Jul 2004 09:27:30 -0000       1.12
@@ -1,9 +1,9 @@
 
 bin_PROGRAMS = eesh
 
-eesh_SOURCES = E.h comms.c globals.c lists.c main.c setup.c memory.c
+eesh_SOURCES = E.h comms.c lists.c main.c
 
-LDADD = $(X_LIBS) -lX11
+LDADD = $(X_LIBS) -lX11 $(RL_LIBS)
 
 INCLUDES = -I$(top_builddir) -I$(top_srcdir)/intl $(X_CFLAGS)
 
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/eesh/comms.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- comms.c     30 Jun 2004 13:03:57 -0000      1.11
+++ comms.c     1 Jul 2004 09:27:30 -0000       1.12
@@ -23,72 +23,68 @@
 
 #include "E.h"
 
-char                waitonly;
-Window              root_win;
+static Window       root_win;
+static Window       my_win;
 
-void
-CommsSetup()
+Window
+CommsSetup(void)
 {
    char               *str;
 
    EDBUG(5, "CommsSetup");
 
    str = getenv("ENL_WM_ROOT");
-   root_win = (str) ? strtoul(str, NULL, 0) : root.win;
+   root_win = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(disp);
 
    my_win = XCreateSimpleWindow(disp, root_win, -100, -100, 5, 5, 0, 0, 0);
 
-   EDBUG_RETURN_;
+   EDBUG_RETURN(my_win);
 }
 
-void
-CommsFindCommsWindow()
+Window
+CommsFindCommsWindow(void)
 {
    unsigned char      *s;
    Atom                a, ar;
    unsigned long       num, after;
    int                 format;
-   Window              rt;
+   Window              rt, comms_win;
    int                 dint;
    unsigned int        duint;
 
    EDBUG(6, "CommsFindCommsWindow");
+
+   comms_win = None;
+
    a = XInternAtom(disp, "ENLIGHTENMENT_COMMS", True);
-   if (a != None)
-     {
-       s = NULL;
-       XGetWindowProperty(disp, root_win, a, 0, 14, False, AnyPropertyType,
-                          &ar, &format, &num, &after, &s);
-       if (s)
-         {
-            comms_win = 0;
-            sscanf((char *)s, "%*s %lx", &comms_win);
-            XFree(s);
-         }
-       else
-          (comms_win = 0);
-       if (comms_win)
-         {
-            if (!XGetGeometry(disp, comms_win, &rt, &dint, &dint,
-                              &duint, &duint, &duint, &duint))
-               comms_win = 0;
-            s = NULL;
-            if (comms_win)
-              {
-                 XGetWindowProperty(disp, comms_win, a, 0, 14, False,
-                                    AnyPropertyType, &ar, &format, &num,
-                                    &after, &s);
-                 if (s)
-                    XFree(s);
-                 else
-                    comms_win = 0;
-              }
-         }
-     }
-   if (comms_win)
-      XSelectInput(disp, comms_win,
-                  StructureNotifyMask | SubstructureNotifyMask);
-   EDBUG_RETURN_;
+   if (a == None)
+      EDBUG_RETURN(None);
+
+   s = NULL;
+   XGetWindowProperty(disp, root_win, a, 0, 14, False, AnyPropertyType,
+                     &ar, &format, &num, &after, &s);
+   if (!s)
+      EDBUG_RETURN(None);
+
+   sscanf((char *)s, "%*s %lx", &comms_win);
+   XFree(s);
+   if (comms_win == None)
+      EDBUG_RETURN(None);
+
+   if (!XGetGeometry(disp, comms_win, &rt, &dint, &dint,
+                    &duint, &duint, &duint, &duint))
+      EDBUG_RETURN(None);
+
+   s = NULL;
+   XGetWindowProperty(disp, comms_win, a, 0, 14, False,
+                     AnyPropertyType, &ar, &format, &num, &after, &s);
+   if (!s)
+      EDBUG_RETURN(None);
+   XFree(s);
+
+   XSelectInput(disp, comms_win, StructureNotifyMask | SubstructureNotifyMask);
+
+   EDBUG_RETURN(comms_win);
 }
 
 void
@@ -250,7 +246,7 @@
    EDBUG_RETURN_;
 }
 
-void
+int
 HandleComms(XEvent * ev)
 {
    Client             *c;
@@ -259,11 +255,9 @@
    EDBUG(4, "HandleComms");
    s = CommsGet(&c, ev);
    if (!s)
-      EDBUG_RETURN_;
+      EDBUG_RETURN(0);
    printf("%s\n", s);
    fflush(stdout);
-   if (waitonly)
-      exit(0);
    Efree(s);
-   EDBUG_RETURN_;
+   EDBUG_RETURN(1);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/eesh/main.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- main.c      21 Mar 2004 01:37:31 -0000      1.18
+++ main.c      1 Jul 2004 09:27:30 -0000       1.19
@@ -22,30 +22,74 @@
  */
 
 #include "E.h"
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
 
-extern char         waitonly;
+/* Global vars */
+Display            *disp;
+List                lists;
 
+static char         buf[10240];
 static int          stdin_state;
-void                restore_stdin_state(void);
-void
-restore_stdin_state(void)
+static char        *display_name;
+static Client      *e;
+
+static void
+process_line(char *line)
+{
+   if (line == NULL)
+      exit(0);
+   if (*line == '\0')
+      return;
+
+   CommsSend(e, line);
+   XSync(disp, False);
+}
+
+static void
+stdin_state_setup(void)
+{
+   stdin_state = fcntl(0, F_GETFL, 0);
+   fcntl(0, F_SETFL, O_NONBLOCK);
+}
+
+static void
+stdin_state_restore(void)
 {
    fcntl(0, F_SETFL, stdin_state);
 }
 
+static void
+stdin_read(void)
+{
+   static int          j = 0;
+   int                 k, ret;
+
+   k = 0;
+   while ((ret = read(0, &(buf[j]), 1) > 0))
+     {
+       k = 1;
+       if (buf[j] == '\n')
+         {
+            buf[j] = 0;
+            if (strlen(buf) > 0)
+               process_line(buf);
+            j = -1;
+         }
+       j++;
+     }
+   if ((ret < 0) || ((k == 0) && (ret == 0)))
+      exit(0);
+}
+
 int
 main(int argc, char **argv)
 {
    XEvent              ev;
-   Client             *me, *e;
-   char                buf[10240];
-   int                 i, j, k;
+   Client             *me;
+   int                 i;
    fd_set              fd;
-   signed char         ret;
    char               *command;
+   Window              my_win, comms_win;
+   char                waitonly, complete;
 
    waitonly = 0;
    lists.next = NULL;
@@ -76,7 +120,6 @@
               }
          }
        else if ((!strcmp(argv[i], "-h")) ||
-                (!strcmp(argv[i], "--h")) ||
                 (!strcmp(argv[i], "-help")) || (!strcmp(argv[i], "--help")))
          {
             printf("%s [ -e \"Command to Send to Enlightenment then exit\"]\n"
@@ -90,15 +133,25 @@
          }
      }
 
-   SetupX();
-   CommsSetup();
-   CommsFindCommsWindow();
-   XSelectInput(disp, comms_win, StructureNotifyMask);
-   XSelectInput(disp, root.win, PropertyChangeMask);
+   /* Open a connection to the diplay nominated by the DISPLAY variable */
+   /* Or set with the -display option */
+   disp = XOpenDisplay(display_name);
+   if (!disp)
+     {
+       Alert("Failed to connect to X server\n");
+       exit(1);
+     }
+
+   my_win = CommsSetup();
+   comms_win = CommsFindCommsWindow();
+
    e = MakeClient(comms_win);
    AddItem(e, "E", e->win, LIST_TYPE_CLIENT);
+
+   /* Not sure this is used... */
    me = MakeClient(my_win);
    AddItem(me, "ME", me->win, LIST_TYPE_CLIENT);
+
    CommsSend(e, "set clientname eesh");
    CommsSend(e, "set version 0.1");
    CommsSend(e, "set author The Rasterman");
@@ -110,74 +163,56 @@
 
    if (command)
      {
+       /* Non-interactive */
        CommsSend(e, command);
+       XSync(disp, False);
        if (!waitonly)
-         {
-            XSync(disp, False);
-            exit(0);
-         }
+          goto done;
+     }
+   else
+     {
+       /* Interactive */
+       stdin_state_setup();
+       atexit(stdin_state_restore);
      }
 
-   XSync(disp, False);
-   j = 0;
-   stdin_state = fcntl(0, F_GETFL, 0);
-   atexit(restore_stdin_state);
-   fcntl(0, F_SETFL, O_NONBLOCK);
    for (;;)
      {
-       if (waitonly)
+       FD_ZERO(&fd);
+       if (!command)
+          FD_SET(0, &fd);
+       FD_SET(ConnectionNumber(disp), &fd);
+
+       if (select(ConnectionNumber(disp) + 1, &fd, NULL, NULL, NULL) < 0)
+          break;
+
+       XSync(disp, False);
+
+       if (FD_ISSET(0, &fd))
          {
-            XNextEvent(disp, &ev);
-            if (ev.type == ClientMessage)
-               HandleComms(&ev);
-            else if (ev.type == DestroyNotify)
-               exit(0);
-            XSync(disp, False);
+            stdin_read();
          }
-       else
+       else if (FD_ISSET(ConnectionNumber(disp), &fd))
          {
-            FD_ZERO(&fd);
-            FD_SET(0, &fd);
-            FD_SET(ConnectionNumber(disp), &fd);
-            if (select(ConnectionNumber(disp) + 1, &fd, NULL, NULL, NULL) < 0)
-               exit(0);
-            XSync(disp, False);
-
-            if (FD_ISSET(0, &fd))
-              {
-                 k = 0;
-                 while ((ret = read(0, &(buf[j]), 1) > 0))
-                   {
-                      k = 1;
-                      if (buf[j] == '\n')
-                        {
-                           buf[j] = 0;
-                           if (strlen(buf) > 0)
-                             {
-                                CommsSend(e, buf);
-                                XSync(disp, False);
-                             }
-                           j = -1;
-                        }
-                      j++;
-                   }
-                 if ((ret < 0) || ((k == 0) && (ret == 0)))
-                    exit(0);
-              }
-            else if (FD_ISSET(ConnectionNumber(disp), &fd))
+            while (XPending(disp))
               {
-                 while (XPending(disp))
+                 XNextEvent(disp, &ev);
+                 switch (ev.type)
                    {
-                      XNextEvent(disp, &ev);
-                      if (ev.type == ClientMessage)
-                         HandleComms(&ev);
-                      else if (ev.type == DestroyNotify)
-                         exit(0);
+                   case ClientMessage:
+                      complete = HandleComms(&ev);
+                      if (waitonly && complete)
+                         goto done;
+                      break;
+                   case DestroyNotify:
+                      goto done;
                    }
-                 XSync(disp, False);
               }
+            XSync(disp, False);
          }
      }
+
+ done:
    return 0;
 }
 
@@ -192,3 +227,20 @@
    va_end(ap);
    EDBUG_RETURN_;
 }
+
+#if !USE_LIBC_STRDUP
+char               *
+Estrdup(const char *s)
+{
+   char               *ss;
+   int                 sz;
+
+   EDBUG(9, "Estrdup");
+   if (!s)
+      EDBUG_RETURN(NULL);
+   sz = strlen(s);
+   ss = Emalloc(sz + 1);
+   strncpy(ss, s, sz + 1);
+   EDBUG_RETURN(ss);
+}
+#endif




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to