From: greg@thirdi.uucp (Greg Holmberg)
Newsgroups: comp.windows.x.motif
Subject: Re: Running Motif application without Motif
Date: 8 Oct 92 22:16:58 GMT
Reply-To: greg@thirdi.UUCP (Greg Holmberg)
Organization: Third Eye Software, Menlo Park, CA

In article <1992Oct8.082708.20904@cc.tut.fi> jaaksi@cc.tut.fi (Jaaksi Ari) writes:
	I've made an application using Motif in SUN.  Now I'd like to
	send my compiled executable program files to somebody who
	doesn't have Motif but only X and Open Windows in his SUN. Is
	it possible to create Motif application so that it includes all
	Motif things inside a program file and doesn't need Motif
	available at the run time? Or do I need all Motif files
	available both when I compile and link and when I run the
	application?

Just make sure you link statically.  With cc this is -Bstatic.  With
gcc this is -static.

Don't forget to send him a fixed up XKeysymDB file with the osf
keysyms.  This is done in the Makefile in the lib/Xm directory.

Also send him the bindings/sun_mit file for him to put in his home
directory as .motifbind.  The .motifbind file is normally loaded by mwm
when it starts up.

You may want to send him mwm since other window managers don't
implement certain things you may depend on (like modal dialog boxes).
Consult your lawyer about the legal implications of shipping mwm
though.  If you don't ship mwm, your user will need a way to load the
.motifbind onto the server.  I've included little program I wrote to do
that.


Greg Holmberg

Third Eye Software, Inc.                415/321-0967 Voice
750 Menlo Avenue, Suite 300             415/321-2066 Fax
Menlo Park, CA  94025                   greg@thirdeye.com


===================================================================

#ifdef __STDC__
# undef _NO_PROTO
# define PARMS(p) p
#else
# define _NO_PROTO
# define PARMS(p) ()
#endif

#define isNil(p) (((void *) (p)) == ((void *) 0))
typedef char *string;
typedef int boolean;
#define true ((boolean) 1)
#define false ((boolean) 0)

#include <stdio.h>
extern int fread PARMS((char *, int, int, FILE *));
extern int fclose PARMS((FILE *));
extern int fprintf PARMS((FILE *, string, ...));

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <Xm/MwmUtil.h>

#include <errno.h>
extern int errno;
extern string sys_errlist[];
extern int sys_nerr;

/* Globals */
Display *display;
Atom MOTIF_BINDINGS;
string progname;


boolean SetBindings(fileName)
string fileName;

{
    FILE		*fileP;
    static unsigned char	buffer[4096];
    int			count;
    static int		mode = PropModeReplace;

    fileP = fopen(fileName, "r");
    if (fileP == NULL)
	return false;

    while ((count = fread((char *) buffer, 1, sizeof(buffer), fileP)) > 0) {
	XChangeProperty (display, RootWindow(display, 0),
	    MOTIF_BINDINGS, 
	    XA_STRING, 8, mode, 
	    buffer, count);

	mode = PropModeAppend;
    }

    fclose(fileP);
    return true;
}


int main(argc, argv)
    int argc;
    string *argv;

{
    progname = argv[0];

    if (argc < 2) {
	fprintf(stderr, "\
Usage: %s <file>\n\
\n\
Loads <file> (usually ~/.motifbind) into the _MOTIF_BINDINGS property of the\n\
root window.  Normally mwm does this for you, but if you want to reload\n\
the bindings without restarting the window manager, or you are not using\n\
mwm, then you should use this tool.\n\
\n\
The bindings determine how your keyboard is interpreted by Motif-based\n\
applications.  If, for example, you find that you can't erase characters\n\
in text widgets, you probably need to load the right set of bindings for\n\
your X server.  After you load the bindings, you must restart your\n\
Motif-based applications.\n\
\n\
For more information, see VirtualBindings(3XM) and mwm(1X).\n\
",
	    progname);
	return 1;
    }

    display = XOpenDisplay(NULL);
    if (isNil(display)) {
	fprintf(stderr, "%s: Can't open display.\n", progname);
	return 1;
    }

    /* Get the atom for the property. */
    MOTIF_BINDINGS = XInternAtom(display, _XA_MOTIF_BINDINGS, False);

    for (++argv; *argv != NULL; ++argv)
	if (!SetBindings(*argv))
	    fprintf(stderr, "%s: Can't open file '%s': %s.\n",
		progname, *argv, sys_errlist[errno]);

    XCloseDisplay(display);
    return 0;
}
Newsgroups: comp.windows.x.motif