[PATCH:xscope 15/24] Record atoms from InternAtom and GetAtomName requests

Alan Coopersmith alan.coopersmith at oracle.com
Fri Aug 31 22:17:57 PDT 2012


Uses them to display strings instead of just numeric ids for atoms
beyond the builtin set in other requests, such as property lookups.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 COPYING   |    3 +-
 print11.c |   92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 proto.h   |    2 ++
 prtype.c  |   35 +++++++----------------
 table11.c |   53 ++++++++++++++++++++++++++++++++++-
 5 files changed, 157 insertions(+), 28 deletions(-)

diff --git a/COPYING b/COPYING
index 5990ff1..1b509fc 100644
--- a/COPYING
+++ b/COPYING
@@ -64,8 +64,9 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 	------------------------------------------------------------
 
 Copyright © 2000, 2001 Keith Packard, member of The XFree86 Project, Inc.
-Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
 Copyright © 2010 Intel Corporation
+Copyright (c) 2002, 2009, 2012, Oracle and/or its affiliates.
+All rights reserved.
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
diff --git a/print11.c b/print11.c
index 4bf74a4..a84de9e 100644
--- a/print11.c
+++ b/print11.c
@@ -25,7 +25,8 @@
  *
  */
 /*
- * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2009, 2012, Oracle and/or its affiliates.
+ * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -1250,6 +1251,65 @@ QueryTreeReply(const unsigned char *buf)
     PrintList(&buf[32], (long) n, WINDOW, "children");
 }
 
+/* Keep track of InternAtom & GetAtomName requests so we can add them to
+   our tables */
+struct atomic_req {
+    uint32_t seq;
+    uint32_t atom;
+    char *name;
+    struct atomic_req *next;
+};
+
+static struct atomic_req *pending_atom_reqs;
+
+static void
+start_atom_request(uint32_t atom, char *name)
+{
+    struct atomic_req *new_ar = malloc(sizeof(struct atomic_req));
+
+    if (new_ar) {
+        new_ar->seq = ILong(SBf);
+        new_ar->atom = atom;
+        new_ar->name = name;
+        new_ar->next = NULL;
+
+        if (pending_atom_reqs == NULL)
+            pending_atom_reqs = new_ar;
+        else {
+            struct atomic_req *ar;
+            for (ar = pending_atom_reqs; ar->next != NULL; ar = ar->next) {
+                /* find list tail */
+            }
+            ar->next = new_ar;
+        }
+    }
+}
+
+static void
+finish_atom_request(uint32_t seq, uint32_t atom, char *name)
+{
+    struct atomic_req *ar, *par, *next;
+
+    for (ar = pending_atom_reqs, par = NULL; ar != NULL; ar = next) {
+        next = ar->next;
+        if (ar->seq == seq) {
+            if (ar->atom == 0)
+                ar->atom = atom;
+            if (ar->name == NULL)
+                ar->name = name;
+            DefineAtom(ar->atom, ar->name);
+            free(ar->name); /* DefineAtom makes a copy if needed */
+            free(ar);
+            if (par == NULL)
+                pending_atom_reqs = next;
+            else
+                par->next = next;
+        }
+        else
+            par = ar;
+    }
+}
+
 void
 InternAtom(FD fd, const unsigned char *buf)
 {
@@ -1267,22 +1327,39 @@ InternAtom(FD fd, const unsigned char *buf)
     printfield(buf, 4, 2, DVALUE2(n), "length of name");
     n = IShort(&buf[4]);
     PrintString8(&buf[8], n, "name");
+
+    if (n > 0) {
+        char *name = malloc(n + 1);
+        if (name != NULL) {
+            memcpy(name, buf + 8, n);
+            name[n] = 0;
+            start_atom_request(0, name);
+        }
+    }
 }
 
 void
 InternAtomReply(const unsigned char *buf)
 {
+    uint32_t seq, atom;
+
     PrintField(RBf, 0, 1, REPLY, REPLYHEADER); /* InternAtom */
     if (Verbose < 1)
         return;
     printfield(buf, 2, 2, CARD16, "sequence number");
     printfield(buf, 4, 4, CONST4(0), "reply length");
     PrintField(buf, 8, 4, ATOM, "atom");
+
+    seq = IShort(&buf[2]);
+    atom = ILong(&buf[8]);
+    finish_atom_request(seq, atom, NULL);
 }
 
 void
 GetAtomName(FD fd, const unsigned char *buf)
 {
+    uint32_t atom;
+
     /* Request GetAtomName is opcode 17 */
     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* GetAtomName */
     if (Verbose < 1)
@@ -1292,12 +1369,17 @@ GetAtomName(FD fd, const unsigned char *buf)
 
     printreqlen(buf, fd, CONST2(2));
     PrintField(buf, 4, 4, ATOM, "atom");
+
+    atom = ILong(&buf[4]);
+    start_atom_request(atom, NULL);
 }
 
 void
 GetAtomNameReply(const unsigned char *buf)
 {
     short n;
+    uint32_t seq;
+    char *name;
 
     PrintField(RBf, 0, 1, REPLY, REPLYHEADER); /* GetAtomName */
     if (Verbose < 1)
@@ -1307,6 +1389,14 @@ GetAtomNameReply(const unsigned char *buf)
     printfield(buf, 8, 2, DVALUE2(n), "length of name");
     n = IShort(&buf[8]);
     PrintString8(&buf[32], n, "name");
+
+    seq = IShort(&buf[2]);
+    name = malloc(n + 1);
+    if (name != NULL) {
+        memcpy(name, buf + 32, n);
+        name[n] = 0;
+    }
+    finish_atom_request(seq, 0, name);
 }
 
 void
