summaryrefslogtreecommitdiffstats
path: root/contrib/global/gozilla
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/global/gozilla')
-rw-r--r--contrib/global/gozilla/Imakefile12
-rw-r--r--contrib/global/gozilla/gozilla.c194
-rw-r--r--contrib/global/gozilla/gozilla.man141
-rw-r--r--contrib/global/gozilla/remote.c717
-rw-r--r--contrib/global/gozilla/vroot.h119
5 files changed, 1183 insertions, 0 deletions
diff --git a/contrib/global/gozilla/Imakefile b/contrib/global/gozilla/Imakefile
new file mode 100644
index 0000000..5bcbc01
--- /dev/null
+++ b/contrib/global/gozilla/Imakefile
@@ -0,0 +1,12 @@
+XCOMM
+XCOMM Imakefile for gozilla
+XCOMM
+
+LOCAL_LIBRARIES = XawClientLibs -L../lib -lutil
+ DEPLIBS = XawClientDepLibs ../lib/libutil.a
+ DEFINES = -DSTANDALONE -DGLOBAL -I../lib
+
+ SRCS = gozilla.c remote.c
+ OBJS = gozilla.o remote.o
+
+ComplexProgramTarget(gozilla)
diff --git a/contrib/global/gozilla/gozilla.c b/contrib/global/gozilla/gozilla.c
new file mode 100644
index 0000000..fd43bbf
--- /dev/null
+++ b/contrib/global/gozilla/gozilla.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Shigio Yamaguchi.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * gozilla.c 27-Oct-97
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include "global.h"
+
+char *progname = "gozilla"; /* command name */
+
+static void usage __P((void));
+void main __P((int, char **));
+int sendcommand __P((char *));
+
+int bflag;
+int pflag;
+int Cflag;
+
+static void
+usage()
+{
+ fprintf(stderr, "usage:\t%s\n\t%s\n",
+ "gozilla [+no] [-b browser] [-p] file",
+ "gozilla -C command");
+ exit(1);
+}
+
+void
+main(argc, argv)
+int argc;
+char *argv[];
+{
+ char c, *p, *q;
+ char *browser = (char *)0;
+ char *command = (char *)0;
+ char *arg = (char *)0;
+ char URL[MAXPATHLEN+1];
+ char com[MAXCOMLINE+1];
+ int linenumber = 0;
+ int status;
+
+ while (--argc > 0 && (c = (++argv)[0][0]) == '-' || c == '+') {
+ if (c == '+') {
+ linenumber = atoi(argv[0] + 1);
+ continue;
+ }
+ p = argv[0] + 1;
+ switch (*p) {
+ case 'b':
+ browser = argv[1];
+ --argc; ++argv;
+ break;
+ case 'p':
+ pflag++;
+ break;
+ case 'C':
+ command = argv[1];
+ --argc; ++argv;
+ break;
+ default:
+ usage();
+ }
+ }
+ if (!browser && getenv("BROWSER"))
+ browser = getenv("BROWSER");
+ if (command) {
+ if (browser)
+ die("-C option is valid only for mozilla.");
+ if (sendcommand(command) == -1)
+ die("mozilla not found.");
+ exit(0);
+ }
+ if (argc == 0)
+ usage();
+ if (locatestring(argv[0], "http:", 1) || locatestring(argv[0], "file:", 1))
+ strcpy(URL, argv[0]);
+ else {
+ char *abspath;
+ char pathbuf[MAXPATHLEN+1];
+ char htmlpath[MAXPATHLEN+1];
+
+ if (!test("f", argv[0]) && !test("d", argv[0]))
+ die1("path '%s' not found.", argv[0]);
+ if (!(abspath = realpath(argv[0], pathbuf)))
+ die1("cannot make absolute path name. realpath(%s) failed.", argv[0]);
+ if (*abspath != '/')
+ die("realpath(3) is not compatible with BSD version.");
+ if (issource(abspath)) {
+ char cwd[MAXPATHLEN+1];
+ char root[MAXPATHLEN+1];
+ char dbpath[MAXPATHLEN+1];
+ char htmldir[MAXPATHLEN+1];
+ /*
+ * get current, root and dbpath directory.
+ * if GTAGS not found, getdbpath doesn't return.
+ */
+ getdbpath(cwd, root, dbpath);
+ if (test("d", makepath(dbpath, "HTML")))
+ strcpy(htmldir, makepath(dbpath, "HTML"));
+ else if (test("d", makepath(root, "HTML")))
+ strcpy(htmldir, makepath(root, "HTML"));
+ else
+ die("hypertext not found. See htags(1).");
+ /*
+ * convert path into hypertext.
+ */
+ p = abspath + strlen(root);
+ for (q = ++p; *q; q++)
+ if (*q == '/')
+ *q = ' ';
+ if (linenumber)
+ sprintf(URL, "file:%s/S/%s.html#%d", htmldir, p, linenumber);
+ else
+ sprintf(URL, "file:%s/S/%s.html", htmldir, p);
+ } else {
+ sprintf(URL, "file:%s", abspath);
+ }
+ }
+ if (pflag) {
+ fprintf(stdout, "%s\n", URL);
+ exit(0);
+ }
+ /*
+ * execute generic browser.
+ */
+ if (browser && !locatestring(browser, "netscape", 3)) {
+ sprintf(com, "%s '%s'", browser, URL);
+ system(com);
+ exit (0);
+ }
+ /*
+ * send a command to mozilla.
+ */
+ sprintf(com, "openURL(%s)", URL);
+ status = sendcommand(com);
+ /*
+ * load mozilla if not found.
+ */
+ if (status != 0) {
+ int pid;
+
+ if ((pid = fork()) < 0) {
+ die("cannot execute netscape (fork).");
+ } else if (pid == 0) {
+ execlp("netscape", "netscape", URL, (char *)0);
+ die("loading mozilla failed.");
+ }
+ exit(0);
+ }
+ exit(status);
+}
+int
+sendcommand(com)
+char *com;
+{
+ int argc = 3;
+ char *argv[4];
+
+ argv[0] = "netscape-remote";
+ argv[1] = "-remote";
+ argv[2] = com;
+ argv[3] = (char *)0;
+
+ return netscape_remote(argc, argv);
+}
diff --git a/contrib/global/gozilla/gozilla.man b/contrib/global/gozilla/gozilla.man
new file mode 100644
index 0000000..1065529
--- /dev/null
+++ b/contrib/global/gozilla/gozilla.man
@@ -0,0 +1,141 @@
+.\"
+.\" Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Shigio Yamaguchi.
+.\" 4. Neither the name of the author nor the names of any co-contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd Sep 17, 1997
+.Dt GOZILLA 1
+.Os BSD 4
+.Sh NAME
+.Nm gozilla
+.Nd force mozilla to display specified source file
+.Sh SYNOPSIS
+\fBgozilla\fP [\fB+\fP\fIno\fP]
+.Op Fl b Ar browser
+.Op Fl p
+.Ar file
+.Nm gozilla
+.Fl C Ar command
+.Sh DESCRIPTION
+First form:
+.br
+.Nm Gozilla
+force mozilla (Netscape Navigator) to display specified source file
+as a hypertext.
+If mozilla has not loaded then
+.Nm
+loads it.
+.Pp
+In advance of using this command, you must execute
+.Xr gtags 1
+and
+.Xr htags 1
+at the root directory of the source tree to make tag files.
+Then you can execute
+.Nm
+at anywhere in the source tree.
+.br
+You can specify source file and the line number optionally.
+.Pp
+Second form:
+.br
+.Nm Gozilla
+send
+.Ar command
+to mozilla directly.
+.Ar Command
+is undocumented. But the hint is in the resource file of mozilla.
+.Pp
+The following options are available:
+.Bl -tag -width Ds
+.It Ar \fB+\fP\fIno\fP
+line number. It must be a line on which function definition or function
+reference is exist.
+If you execute
+.Xr htags 1
+with -l option, you can specify any line.
+.It Fl b Ar browser
+browser to use. By default, assumes mozilla.
+If you specify another browser,
+.Nm
+waits for exiting of the browser.
+.It Fl p
+just print generated target URL.
+.It Ar file
+path of source file.
+.It Fl C Ar command
+send
+.Ar command
+to mozilla directly.
+.El
+.Sh FILES
+.Bl -tag -width tags -compact
+.It Pa HTML/
+hypertext of source tree.
+.It Pa GTAGS
+tags file for function definitions.
+.El
+.Sh ENVIRONMENT
+The following environment variables affect the execution of gozilla.
+.Pp
+.Bl -tag -width indent
+.It Ev GTAGSROOT
+The directory which is the root of source tree.
+.It Ev GTAGSDBPATH
+The directory on which HTML directory exist. This value is ignored
+when GTAGSROOT is not defined.
+.It Ev BROWSER
+browser to use. By default, assumes mozilla.
+.El
+.Sh EXAMPLES
+
+ % global -x main
+ main 82 ctags.c main(argc, argv)
+ % gozilla +82 ctags.c
+ % gozilla -C pageDown
+ % gozilla -C back
+
+.Sh DIAGNOSTICS
+.Nm Gozilla
+exits with a non 0 value if an error occurred, 0 otherwise.
+.Sh SEE ALSO
+.Xr global 1 ,
+.Xr gtags 1 ,
+.Xr htags 1 .
+.Sh NOTES
+Netscape Navigator is a registered trademark of Netscape Communications Corporation
+in the United States and other countries.
+.Pp
+.Nm Gozilla
+means 'Global for mozilla'.
+.Sh BUGS
+.Nm Gozilla
+can treat not only source file but also normal file, directory, HTML file
+and even URL, because it is omnivorous.
+.Sh AUTHORS
+Shigio Yamaguchi (shigio@wafu.netgate.net)
diff --git a/contrib/global/gozilla/remote.c b/contrib/global/gozilla/remote.c
new file mode 100644
index 0000000..d2e6a34
--- /dev/null
+++ b/contrib/global/gozilla/remote.c
@@ -0,0 +1,717 @@
+/* -*- Mode:C; tab-width: 8 -*-
+ * remote.c --- remote control of Netscape Navigator for Unix.
+ * version 1.1.3, for Netscape Navigator 1.1 and newer.
+ *
+ * Copyright © 1996 Netscape Communications Corporation, all rights reserved.
+ * Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94.
+ *
+ * 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. No representations are made about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * To compile:
+ *
+ * cc -o netscape-remote remote.c -DSTANDALONE -lXmu -lX11
+ *
+ * To use:
+ *
+ * netscape-remote -help
+ *
+ * Documentation for the protocol which this code implements may be found at:
+ *
+ * http://home.netscape.com/newsref/std/x-remote.html
+ *
+ * Bugs and commentary to x_cbug@netscape.com.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xmu/WinUtil.h> /* for XmuClientWindow() */
+
+
+/* vroot.h is a header file which lets a client get along with `virtual root'
+ window managers like swm, tvtwm, olvwm, etc. If you don't have this header
+ file, you can find it at "http://home.netscape.com/newsref/std/vroot.h".
+ If you don't care about supporting virtual root window managers, you can
+ comment this line out.
+ */
+#include "vroot.h"
+
+
+#ifdef STANDALONE
+#ifdef GLOBAL
+ extern char *progname;
+#else
+ static const char *progname = 0;
+#endif
+ static const char *expected_mozilla_version = "1.1";
+#else /* !STANDALONE */
+ extern const char *progname;
+ extern const char *expected_mozilla_version;
+#endif /* !STANDALONE */
+
+#define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
+#define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
+#define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND"
+#define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
+static Atom XA_MOZILLA_VERSION = 0;
+static Atom XA_MOZILLA_LOCK = 0;
+static Atom XA_MOZILLA_COMMAND = 0;
+static Atom XA_MOZILLA_RESPONSE = 0;
+
+static void
+mozilla_remote_init_atoms (Display *dpy)
+{
+ if (! XA_MOZILLA_VERSION)
+ XA_MOZILLA_VERSION = XInternAtom (dpy, MOZILLA_VERSION_PROP, False);
+ if (! XA_MOZILLA_LOCK)
+ XA_MOZILLA_LOCK = XInternAtom (dpy, MOZILLA_LOCK_PROP, False);
+ if (! XA_MOZILLA_COMMAND)
+ XA_MOZILLA_COMMAND = XInternAtom (dpy, MOZILLA_COMMAND_PROP, False);
+ if (! XA_MOZILLA_RESPONSE)
+ XA_MOZILLA_RESPONSE = XInternAtom (dpy, MOZILLA_RESPONSE_PROP, False);
+}
+
+static Window
+mozilla_remote_find_window (Display *dpy)
+{
+ int i;
+ Window root = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
+ Window root2, parent, *kids;
+ unsigned int nkids;
+ Window result = 0;
+ Window tenative = 0;
+ unsigned char *tenative_version = 0;
+
+ if (! XQueryTree (dpy, root, &root2, &parent, &kids, &nkids))
+ {
+ fprintf (stderr, "%s: XQueryTree failed on display %s\n", progname,
+ DisplayString (dpy));
+ exit (2);
+ }
+
+ /* root != root2 is possible with virtual root WMs. */
+
+ if (! (kids && nkids))
+ {
+ fprintf (stderr, "%s: root window has no children on display %s\n",
+ progname, DisplayString (dpy));
+ exit (2);
+ }
+
+ for (i = nkids-1; i >= 0; i--)
+ {
+ Atom type;
+ int format;
+ unsigned long nitems, bytesafter;
+ unsigned char *version = 0;
+ Window w = XmuClientWindow (dpy, kids[i]);
+ int status = XGetWindowProperty (dpy, w, XA_MOZILLA_VERSION,
+ 0, (65536 / sizeof (long)),
+ False, XA_STRING,
+ &type, &format, &nitems, &bytesafter,
+ &version);
+ if (! version)
+ continue;
+ if (strcmp ((char *) version, expected_mozilla_version) &&
+ !tenative)
+ {
+ tenative = w;
+ tenative_version = version;
+ continue;
+ }
+ XFree (version);
+ if (status == Success && type != None)
+ {
+ result = w;
+ break;
+ }
+ }
+
+ if (result && tenative)
+ {
+#ifndef GLOBAL
+ fprintf (stderr,
+ "%s: warning: both version %s (0x%x) and version\n"
+ "\t%s (0x%x) are running. Using version %s.\n",
+ progname, tenative_version, (unsigned int) tenative,
+ expected_mozilla_version, (unsigned int) result,
+ expected_mozilla_version);
+#endif
+ XFree (tenative_version);
+ return result;
+ }
+ else if (tenative)
+ {
+#ifndef GLOBAL
+ fprintf (stderr,
+ "%s: warning: expected version %s but found version\n"
+ "\t%s (0x%x) instead.\n",
+ progname, expected_mozilla_version,
+ tenative_version, (unsigned int) tenative);
+#endif
+ XFree (tenative_version);
+ return tenative;
+ }
+ else if (result)
+ {
+ return result;
+ }
+ else
+ {
+#ifdef GLOBAL
+ return 0;
+#else
+ fprintf (stderr, "%s: not running on display %s\n", progname,
+ DisplayString (dpy));
+ exit (1);
+#endif
+ }
+}
+
+static void
+mozilla_remote_check_window (Display *dpy, Window window)
+{
+ Atom type;
+ int format;
+ unsigned long nitems, bytesafter;
+ unsigned char *version = 0;
+ int status = XGetWindowProperty (dpy, window, XA_MOZILLA_VERSION,
+ 0, (65536 / sizeof (long)),
+ False, XA_STRING,
+ &type, &format, &nitems, &bytesafter,
+ &version);
+ if (status != Success || !version)
+ {
+ fprintf (stderr, "%s: window 0x%x is not a Netscape window.\n",
+ progname, (unsigned int) window);
+ exit (6);
+ }
+ else if (strcmp ((char *) version, expected_mozilla_version))
+ {
+ fprintf (stderr,
+ "%s: warning: window 0x%x is Netscape version %s;\n"
+ "\texpected version %s.\n",
+ progname, (unsigned int) window,
+ version, expected_mozilla_version);
+ }
+ XFree (version);
+}
+
+
+static char *lock_data = 0;
+
+static void
+mozilla_remote_obtain_lock (Display *dpy, Window window)
+{
+ Bool locked = False;
+ Bool waited = False;
+
+ if (! lock_data)
+ {
+ lock_data = (char *) malloc (255);
+ sprintf (lock_data, "pid%d@", getpid ());
+ if (gethostname (lock_data + strlen (lock_data), 100))
+ {
+ perror ("gethostname");
+ exit (-1);
+ }
+ }
+
+ do
+ {
+ int result;
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+ unsigned char *data = 0;
+
+ XGrabServer (dpy); /* ################################# DANGER! */
+
+ result = XGetWindowProperty (dpy, window, XA_MOZILLA_LOCK,
+ 0, (65536 / sizeof (long)),
+ False, /* don't delete */
+ XA_STRING,
+ &actual_type, &actual_format,
+ &nitems, &bytes_after,
+ &data);
+ if (result != Success || actual_type == None)
+ {
+ /* It's not now locked - lock it. */
+#ifdef DEBUG_PROPS
+ fprintf (stderr, "%s: (writing " MOZILLA_LOCK_PROP
+ " \"%s\" to 0x%x)\n",
+ progname, lock_data, (unsigned int) window);
+#endif
+ XChangeProperty (dpy, window, XA_MOZILLA_LOCK, XA_STRING, 8,
+ PropModeReplace, (unsigned char *) lock_data,
+ strlen (lock_data));
+ locked = True;
+ }
+
+ XUngrabServer (dpy); /* ################################# danger over */
+ XSync (dpy, False);
+
+ if (! locked)
+ {
+ /* We tried to grab the lock this time, and failed because someone
+ else is holding it already. So, wait for a PropertyDelete event
+ to come in, and try again. */
+
+ fprintf (stderr, "%s: window 0x%x is locked by %s; waiting...\n",
+ progname, (unsigned int) window, data);
+ waited = True;
+
+ while (1)
+ {
+ XEvent event;
+ XNextEvent (dpy, &event);
+ if (event.xany.type == DestroyNotify &&
+ event.xdestroywindow.window == window)
+ {
+ fprintf (stderr, "%s: window 0x%x unexpectedly destroyed.\n",
+ progname, (unsigned int) window);
+ exit (6);
+ }
+ else if (event.xany.type == PropertyNotify &&
+ event.xproperty.state == PropertyDelete &&
+ event.xproperty.window == window &&
+ event.xproperty.atom == XA_MOZILLA_LOCK)
+ {
+ /* Ok! Someone deleted their lock, so now we can try
+ again. */
+#ifdef DEBUG_PROPS
+ fprintf (stderr, "%s: (0x%x unlocked, trying again...)\n",
+ progname, (unsigned int) window);
+#endif
+ break;
+ }
+ }
+ }
+ if (data)
+ XFree (data);
+ }
+ while (! locked);
+
+ if (waited)
+ fprintf (stderr, "%s: obtained lock.\n", progname);
+}
+
+
+static void
+mozilla_remote_free_lock (Display *dpy, Window window)
+{
+ int result;
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+ unsigned char *data = 0;
+
+#ifdef DEBUG_PROPS
+ fprintf (stderr, "%s: (deleting " MOZILLA_LOCK_PROP
+ " \"%s\" from 0x%x)\n",
+ progname, lock_data, (unsigned int) window);
+#endif
+
+ result = XGetWindowProperty (dpy, window, XA_MOZILLA_LOCK,
+ 0, (65536 / sizeof (long)),
+ True, /* atomic delete after */
+ XA_STRING,
+ &actual_type, &actual_format,
+ &nitems, &bytes_after,
+ &data);
+ if (result != Success)
+ {
+ fprintf (stderr, "%s: unable to read and delete " MOZILLA_LOCK_PROP
+ " property\n",
+ progname);
+ return;
+ }
+ else if (!data || !*data)
+ {
+ fprintf (stderr, "%s: invalid data on " MOZILLA_LOCK_PROP
+ " of window 0x%x.\n",
+ progname, (unsigned int) window);
+ return;
+ }
+ else if (strcmp ((char *) data, lock_data))
+ {
+ fprintf (stderr, "%s: " MOZILLA_LOCK_PROP
+ " was stolen! Expected \"%s\", saw \"%s\"!\n",
+ progname, lock_data, data);
+ return;
+ }
+
+ if (data)
+ XFree (data);
+}
+
+
+static int
+mozilla_remote_command (Display *dpy, Window window, const char *command,
+ Bool raise_p)
+{
+ int result;
+ Bool done = False;
+ char *new_command = 0;
+
+ /* The -noraise option is implemented by passing a "noraise" argument
+ to each command to which it should apply.
+ */
+ if (! raise_p)
+ {
+ char *close;
+ new_command = (char *) malloc (strlen (command) + 20);
+ strcpy (new_command, command);
+ close = strrchr (new_command, ')');
+ if (close)
+ strcpy (close, ", noraise)");
+ else
+ strcat (new_command, "(noraise)");
+ command = new_command;
+ }
+
+#ifdef DEBUG_PROPS
+ fprintf (stderr, "%s: (writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
+ progname, command, (unsigned int) window);
+#endif
+
+ XChangeProperty (dpy, window, XA_MOZILLA_COMMAND, XA_STRING, 8,
+ PropModeReplace, (unsigned char *) command,
+ strlen (command));
+
+ while (!done)
+ {
+ XEvent event;
+ XNextEvent (dpy, &event);
+ if (event.xany.type == DestroyNotify &&
+ event.xdestroywindow.window == window)
+ {
+ /* Print to warn user...*/
+ fprintf (stderr, "%s: window 0x%x was destroyed.\n",
+ progname, (unsigned int) window);
+ result = 6;
+ goto DONE;
+ }
+ else if (event.xany.type == PropertyNotify &&
+ event.xproperty.state == PropertyNewValue &&
+ event.xproperty.window == window &&
+ event.xproperty.atom == XA_MOZILLA_RESPONSE)
+ {
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+ unsigned char *data = 0;
+
+ result = XGetWindowProperty (dpy, window, XA_MOZILLA_RESPONSE,
+ 0, (65536 / sizeof (long)),
+ True, /* atomic delete after */
+ XA_STRING,
+ &actual_type, &actual_format,
+ &nitems, &bytes_after,
+ &data);
+#ifdef DEBUG_PROPS
+ if (result == Success && data && *data)
+ {
+ fprintf (stderr, "%s: (server sent " MOZILLA_RESPONSE_PROP
+ " \"%s\" to 0x%x.)\n",
+ progname, data, (unsigned int) window);
+ }
+#endif
+
+ if (result != Success)
+ {
+ fprintf (stderr, "%s: failed reading " MOZILLA_RESPONSE_PROP
+ " from window 0x%0x.\n",
+ progname, (unsigned int) window);
+ result = 6;
+ done = True;
+ }
+ else if (!data || strlen((char *) data) < 5)
+ {
+ fprintf (stderr, "%s: invalid data on " MOZILLA_RESPONSE_PROP
+ " property of window 0x%0x.\n",
+ progname, (unsigned int) window);
+ result = 6;
+ done = True;
+ }
+ else if (*data == '1') /* positive preliminary reply */
+ {
+ fprintf (stderr, "%s: %s\n", progname, data + 4);
+ /* keep going */
+ done = False;
+ }
+#if 1
+ else if (!strncmp ((char *)data, "200", 3)) /* positive completion */
+ {
+ result = 0;
+ done = True;
+ }
+#endif
+ else if (*data == '2') /* positive completion */
+ {
+ fprintf (stderr, "%s: %s\n", progname, data + 4);
+ result = 0;
+ done = True;
+ }
+ else if (*data == '3') /* positive intermediate reply */
+ {
+ fprintf (stderr, "%s: internal error: "
+ "server wants more information? (%s)\n",
+ progname, data);
+ result = 3;
+ done = True;
+ }
+ else if (*data == '4' || /* transient negative completion */
+ *data == '5') /* permanent negative completion */
+ {
+ fprintf (stderr, "%s: %s\n", progname, data + 4);
+ result = (*data - '0');
+ done = True;
+ }
+ else
+ {
+ fprintf (stderr,
+ "%s: unrecognised " MOZILLA_RESPONSE_PROP
+ " from window 0x%x: %s\n",
+ progname, (unsigned int) window, data);
+ result = 6;
+ done = True;
+ }
+
+ if (data)
+ XFree (data);
+ }
+#ifdef DEBUG_PROPS
+ else if (event.xany.type == PropertyNotify &&
+ event.xproperty.window == window &&
+ event.xproperty.state == PropertyDelete &&
+ event.xproperty.atom == XA_MOZILLA_COMMAND)
+ {
+ fprintf (stderr, "%s: (server 0x%x has accepted "
+ MOZILLA_COMMAND_PROP ".)\n",
+ progname, (unsigned int) window);
+ }
+#endif /* DEBUG_PROPS */
+ }
+
+ DONE:
+
+ if (new_command)
+ free (new_command);
+
+ return result;
+}
+
+int
+mozilla_remote_commands (Display *dpy, Window window, char **commands)
+{
+ Bool raise_p = True;
+ int status = 0;
+ mozilla_remote_init_atoms (dpy);
+
+ if (window == 0)
+ window = mozilla_remote_find_window (dpy);
+ else
+ mozilla_remote_check_window (dpy, window);
+#ifdef GLOBAL
+ if (window == 0)
+ return -1;
+#endif
+
+ XSelectInput (dpy, window, (PropertyChangeMask|StructureNotifyMask));
+
+ mozilla_remote_obtain_lock (dpy, window);
+
+ while (*commands)
+ {
+ if (!strcmp (*commands, "-raise"))
+ raise_p = True;
+ else if (!strcmp (*commands, "-noraise"))
+ raise_p = False;
+ else
+ status = mozilla_remote_command (dpy, window, *commands, raise_p);
+
+ if (status != 0)
+ break;
+ commands++;
+ }
+
+ /* When status = 6, it means the window has been destroyed */
+ /* It is invalid to free the lock when window is destroyed. */
+
+ if ( status != 6 )
+ mozilla_remote_free_lock (dpy, window);
+
+ return status;
+}
+
+
+#ifdef STANDALONE
+
+static void
+usage (void)
+{
+ fprintf (stderr, "usage: %s [ options ... ]\n\
+ where options include:\n\
+\n\
+ -help to show this message.\n\
+ -display <dpy> to specify the X server to use.\n\
+ -remote <remote-command> to execute a command in an already-running\n\
+ Netscape process. See the manual for a\n\
+ list of valid commands.\n\
+ -id <window-id> the id of an X window to which the -remote\n\
+ commands should be sent; if unspecified,\n\
+ the first window found will be used.\n\
+ -raise whether following -remote commands should\n\
+ cause the window to raise itself to the top\n\
+ (this is the default.)\n\
+ -noraise the opposite of -raise: following -remote\n\
+ commands will not auto-raise the window.\n\
+",
+ progname);
+}
+
+
+#ifdef GLOBAL
+int
+netscape_remote(int argc, char **argv)
+#else
+void
+main (int argc, char **argv)
+#endif
+{
+ Display *dpy;
+ char *dpy_string = 0;
+ char **remote_commands = 0;
+ int remote_command_count = 0;
+ int remote_command_size = 0;
+ unsigned long remote_window = 0;
+ Bool sync_p = False;
+ int i;
+
+ progname = strrchr (argv[0], '/');
+ if (progname)
+ progname++;
+ else
+ progname = argv[0];
+
+ /* Hack the -help and -version arguments before opening the display. */
+ for (i = 1; i < argc; i++)
+ {
+ if (!strcasecmp (argv [i], "-h") ||
+ !strcasecmp (argv [i], "-help"))
+ {
+ usage ();
+ exit (0);
+ }
+ else if (!strcmp (argv [i], "-d") ||
+ !strcmp (argv [i], "-dpy") ||
+ !strcmp (argv [i], "-disp") ||
+ !strcmp (argv [i], "-display"))
+ {
+ i++;
+ dpy_string = argv [i];
+ }
+ else if (!strcmp (argv [i], "-sync") ||
+ !strcmp (argv [i], "-synchronize"))
+ {
+ sync_p = True;
+ }
+ else if (!strcmp (argv [i], "-remote"))
+ {
+ if (remote_command_count == remote_command_size)
+ {
+ remote_command_size += 20;
+ remote_commands =
+ (remote_commands
+ ? realloc (remote_commands,
+ remote_command_size * sizeof (char *))
+ : calloc (remote_command_size, sizeof (char *)));
+ }
+ i++;
+ if (!argv[i] || *argv[i] == '-' || *argv[i] == 0)
+ {
+ fprintf (stderr, "%s: invalid `-remote' option \"%s\"\n",
+ progname, argv[i] ? argv[i] : "");
+ usage ();
+ exit (-1);
+ }
+ remote_commands [remote_command_count++] = argv[i];
+ }
+ else if (!strcmp (argv [i], "-raise") ||
+ !strcmp (argv [i], "-noraise"))
+ {
+ char *r = argv [i];
+ if (remote_command_count == remote_command_size)
+ {
+ remote_command_size += 20;
+ remote_commands =
+ (remote_commands
+ ? realloc (remote_commands,
+ remote_command_size * sizeof (char *))
+ : calloc (remote_command_size, sizeof (char *)));
+ }
+ remote_commands [remote_command_count++] = r;
+ }
+ else if (!strcmp (argv [i], "-id"))
+ {
+ char c;
+ if (remote_command_count > 0)
+ {
+ fprintf (stderr,
+ "%s: the `-id' option must preceed all `-remote' options.\n",
+ progname);
+ usage ();
+ exit (-1);
+ }
+ else if (remote_window != 0)
+ {
+ fprintf (stderr, "%s: only one `-id' option may be used.\n",
+ progname);
+ usage ();
+ exit (-1);
+ }
+ i++;
+ if (argv[i] &&
+ 1 == sscanf (argv[i], " %ld %c", &remote_window, &c))
+ ;
+ else if (argv[i] &&
+ 1 == sscanf (argv[i], " 0x%lx %c", &remote_window, &c))
+ ;
+ else
+ {
+ fprintf (stderr, "%s: invalid `-id' option \"%s\"\n",
+ progname, argv[i] ? argv[i] : "");
+ usage ();
+ exit (-1);
+ }
+ }
+ }
+
+ dpy = XOpenDisplay (dpy_string);
+ if (! dpy)
+ exit (-1);
+
+ if (sync_p)
+ XSynchronize (dpy, True);
+
+#ifdef GLOBAL
+ return mozilla_remote_commands (dpy, (Window) remote_window,
+ remote_commands);
+#else
+ exit (mozilla_remote_commands (dpy, (Window) remote_window,
+ remote_commands));
+#endif
+}
+
+#endif /* STANDALONE */
diff --git a/contrib/global/gozilla/vroot.h b/contrib/global/gozilla/vroot.h
new file mode 100644
index 0000000..e06c263
--- /dev/null
+++ b/contrib/global/gozilla/vroot.h
@@ -0,0 +1,119 @@
+/*****************************************************************************/
+/** Copyright 1991 by Andreas Stolcke **/
+/** Copyright 1990 by Solbourne Computer Inc. **/
+/** Longmont, Colorado **/
+/** **/
+/** All Rights Reserved **/
+/** **/
+/** Permission to use, copy, modify, and distribute this software and **/
+/** its documentation for any purpose and without fee is hereby **/
+/** granted, provided that the above copyright notice appear in all **/
+/** copies and that both that copyright notice and this permis- **/
+/** sion notice appear in supporting documentation, and that the **/
+/** name of Solbourne not be used in advertising **/
+/** in publicity pertaining to distribution of the software without **/
+/** specific, written prior permission. **/
+/** **/
+/** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
+/** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/
+/** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/
+/** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/
+/** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
+/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
+/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
+/** OR PERFORMANCE OF THIS SOFTWARE. **/
+/*****************************************************************************/
+/*
+ * vroot.h -- Virtual Root Window handling header file
+ *
+ * This header file redefines the X11 macros RootWindow and DefaultRootWindow,
+ * making them look for a virtual root window as provided by certain `virtual'
+ * window managers like swm and tvtwm. If none is found, the ordinary root
+ * window is returned, thus retaining backward compatibility with standard
+ * window managers.
+ * The function implementing the virtual root lookup remembers the result of
+ * its last invocation to avoid overhead in the case of repeated calls
+ * on the same display and screen arguments.
+ * The lookup code itself is taken from Tom LaStrange's ssetroot program.
+ *
+ * Most simple root window changing X programs can be converted to using
+ * virtual roots by just including
+ *
+ * #include <X11/vroot.h>
+ *
+ * after all the X11 header files. It has been tested on such popular
+ * X clients as xphoon, xfroot, xloadimage, and xaqua.
+ * It also works with the core clients xprop, xwininfo, xwd, and editres
+ * (and is necessary to get those clients working under tvtwm).
+ * It does NOT work with xsetroot; get the xsetroot replacement included in
+ * the tvtwm distribution instead.
+ *
+ * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
+ * - replaced all NULL's with properly cast 0's, 5/6/91
+ * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
+ * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
+ */
+
+#ifndef _VROOT_H_
+#define _VROOT_H_
+
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+
+static Window
+VirtualRootWindowOfScreen(screen)
+ Screen *screen;
+{
+ static Screen *save_screen = (Screen *)0;
+ static Window root = (Window)0;
+
+ if (screen != save_screen) {
+ Display *dpy = DisplayOfScreen(screen);
+ Atom __SWM_VROOT = None;
+ int i;
+ Window rootReturn, parentReturn, *children;
+ unsigned int numChildren;
+
+ root = RootWindowOfScreen(screen);
+
+ /* go look for a virtual root */
+ __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
+ if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
+ &children, &numChildren)) {
+ for (i = 0; i < numChildren; i++) {
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems, bytesafter;
+ Window *newRoot = (Window *)0;
+
+ if (XGetWindowProperty(dpy, children[i],
+ __SWM_VROOT, 0, 1, False, XA_WINDOW,
+ &actual_type, &actual_format,
+ &nitems, &bytesafter,
+ (unsigned char **) &newRoot) == Success
+ && newRoot) {
+ root = *newRoot;
+ break;
+ }
+ }
+ if (children)
+ XFree((char *)children);
+ }
+
+ save_screen = screen;
+ }
+
+ return root;
+}
+
+#undef RootWindowOfScreen
+#define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
+
+#undef RootWindow
+#define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
+
+#undef DefaultRootWindow
+#define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
+
+#endif /* _VROOT_H_ */
OpenPOWER on IntegriCloud