From: drew@sscvx1.ssc.gov
Subject: Porting X/Motif/Mrm to SGI from VAX
Organization: Superconducting Super Collider Laboratory
Date: Sun, 4 Oct 1992 21:11:31 GMT

I have been using VAXs and IBM RS/6000s, and now have to port some
applications to SGI.  So far so good, but I have an X/Motif app which
does NOT work!  The story is that this app is built on the VAX using
the VUIT interfact builder (an adequate IB actually).  It does NOT
rely on VAX extensions, etc.  The program I tried to port went fairly
smoothly to the IBM, but will NOT work on the SGI.  It uses a UIL
file, the bomb occurs on MrmFetchWidget.  Here is a very simple program
which just puts up a builletin widget, and a button to exit.  It
compiles ok, but won't run AND I CAN'T FIGURE OUT WHY!!!!  Can anyone
(especially someone from SGI who wants to see their machine used by
a large group of physicists!) help????

------ the uil file called mtest.uil - the program reads mtest.uid

module mtest
    names = case_sensitive

object
    main: XmMainWindow 
        {
        arguments
            {
            XmNx = 95;
            XmNy = 118;
            XmNborderWidth = 1;
            XmNwidth = 254;
            XmNheight = 250;
            };
        controls
                    {
                    XmPushButton 
                        {
                        arguments
                            {
                            XmNx = 91;
                            XmNy = 107;
                            XmNlabelString = 
                            compound_string("byebye");
                            };
                        callbacks
                            {
                            XmNactivateCallback = procedures
                                {
                                byebye(0);
                                };
                            };
                        };
                    };
                };
            };
        };

procedure
!***VUIT_Action Exit ***

    byebye;

end module;

------------------ here is the main program

#include <stdio.h>                      /* For printf and so on. */
#include <Xm/Text.h>
#include <Mrm/MrmAppl.h>                /* Motif Toolkit and MRM */
#include <X11/X.h>

/* The vuit generated application include file.                             */
/* If the user does not specify a directory for the file                    */
/* then the vaxc$include logical needs to be defined to point to the        */
/* directory of the include file.                                           */
/*                                                                          */
/* Include file from VUIT                                                   */
/*      1. VUIT global routine declarations                                 */
/*      2. Global variables                                                 */
/*      3. Literals from UIL code                                           */

/* VUIT routines for the user to call */
void s_error();
int HashFunction();
int HashLookup();
int HashRegister();
void VUIT_Manage();
void VUIT_Unmanage();

/* Motif Global variables */
Display         *display;               /* Display variable */
XtAppContext    app_context;            /* application context */
Widget          toplevel_widget;        /* Root widget ID of application */

MrmHierarchy    s_MrmHierarchy;         /* MRM database hierarchy ID */

/* Literals from the UIL code */


/*
 * Global data
 */
static MrmType class_id;                /* Place to keep class ID*/
static MrmType *dummy_class;            /* and class variable. */
static char *db_filename_vec[] =        /* Mrm.hierachy file list. */
  {
"mtest.uid"
  };
static int db_filename_num =
                (sizeof db_filename_vec / sizeof db_filename_vec [0]);
char *vuit_dummy_ident_value = "VUIT dummy identifier value";
int i;
#define hash_table_limit 500
struct HASH_TABLE_STRUCT
    {
    char        *widget_name;
    Widget      id;
    } hash_table[hash_table_limit + 1];

/*
 * Forward declarations
 */
void byebye();

/*
 * Names and addresses of callback routines to register with Mrm
 */
static MrmRegisterArg reglist [] = {
{"byebye", (caddr_t)byebye}};

static int reglist_num = (sizeof reglist / sizeof reglist[0]);

/*
 * Names and addresses of uil identifiers (if any) to register with Mrm.
 * These identifiers are registered with a dummy value to allow the generated
 * code to run without error.
 * You can avoid the registration of these identifiers by simplying editing
 * this template file (vuit_main_template_c) and removing the following
 * special format comments:
 *      ***VUIT ident registration***
 *      ***VUIT identlist size***
 *      ***VUIT register identifiers***
 * You can provide your own registration of identifiers by calling your own
 * routine in response to a callback (such as the MrmNcreateCallback for your
 * application's main window), or by modifying this template to call your
 * own registration routine.
*/

/*
 * OS transfer point.  The main routine does all the one-time setup and
 * then calls XtAppMainLoop.
 */
