From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 11-SEP-1992 23:59:35.83
To:	info-vax@kl.sri.com
CC:	
Subj:	Re: HLL equiv of DCL SHOW DISPLAY

In article <1992Sep5.002240.1@musctn.monsanto.com>, rewise@musctn.monsanto.com 
(Richard Wiseman - VAX/VMS CraftsPerson) writes:
> 	DECWindows people:
> 
> 	I'an in need of a routine or the system services that will allow
> me to extract the equiv. information as a SHOW DISPLAY disp_name
> does in dcl, only from a HLL.
> 			Thank you in advance
> 
> 				...rew

I wrote this some time ago. It also includes other information besides the
node name.
No Warranty implied.

**** long ****
************************
xservername.txt


								August 9th,1990


XServerName - 

This program is intended to be used for the remote launching of applications.
It will interrogate the server the user is logged into and assumes that it
is being executed on the node the user wants. ie, multiple set hosts to other
machines may not produce the desired effect.

--------------------
/*
 * Program that will return the name of the x-server the program is
 *	a) run on
 *	b) where the VMS command SET DISPLAY... points to
 *	c) where the usage line on the command line points to
 *
 * into a) a logical name of "X_SERVER_NAME"
 *	b) a symbol (local) name of "X_SERVER_NAME"
 *
 * Note:  The order used is the reverse of the above, ie "C" overrides "B", etc
 *
 * Author:  Steve Garrett
 *
 * Modifications: Highly modified for VMS 5.4. The above behavior has been
 *  2/11/91	  retained, with the addition of new symbols and logicals
 *                as follows:
 *
 *  "X_SERVER_NAME" 		: same as before
 *  "X_SERVER_NODE" 		: node of server
 *  "X_SERVER_SCREEN" 		: screen assigned
 *  "X_SERVER_SERVER" 		: server number
 *  "X_SERVER_TRANSPORT" 	" type of transport
 *
 *  3/19/91 S.G. modified for 5.4-1 behavior
 */

#include <descrip>
#include <iodef>
#include <ssdef>
#include <stsdef>
#include <stdio.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

struct	descriptor_t {			/* descriptor structure		*/
	unsigned short len;
	unsigned char  type;
	unsigned char  class;
	char  *ptr;
	};
typedef struct descriptor_t dsc;

/* $dsc creates a descriptor for a predefined string */

#define	$dsc(name,string) dsc name = { sizeof(string)-1,14,1,string}

/* $dscp creates a descriptor pointing to a buffer allocated elsewhere */

#define $dscp(name,size,addr) dsc name = { size,14,1,addr }

typedef struct _vms_itemlist {
	unsigned short len1;
        unsigned short item1;
        char *buf1;
        int  *retlen1;
    	
        unsigned long end;
    	
} vms_itemlist;
    	

#define NULL 0
#define BUFSIZE 132
#define DECW$C_WS_DSP_NODE 1   	   /*  taken from wsdriver.lis */    	
#define DECW$C_WS_DSP_TRANSPORT 2  /*  taken from wsdriver.lis */    	
#define DECW$C_WS_DSP_SERVER 3     /*  taken from wsdriver.lis */    	
#define DECW$C_WS_DSP_SCREEN 4     /*  taken from wsdriver.lis */    	

#define IO$M_WS_DISPLAY 0x00000040  /* taken from wsdriver */

int show_params();
int sys$trnlog();
unsigned long chan;
char *ProgramName;

static void usage ()
{
    fprintf (stderr, "usage:  %s [-display displayname]\n",
	     ProgramName);
    exit (1);
}