diff --git a/proto.h b/proto.h
index 5232d59..14ab41e 100644
--- a/proto.h
+++ b/proto.h
@@ -297,3 +297,5 @@ extern void DefineEValue(TYPE type, long value, const char *name);
 extern void DefineValues(TYPE type, long value, short length,
                          short ctype, const char *name);
 extern long GetEValue(short typeid, const char *name);
+extern void DefineAtom(uint32_t atom, const char *name);
+extern const char *FindAtomName(uint32_t atom);
diff --git a/prtype.c b/prtype.c
index 8d4e06f..38b44c6 100644
--- a/prtype.c
+++ b/prtype.c
@@ -25,7 +25,7 @@
  *
  */
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -456,37 +456,22 @@ PrintFONTABLE(const unsigned char *buf)
 
 /* ************************************************************ */
 
-#define NumberofAtoms 68
-
-static const char *const AtomTable[NumberofAtoms + 1] = {
-    "NONE", "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL",
-    "COLORMAP", "CURSOR", "CUT_BUFFER0", "CUT_BUFFER1", "CUT_BUFFER2",
-    "CUT_BUFFER3", "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
-    "CUT_BUFFER7", "DRAWABLE", "FONT", "INTEGER", "PIXMAP", "POINT",
-    "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP", "RGB_BEST_MAP",
-    "RGB_BLUE_MAP", "RGB_DEFAULT_MAP", "RGB_GRAY_MAP", "RGB_GREEN_MAP",
-    "RGB_RED_MAP", "STRING", "VISUALID", "WINDOW", "WM_COMMAND",
-    "WM_HINTS", "WM_CLIENT_MACHINE", "WM_ICON_NAME", "WM_ICON_SIZE",
-    "WM_NAME", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
-    "MIN_SPACE", "NORM_SPACE", "MAX_SPACE", "END_SPACE", "SUPERSCRIPT_X",
-    "SUPERSCRIPT_Y", "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
-    "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
-    "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH", "WEIGHT", "POINT_SIZE",
-    "RESOLUTION", "COPYRIGHT", "NOTICE", "FONT_NAME", "FAMILY_NAME",
-    "FULL_NAME", "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR"
-};
-
-/* for atoms, we print the built-in atoms.  We could expand to printing
-   the user defined ones, too. */
+/* for atoms, we print the built-in atoms, as well as any user defined
+   ones we've captured during this session. */
 
 int
 PrintATOM(const unsigned char *buf)
 {
     /* print a ATOM -- CARD32 plus 0 = None */
     long n = ILong(buf);
+    const char *name = FindAtomName(n);
 
-    if (0 <= n && n <= NumberofAtoms)
-        fprintf(stdout, "<%s>", AtomTable[n]);
+    if (name != NULL) {
+        if (Verbose > 1)
+            fprintf(stdout, "ATM %08lx <%s>", n, name);
+        else
+            fprintf(stdout, "<%s>", name);
+    }
     else
         fprintf(stdout, "ATM %08lx", n);
     return (4);
diff --git a/table11.c b/table11.c
index 3463173..1bc1b95 100644
--- a/table11.c
+++ b/table11.c
@@ -25,7 +25,7 @@
  *
  */
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -314,6 +314,57 @@ DefineValues(TYPE type, long value, short length, short ctype, const char *name)
 
 
 /* ************************************************************ */
+/* Atoms are defined as a builtin type for the core protocol defined
+   atoms, with atoms passed via InternAtom & GetAtomName added as
+   additional enumerated type values */
+#define NumberofAtoms 68
+
+static const char *const AtomTable[NumberofAtoms + 1] = {
+    "NONE", "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL",
+    "COLORMAP", "CURSOR", "CUT_BUFFER0", "CUT_BUFFER1", "CUT_BUFFER2",
+    "CUT_BUFFER3", "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
+    "CUT_BUFFER7", "DRAWABLE", "FONT", "INTEGER", "PIXMAP", "POINT",
+    "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP", "RGB_BEST_MAP",
+    "RGB_BLUE_MAP", "RGB_DEFAULT_MAP", "RGB_GRAY_MAP", "RGB_GREEN_MAP",
+    "RGB_RED_MAP", "STRING", "VISUALID", "WINDOW", "WM_COMMAND",
+    "WM_HINTS", "WM_CLIENT_MACHINE", "WM_ICON_NAME", "WM_ICON_SIZE",
+    "WM_NAME", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
+    "MIN_SPACE", "NORM_SPACE", "MAX_SPACE", "END_SPACE", "SUPERSCRIPT_X",
+    "SUPERSCRIPT_Y", "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
+    "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
+    "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH", "WEIGHT", "POINT_SIZE",
+    "RESOLUTION", "COPYRIGHT", "NOTICE", "FONT_NAME", "FAMILY_NAME",
+    "FULL_NAME", "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR"
+};
+
+const char *
+FindAtomName(uint32_t atom)
+{
+    struct ValueListEntry *p;
+
+    if (atom <= NumberofAtoms)
+        return AtomTable[atom];
+
+    for (p = TD[ATOM].ValueList; p != NULL; p = p->Next) {
+        if (p->Value == atom)
+            return p->Name;
+    }
+
+    return NULL;
+}
+
+void
+DefineAtom(uint32_t atom, const char *name)
+{
+    if ((atom == 0) || (name == NULL))
+        return;
+
+    if (FindAtomName(atom) == NULL)
+        DefineEValue(&TD[ATOM], atom, strdup(name));
+}
+
+
+/* ************************************************************ */
 
 static void
 InitBuiltInTypes(void)
-- 
1.7.9.2



More information about the xorg-devel mailing list