unsigned int main(argc, argv)
    unsigned int argc;                  /* Command line argument count. */
    char *argv[];                       /* Pointers to command line args. */
{
    Arg arglist[2];
    int n;

    MrmInitialize();                    /* Initialize MRM before initializing */
                                        /* the X Toolkit. */

    /*
     * If we had user-defined widgets, we would register them with Mrm.here.
     */

    /*
     * Initialize the X Toolkit. We get back a top level shell widget.
     */
    XtToolkitInitialize();

    app_context = XtCreateApplicationContext();
    display = XtOpenDisplay(app_context, NULL, argv[0], "example",
                            NULL, 0, &argc, argv);
    if (display == NULL)
        {
        fprintf(stderr, "%s:  Can't open display\n", argv[0]);
        exit(1);
        }

    n = 0;
    XtSetArg(arglist[n], XmNallowShellResize, True);  n++;
    toplevel_widget = XtAppCreateShell(argv[0], NULL, 
       applicationShellWidgetClass,
                              display, arglist, n);

    /*
     * Open the UID files (the output of the UIL compiler) in the hierarchy
     */
    if (MrmOpenHierarchy(db_filename_num, /* Number of files. */
      db_filename_vec,                    /* Array of file names.  */
      NULL,                               /* Default OS extenstion. */
      &s_MrmHierarchy)                    /* Pointer to returned MRM ID */
      !=MrmSUCCESS)
        s_error("can't open hierarchy");
MrmRegisterNames (reglist, reglist_num);


VUIT_Manage("main");


    /*
     * Realize the top level widget.  All managed children now become visible
     */
    XtRealizeWidget(toplevel_widget);

    /*
     * Sit around forever waiting to process X-events.  We never leave
     * XtAppMainLoop. From here on, we only execute our callback routines.
     */
    XtAppMainLoop(app_context);
}


/*
 * All errors are fatal.
 */
void s_error(problem_string)
    char *problem_string;
{
    printf("%s\n", problem_string);
    exit(0);
}

void VUIT_Manage(widget_name)
    char        *widget_name;
{

    Widget              id;
    Window              pop_window;
    XWindowChanges      values;

    if (HashLookup(widget_name, &id))
        if (XtIsManaged(id))
            {
            pop_window = XtWindow(XtParent(id));
            values.x = values.y = values.width = values.height =
                values.border_width = values.sibling = NULL;
            values.stack_mode = Above;
            XConfigureWindow(display, pop_window, CWStackMode, &values);
            }
        else
            XtManageChild(id);
    else
        {
        MrmFetchWidget(s_MrmHierarchy, widget_name, toplevel_widget, &id,
            &class_id);
        XtManageChild(id);
        HashRegister(widget_name, id);
        }
}

void VUIT_Unmanage(widget_name)
    char        *widget_name;
{
    Widget      id;

    if (HashLookup(widget_name, &id))
        XtUnmanageChild(id);
}

int HashRegister (widget_name, id)
    char                *widget_name;
    Widget              id;
{
    int                 ndx;

    for (ndx = HashFunction(widget_name, hash_table_limit);
        ((hash_table[ndx].widget_name != NULL) &&
            (ndx < hash_table_limit));
        ndx++);
    if (hash_table[ndx].widget_name != NULL)
        for (ndx = 0;
            hash_table[ndx].widget_name != NULL;
            ndx++);
    if (ndx > hash_table_limit)
        return (FALSE);
    else
        {
        hash_table[ndx].widget_name = XtCalloc(1, strlen(widget_name) + 1);
        strcpy(hash_table[ndx].widget_name, widget_name);
        hash_table[ndx].id = id;
        return (TRUE);
        }
}


int HashLookup (name, id)
    char                *name;
    Widget              *id;
{
    int                 ndx;

    for (ndx = HashFunction(name, hash_table_limit);
        ((hash_table[ndx].widget_name != NULL) &&
            (ndx <= hash_table_limit));
        ndx++)
        if (strcmp(name, hash_table[ndx].widget_name) == 0)
            {
            *id = hash_table[ndx].id;
            return (TRUE);
            }

    if (ndx > hash_table_limit)
        for (ndx = 0;
            ((hash_table[ndx].widget_name != NULL) &&
                (ndx <= hash_table_limit));
            ndx++)
            {
            if (strcmp(name, hash_table[ndx].widget_name) == 0)
                {
                *id = hash_table[ndx].id;
                return (TRUE);
                }
            }

    return (FALSE);
}

int HashFunction (name, max)
    char                *name;
    int                 max;

{
#define HashVecSize             20      /* plenty for 31 character names */
typedef union
    {
    short int           intname[HashVecSize];    /* name as vector of ints */
    char                charname[2*HashVecSize]; /* name as vector of chars */
    } HashName;

    HashName            locname;        /* aligned name */
    int                 namelen;        /* length of name */
    int                 namelim;        /* length limit (fullword size) */
    int                 namextra;       /* limit factor remainder */
    int                 code = 0;       /* hash code value */
    int                 ndx;            /* loop index */


    /*
     * Copy the name into the local aligned union.
     * Process the name as a vector of integers, with some remaining characters.
     * The string is copied into a local union in order to force correct
     * alignment for alignment-sensitive processors.
     */
    strcpy (locname.charname, name);
    namelen = strlen (locname.charname);
    namelim = namelen >> 1;             /* divide by 2 */
    namextra = namelen & 1;             /* remainder */

    /*
     * XOR each integer part of the name together, followed by the trailing
     * 0/1 character
     */
    for ( ndx=0 ; ndx<namelim ; ndx++ )
        code = code ^ ((locname.intname[ndx])<<ndx);
    if ( namextra > 0 )
        code = code ^ ((locname.intname[ndx])&0x00FF);

    return (code&0x7FFF) % max;
}


void byebye (w, tag, reason)
Widget          w;
int             *tag;
unsigned long   *reason;
{
exit(0);
}



Newsgroups: comp.sys.sgi