main (argc, argv)
    int argc;
    char *argv[];
{
    Display *dpy;			/* X connection */
    char *displayname = NULL;		/* server to contact */
    char *xservername = NULL;		/* name of xserver */
    char *tmp_str;			/* temp string storage */
    char server_name[100];
    $dscp(server_name_d,99,server_name); /* descriptor for vms access */
    char server_node[100];
    char server_transport[100];
    char server_screen[100];
    char server_server[100];
    int i;				/* temp variable:  iterator */
    int len;				/* temp variable: str len */
    unsigned int status;

    ProgramName = argv[0];

    for (i = 1; i < argc; i++) {
	char *arg = argv[i];

	if (arg[0] == '-') {
	    switch (arg[1]) {
	      case 'd':
		if (++i >= argc) usage ();
		displayname = argv[i];
		continue;
	      default:
		usage ();
	    }
	} else
	  usage ();
    }

    dpy = XOpenDisplay (displayname);
    if (!dpy) {
	fprintf (stderr, "%s:  unable to open display \"%s\".\n",
		 ProgramName, XDisplayName (displayname));
	exit (1);
    }

    xservername = DisplayString (dpy);
    if ( (xservername[0] == '_') | 
	((xservername[0] == 'W') &
	 (xservername[1] == 'S') &
	 (xservername[2] == 'A'))) { /* this implies a v5.4 system. The return
				    value is a device name, which must be
				    interrogated to find the real information */

	status = sys$assign (descr(xservername), &chan, 0, 0);
	if (!(status & 1)) 
 	    {xservername = " ";}
 	  else
	    {
	    status = get_info (chan, DECW$C_WS_DSP_NODE,
				server_node, &len);
	    if (!(status & 1)) exit (status);

	    status = get_info (chan, DECW$C_WS_DSP_SERVER,
				server_server, &len);
	    if (!(status & 1)) exit (status);

	    status = get_info (chan, DECW$C_WS_DSP_SCREEN,
				server_screen, &len);
	    if (!(status & 1)) exit (status);

	    status = get_info (chan, DECW$C_WS_DSP_TRANSPORT,
				server_transport, &len);
	    if (!(status & 1)) exit (status);

	   strcpy(server_name, server_node);
           if ( !strcmp (server_transport, "DECNET") )
		{
		strcat (server_name, "::");
		}
	     else if ( !strcmp (server_transport, "LOCAL") )
		{
		sys$trnlog(descr("SYS$NODE"), &len, &server_name_d, 0, 0, 0);
		server_name[len] = 0; /* NULL terminate */
		}
	     else
		{
		strcat (server_name, ":");
		};
	   strcat (server_name, server_server);
	   strcat (server_name, ".");
	   strcat (server_name, server_screen);
           }
    }
    else
    {
    strcpy(server_name,xservername);
    };

    lib$set_logical( descr("X_SERVER_NAME"), descr(server_name), 0, 0, 0);
    lib$set_symbol( descr("X_SERVER_NAME"), descr(server_name), 0);

    lib$set_logical( descr("X_SERVER_NODE"), descr(server_node), 0, 0, 0);
    lib$set_symbol( descr("X_SERVER_NODE"), descr(server_node), 0);

    lib$set_logical( descr("X_SERVER_TRANSPORT"), 
	descr(server_transport), 0, 0, 0);
    lib$set_symbol( descr("X_SERVER_TRANSPORT"), 
	descr(server_transport), 0);

    lib$set_logical( descr("X_SERVER_SERVER"), descr(server_server), 0, 0, 0);
    lib$set_symbol( descr("X_SERVER_SERVER"), descr(server_server), 0);

    lib$set_logical( descr("X_SERVER_SCREEN"), descr(server_screen), 0, 0, 0);
    lib$set_symbol( descr("X_SERVER_SCREEN"), descr(server_screen), 0);

    XCloseDisplay (dpy);

    exit (0);
}

/* routine that will return descripter of asciz string */

descr( name )
  char *name;
  {                 
  static $dscp(d1,0,0);
  static $dscp(d2,0,0);
  static $dscp(d3,0,0);
  static $dscp(d4,0,0);
  static $dscp(d5,0,0);
  static $dscp(d6,0,0);
  static dsc *tbl[] = { &d1, &d2, &d3, &d4, &d5, &d6 };
  static int didx = 0;

  if (didx == 6) didx = 0;
  
  tbl[didx]->len = strlen(name);
  tbl[didx]->ptr = name;
  
  return tbl[didx++];
  }


/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**	int get_info (chan, item, ret_str, ret_len)
**
**	Fetch a single characteristics from the pseudo-workstation
**	device and return the information.
**	(Taken and modified from the v5.4 fiche. PPL/SG 2/10/91
**
**  FORMAL PARAMETERS:
**
**      chan:	the device channel
**	item:	the characteristic to show
**	ret_str: str pointer to information
**	ret_len: length of above string
**
**  IMPLICIT INPUTS:
**
**      none
**
**  IMPLICIT OUTPUTS:
**
**      none
**
**  COMPLETION CODES:
**
**      errors returned by SYS$QIO
**
**  SIDE EFFECTS:
**
**      none
**
**--
**/
	
int get_info (chan, item, ret_str, ret_len)
unsigned long chan, item, *ret_len;
char *ret_str;
{
unsigned long iosb[2];
int status;
char itembuf[BUFSIZE];
struct dsc$descriptor itemval;
	
itemval.dsc$w_length = BUFSIZE;
itemval.dsc$b_dtype = 0;
itemval.dsc$b_class = 0;
itemval.dsc$a_pointer = &itembuf[0];
	
status = sys$qiow (0, chan, IO$_SENSEMODE|IO$M_WS_DISPLAY, &iosb, 0, 0,
		   itemval.dsc$a_pointer, 
	    	   itemval.dsc$w_length, 
	    	   item, 0, 0, 0);
if (status != SS$_NORMAL) return(status);
if (iosb[0] != SS$_NORMAL) return(iosb[0]);
	
itemval.dsc$w_length = iosb[1];
*ret_len = iosb[1];
itembuf[*ret_len] = 0;
strcpy( ret_str, &itembuf[0]);	
	
return(status);
}

************************
make.com
$ define x11 decw$include
$ cc/lis xservername 'p1 'p2
$ link xservername,sys$input/opt 'p1
sys$library:decw$dwtlibshr/share
sys$library:decw$xlibshr/share
sys$share:vaxcrtl/share
$ exit

------------------------------------------------------

Steve Garrett
garrett@pacpwr.uucp
503.251.5170

> -- 
> -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>    Richard Wiseman		 VAX-VMS Crafts Person
>    MONSANTO	                Internet:  Rewise@musctn.monsanto.com
>    RR #5 Wiggins Rd.             Yellnet:  +1 (319)262-7528 or 262-7339
>    BOX 473                           FAX:  +1 (319)262-5626
>    Muscatine, Ia 52761        Disclaimer:  All opinions are my own, I think
> -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

