summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:54 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:54 +0000
commitc4577392d4ebbd4a4fdf37720982cb378b5749a0 (patch)
treef72fa2951e360a9117b075e8add9b3ac4f98a725
R6.6 is the Xorg base-lineXORG-MAINXORG-STABLE
-rw-r--r--xlsatoms.c235
-rw-r--r--xlsatoms.man65
2 files changed, 300 insertions, 0 deletions
diff --git a/xlsatoms.c b/xlsatoms.c
new file mode 100644
index 0000000..ca2d68f
--- /dev/null
+++ b/xlsatoms.c
@@ -0,0 +1,235 @@
+/*
+ * $Xorg: xlsatoms.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Jim Fulton, MIT X Consortium
+ */
+
+#include <stdio.h>
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/Xproto.h>
+#include <X11/Xmu/Error.h>
+
+char *ProgramName;
+
+static void usage ()
+{
+ fprintf (stderr, "usage: %s [-options...]\n\n", ProgramName);
+ fprintf (stderr, "where options include:\n");
+ fprintf (stderr,
+ " -display dpy X server to which to connect\n");
+ fprintf (stderr,
+ " -format string printf-style format to use\n");
+ fprintf (stderr,
+ " -range [num]-[num] atom values to list\n");
+ fprintf (stderr,
+ " -name string name of single atom to print\n");
+ putc ('\n', stderr);
+ exit (1);
+}
+
+
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ char *displayname = NULL;
+ char *format = "%lu\t%s";
+ int i, doit;
+ int didit = 0;
+ Display *dpy = NULL;
+
+ ProgramName = argv[0];
+
+ for (doit = 0; doit < 2; doit++) { /* pre-parse to get display */
+ for (i = 1; i < argc; i++) {
+ char *arg = argv[i];
+
+ if (arg[0] == '-') {
+ switch (arg[1]) {
+ case 'd': /* -display dpy */
+ if (++i >= argc) usage ();
+ if (!doit) displayname = argv[i];
+ continue;
+ case 'f': /* -format string */
+ if (++i >= argc) usage ();
+ if (doit) format = argv[i];
+ continue;
+ case 'r': /* -range num-[num] */
+ if (++i >= argc) usage ();
+ if (doit) {
+ do_range (dpy, format, argv[i]);
+ didit = 1;
+ }
+ continue;
+ case 'n': /* -name string */
+ if (++i >= argc) usage ();
+ if (doit) {
+ do_name (dpy, format, argv[i]);
+ didit = 1;
+ }
+ continue;
+ }
+ }
+ usage ();
+ }
+ if (!doit) {
+ dpy = XOpenDisplay (displayname);
+ if (!dpy) {
+ fprintf (stderr, "%s: unable to open display \"%s\"\n",
+ ProgramName, XDisplayName (displayname));
+ exit (1);
+ }
+ } else
+ if (!didit) /* no options, default is list all */
+ list_atoms(dpy, format, 0, 0, 0);
+ }
+
+ XCloseDisplay (dpy);
+ exit (0);
+}
+
+do_name (dpy, format, name)
+ Display *dpy;
+ char *format;
+ char *name;
+{
+ Atom a = XInternAtom (dpy, name, True);
+
+ if (a != None) {
+ printf (format, (unsigned long) a, name);
+ putchar ('\n');
+ } else {
+ fprintf (stderr, "%s: no atom named \"%s\" on server \"%s\"\n",
+ ProgramName, name, DisplayString(dpy));
+ }
+}
+
+
+#define RangeLow (1 << 0)
+#define RangeHigh (1 << 1)
+
+static int parse_range (range, lowp, highp)
+ char *range;
+ long *lowp, *highp;
+{
+ char *dash;
+ int mask = 0;
+
+ if (!range) { /* NULL means default */
+ *lowp = 1;
+ return RangeLow;
+ }
+
+ dash = strchr(range, '-');
+ if (!dash) dash = strchr(range, ':');
+ if (dash) {
+ if (dash == range) { /* -high */
+ *lowp = 1;
+ } else { /* low-[high] */
+ *dash = '\0';
+ *lowp = atoi (range);
+ *dash = '-';
+ }
+ mask |= RangeLow;
+ dash++;
+ if (*dash) { /* [low]-high */
+ *highp = atoi (dash);
+ mask |= RangeHigh;
+ }
+ } else { /* number (low == high) */
+ *lowp = *highp = atoi (range);
+ mask |= (RangeLow | RangeHigh);
+ }
+
+ return mask;
+}
+
+do_range (dpy, format, range)
+ Display *dpy;
+ char *format;
+ char *range;
+{
+ int mask;
+ long low, high;
+
+ mask = parse_range (range, &low, &high);
+ list_atoms (dpy, format, mask, low, high);
+}
+
+
+static int catcher (dpy, err)
+ Display *dpy;
+ XErrorEvent *err;
+{
+ if (err->request_code != X_GetAtomName) {
+ XmuPrintDefaultErrorMessage (dpy, err, stderr);
+ }
+ return 0;
+}
+
+list_atoms (dpy, format, mask, low, high)
+ Display *dpy;
+ char *format;
+ int mask;
+ long low, high;
+{
+ int (*oldhandler)() = XSetErrorHandler (catcher);
+
+ switch (mask) {
+ case RangeHigh:
+ low = 1;
+ /* fall through */
+ case (RangeLow | RangeHigh):
+ for (; low <= high; low++) {
+ char *s = XGetAtomName (dpy, (Atom)low);
+ if (s) {
+ printf (format, low, s);
+ putchar ('\n');
+ XFree (s);
+ }
+ }
+ break;
+
+ default:
+ low = 1;
+ /* fall through */
+ case RangeLow:
+ for (; ; low++) {
+ char *s = XGetAtomName (dpy, (Atom)low);
+ if (s) {
+ printf (format, low, s);
+ putchar ('\n');
+ XFree (s);
+ } else {
+ break;
+ }
+ }
+ break;
+ }
+
+ XSetErrorHandler (oldhandler);
+ return;
+}
diff --git a/xlsatoms.man b/xlsatoms.man
new file mode 100644
index 0000000..5b0bd7a
--- /dev/null
+++ b/xlsatoms.man
@@ -0,0 +1,65 @@
+.\" $Xorg: xlsatoms.man,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $
+.\" Copyright 1989, 1994, 1998 The Open Group
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that
+.\" copyright notice and this permission notice appear in supporting
+.\" documentation.
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of The Open Group shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from The Open Group.
+.TH XLSATOMS 1 "Release 6.4" "X Version 11"
+.SH NAME
+xlsatoms - list interned atoms defined on server
+.SH SYNOPSIS
+.B xlsatoms
+[-options ...]
+.SH DESCRIPTION
+.I Xlsatoms
+lists the interned atoms. By default, all atoms starting from 1 (the lowest
+atom value defined by the protocol) are listed until unknown atom is found.
+If an explicit range is given, \fIxlsatoms\fP will try all atoms in the range,
+regardless of whether or not any are undefined.
+.SH "OPTIONS"
+.PP
+.TP 8
+.B \-display \fIdpy\fP
+This option specifies the X server to which to connect.
+.TP 8
+.B \-format \fIstring\fP
+This option specifies a \fIprintf\fP-style string used to list each atom
+\fI<value,name>\fP pair, printed in that order (\fIvalue\fP is an \fIunsigned
+long\fP and \fIname\fP is a \fIchar *\fP). \fIXlsatoms\fP will supply a
+newline at the end of each line. The default is \fI%ld\\t%s\fP.
+.TP 8
+.B \-range \fI[low]-[high]\fP
+This option specifies the range of atom values to check. If \fIlow\fP is not
+given, a value of 1 assumed. If \fIhigh\fP is not given, \fIxlsatoms\fP will
+stop at the first undefined atom at or above \fIlow\fP.
+.TP 8
+.B \-name \fIstring\fP
+This option specifies the name of an atom to list. If the atom does not
+exist, a message will be printed on the standard error.
+.PP
+.SH "SEE ALSO"
+X(1), Xserver(1), xprop(1)
+.SH ENVIRONMENT
+.TP 8
+.B DISPLAY
+to get the default host and display to use.
+.SH AUTHOR
+Jim Fulton, MIT X Consortium