From:	CSBVAX::MRGATE!info-vax-RELAY@KL.SRI.COM@SMTP 11-FEB-1988 21:47
To:	ARISIA::EVERHART
Subj:	VWS - Spawning a process into a new window


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue 2 Feb 88 14:04:37-PST
Received: by ucbvax.Berkeley.EDU (5.58/1.26)
	id AA26289; Tue, 2 Feb 88 10:41:01 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 31 Jan 88 15:14:17 GMT
From: mcvax!unido!tub!tmpmbx!pengo@uunet.uu.net  (Hans H. Huebner)
Organization: netmbx GbR, Berlin - West Germany
Subject: VWS - Spawning a process into a new window
Message-Id: <75@tmpmbx.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Hello,

since I realized that it is not easily possible to spawn a process into a
new window from DCL, i wrote a replacement for the SPAWN command in C. I
enclosed the Source for NEW_WINDOW, hopefully some of the VAXStation users
out there have use for it.
While compiling you may have problems finding CLIMSGDEF in
SYS$LIBRARY:VAXCDEF.TLB. It is not included in the standard distribution of
VAX C. There have been lots of hints on how to get the complete definition
files in this group lately, if you have problems anyways, feel free to
cantact me at one of the addresses in my .signature.

BTW: Is this still the right group for VMS source postings ?

	Have fun !
			Hans

<- cut here for NEW_WINDOW.SHAR ->
....................... Cut between dotted lines and save ......................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by PENGO
$! on Sunday 31-JAN-1988 15:49:59.44
$!
$! It contains the following 5 files:
$! AAAREADME.TXT MAKE.COM NEW_WINDOW.C NEW_WINDOW.CLD NEW_WINDOW.HLP_DIFF
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="AAAREADME.TXT"
$ Check_Sum_is=174266036
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
XAAAREADME.TXT
X
XNEW_WINDOW is a replacement for the VMS SPAWN command, which
Xmakes use of the window interface on the VAXStation. The command
Xusage is the same as for SPAWN, except for the new qualifier
X
X`009/TITLE=title-string
X
Xwhich allows for a title displayed in the window's title bar to
Xbe specified.
XThe default for the /WAIT qualifier has been changed to /NOWAIT,
Xsince it doesn't normally make sense to wait for a subprocess in
Xa window to terminate.
X
XI use this command to set up a standard set of windows automatically
Xwhen i log on to the VAXStation.
X
XThe program has proven to compile under MicroVMS V4.5b, VAX C V2.3
Xand VWS V3.2. I don't have other versions, so i can't tell about
Xproblems.
XSince the distribution of VAX C doesn't contain all of the required
Xinclude-files you may have to convert some definition files (clidef)
Xfrom MACRO to C. Contact me at one of the adresses below if you need
Xhelp.
X
XYou may want to edit NEW_WINDOW.CLD to change the directory speci-
Xfication in the image-line. Currently it uses the logical name
XVWS_TOOLS, which is defined by MAKE.COM.
X
XI also included a DIFFERENCES-Output of the comparison for a HELP-
Xentries for NEW_WINDOW and SPAWN.
X
XHope you have fun with it,
X`009`009`009`009Hans
X
X--
XHans Huebner, netmbx GbR
Xhuebner@db0tui6.bitnet, huebner@tub.bitnet, pengo@netmbx.uucp
X..!pyramid!tub!netmbx!pengo
XTel.: +49 30 332 40 15
$ GoSub Convert_File
$ File_is="MAKE.COM"
$ Check_Sum_is=50469021
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ Old_Ver = f$ver(1)
X$ Define VWS_Tools 'F$Environment("DEFAULT")'
X$ CC New_Window
X$ Link New_Window,SYS$Input:/Options
XSYS$Share:UISSHR/Share
XSYS$Share:VAXCRTL/Share
X$ Set Command New_Window
X$ New_Window/Title="First Testwindow"/Process="VWS_Test" Show Users
X$ If .Not. Old_Ver Then $ Set Verify
X$ Exit
$ GoSub Convert_File
$ File_is="NEW_WINDOW.C"
$ Check_Sum_is=1666909486
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X/*
V * new_window.c  -- spawn a DCL subprocess in a new window on the VAXStation Sc
Xreen
X *
X *`009`009`009`009`009`00925-Jan-1988`009H.Huebner
X *`009`009`009`009`009`009`009`009pengo@netmbx.UUCP
X *`009`009`009`009`009`009`009`009huebner@db0tui6.BITNET
X *
X * This is Copyright 1988 by Hans Huebner, noncommercial use welcome !
X */
X
X/*
V * includes --`009unfortunately the library SYS$LIBRARY:VAXCDEF.TLB, which cont
Xains
X *`009`009the header files, isn't complete -- UISUSRDEF.H has to be added
X *`009`009by hand with
X *`009`009 $ LIBRARY/TEXT SYS$LIBRARY:VAXCDEF SYS$LIBRARY:UISUSRDEF.H
X *`009`009clidef.h isn't containted in the library, nor does DEC deliver
X *`009`009a C version of this file. You have to extract the MACRO version
X *`009`009of it with
X *`009`009 $ LIBRARY/MACRO/EXTRACT=CLIDEF SYS$LIBRARY:STARLET
X *`009`009This results in a file STARLET.MAR being created, which has to
X * `009`009be edited to contain valid #define-statements instead of the
X *`009`009%EQU's -- The first and last two lines need to be deleted. This
X *`009`009file then should be renamed to CLIDEF.MAR and added to VAXCDEF
X *`009`009as seen above.
X *
X */
X
X#include descrip
X#include stsdef
X#include ssdef
X#include clidef
X#include climsgdef
X#include uisusrdef
X
X
X/*
X * descriptors for argument values
X *
X */
X
Xchar`009_title[64] `009= "Spawned DCL Window";`009$DESCRIPTOR(title, _title);
Xchar`009_devnam[6];`009`009`009`009$DESCRIPTOR(devnam, _devnam);
Xchar`009_termtype[3]`009= "WT";`009`009`009$DESCRIPTOR(termtype, _termtype);
Xchar`009_process[64]`009= "";`009`009`009$DESCRIPTOR(process, _process);
Xchar`009_p1[255]`009= "";`009`009`009$DESCRIPTOR(p1, _p1);
Xchar`009_cli[64]`009= "";`009`009`009$DESCRIPTOR(cli, _cli);
Xchar`009_prompt[64]`009= "";`009`009`009$DESCRIPTOR(prompt, _prompt);
Xchar`009_input[64]`009= "";`009`009`009$DESCRIPTOR(input, _input);
Xchar`009_output[64]`009= "";`009`009`009$DESCRIPTOR(output, _output);
X
X/*
X * macro which returns NULL if a given string descriptor has the length 0
X * or a pointer to the descriptor otherwise.
X *
X */
X
X#define`009DSCORNULL(p)`009(*(p).dsc$a_pointer ? &(p) : 0)
X
X/*
X * descriptors for command line qualifiers
X *
X */
X
X$DESCRIPTOR(q_wait,`009`009"WAIT");
X$DESCRIPTOR(q_carriage_control,`009"CARRIAGE_CONTROL");
X$DESCRIPTOR(q_logical_names,`009"LOGICAL_NAMES");
X$DESCRIPTOR(q_keypad,`009`009"KEYPAD");
X$DESCRIPTOR(q_symbols,`009`009"SYMBOLS");
X$DESCRIPTOR(q_notify,`009`009"NOTIFY");
X$DESCRIPTOR(q_aligned,`009`009"ALIGNED");
X
X$DESCRIPTOR(q_cli,`009`009"CLI");
X$DESCRIPTOR(q_input,`009`009"INPUT");
X$DESCRIPTOR(q_output,`009`009"OUTPUT");
X$DESCRIPTOR(q_process,`009`009"PROCESS");
X$DESCRIPTOR(q_prompt,`009`009"PROMPT");
X$DESCRIPTOR(q_table,`009`009"TABLE");
X$DESCRIPTOR(q_title,`009`009"TITLE");
X$DESCRIPTOR(q_terminal_type,`009"TERMINAL_TYPE");
X$DESCRIPTOR(q_p1,`009`009"COMMAND");
X
X
X/*
X *`009get_bool_qual`009- determine if a given qualifier is present in the
X *`009`009`009  command line.
X *`009`009`009  returns 1 if qualifier present, 0 if qualifier
X *`009`009`009  negated (/NOqual) and deflt if absent.
X *
X */
X
Xint
Xget_bool_qual(qualdsc, deflt)
X
X`009struct`009dsc$descriptor_s`009*qualdsc;
X`009int`009`009`009`009deflt;
X{`009int`009`009`009`009result;
X
X`009switch (cli$present(qualdsc)) {
X`009`009case CLI$_PRESENT:`009result = 1; break;
X`009`009case CLI$_NEGATED:`009result = 0; break;
X`009`009case CLI$_ABSENT:
X`009`009case CLI$_DEFAULTED:`009result = deflt; break;
X`009`009default:`009`009puts("cli$present returned unsupported value");
X`009}
X`009return(result);
X}
X
X
X/*
X *`009set_val_qual`009- get argument given to a qualifier.
X *`009`009`009  the target descritor is set with the argument
X *`009`009`009  given to the qualifier qual or to deflt if the
X *`009`009`009  qualifier is absent.
X *
X */
X
Xset_val_qual(qual, target, deflt)
X
X`009struct`009dsc$descriptor_s`009*qual;
X`009struct`009dsc$descriptor_s`009*target;
X`009char`009`009`009`009*deflt;
X{
X`009switch (cli$get_value(qual, target, &(target->dsc$w_length))) {
X`009`009case SS$_NORMAL:`009break;
X`009`009case CLI$_ABSENT:`009strcpy(target->dsc$a_pointer, deflt);
X`009`009`009`009`009target->dsc$w_length = strlen(deflt);
X`009`009`009`009`009break;
X`009`009default:`009`009puts("cli$get_value returned unsupported value");
X`009}
X}
X
X
X/*
X *`009main function - command line option parsing is done by DCL
X *
X */
X
X
Xmain()
X
X{`009int`009`009`009`009rc;
X`009unsigned`009`009`009len;
X`009int`009`009`009`009i;
X`009long`009`009`009`009spawn_mask;
X`009struct`009dsc$descriptor_s`009*input_dev;`009/* pointers to input`009*/
X`009struct`009dsc$descriptor_s`009*output_dev;`009/* /output descriptors`009*/
X`009long`009`009`009`009winattr[] = {`009/* window attribute list */
X`009`009`009`009`009`009`009WDPL$C_ATTRIBUTES,
X`009`009`009`009`009`009`009WDPL$M_ALIGNED,
X`009`009`009`009`009`009`009WDPL$C_END_OF_LIST`009};
X
X
X`009/* get boolean qualifiers which affect the behaviour of LIB$SPAWN`009*/
X
X`009spawn_mask =`009  (get_bool_qual(&q_wait, 0)`009`009? 0 : CLI$M_NOWAIT)
X`009`009`009| (get_bool_qual(&q_notify, 0)`009`009? CLI$M_NOTIFY : 0)
X`009`009`009| (get_bool_qual(&q_carriage_control, 1)? 0 : CLI$M_NOCONTROL)
X`009`009`009| (get_bool_qual(&q_keypad, 1)`009`009? 0 : CLI$M_NOKEYPAD)
X`009`009`009| (get_bool_qual(&q_logical_names, 1)`009? 0 : CLI$M_NOLOGNAM)
X`009`009`009| (get_bool_qual(&q_symbols, 1)`009`009? 0 : CLI$M_NOCLISYM);
X
X`009/* get qualifiers which have an associated value`009`009`009*/
X
X`009set_val_qual(&q_title, &title, _title);
X`009set_val_qual(&q_terminal_type, &termtype, _termtype);
X`009set_val_qual(&q_process, &process, _process);
X`009set_val_qual(&q_p1, &p1, _p1);
X`009set_val_qual(&q_cli, &cli, _cli);
X`009set_val_qual(&q_prompt, &prompt, _prompt);
X`009set_val_qual(&q_input, &input, _input);
X`009set_val_qual(&q_output, &output, _output);
X
X`009/* set input/output to the values specified by /INPUT and /OUTPUT or`009*/
X`009/* to the window which gets created`009`009`009`009`009*/
X
X`009input_dev = DSCORNULL(input) ? &input : &devnam;
X`009output_dev = DSCORNULL(output) ? &output : &devnam;
X
X`009/* create a new terminal window`009`009`009`009`009`009*/
X
X`009rc = uis$create_terminal(`009&termtype,
X`009    `009`009`009`009&title,
X`009`009`009`009`009winattr,
X`009`009`009`009`009&devnam,
X`009`009`009`009`009&(devnam.dsc$w_length)`009);
X
X`009/* go and spawn a new subprocess`009`009`009`009`009*/
X
X`009rc = lib$spawn(`009DSCORNULL(p1),
X`009`009`009input_dev,
X`009`009`009output_dev,
X`009`009`009&spawn_mask,
X`009`009`009DSCORNULL(process),
X`009`009`0090, 0, 0, 0, 0,
X`009`009`009DSCORNULL(prompt),
X`009`009`009DSCORNULL(cli)`009`009);
X
X`009if (!($VMS_STATUS_SUCCESS(rc)))
X`009`009sys$exit(rc);
X}
X
$ GoSub Convert_File
$ File_is="NEW_WINDOW.CLD"
$ Check_Sum_is=1478256538
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
Xdefine type terminal_types
X`009keyword wt, default
X`009keyword tk
X
Xdefine verb new_window
X
X`009image vws_tools:new_window.exe
X
X`009parameter P1 , label=COMMAND
X`009`009value (type=$rest_of_line)
X
X`009qualifier CARRIAGE_CONTROL
X`009qualifier KEYPAD
X`009qualifier NOTIFY
X`009qualifier SYMBOLS
X`009qualifier WAIT
X`009qualifier LOGICAL_NAMES
X
X`009qualifier TITLE
X`009`009value
X
X`009qualifier CLI
X`009`009value (type=$file)
X
X`009qualifier INPUT
X`009`009value (type=$file, default=sys$input)
X
X`009qualifier OUTPUT
X`009`009value (type=$file, default=sys$input)
X
X`009qualifier PROCESS
X`009`009value
X
X`009qualifier PROMPT
X`009`009value (default="$ ")
X
X`009qualifier TABLE
X`009`009value (type=$file)
X
X`009qualifier TERMINAL_TYPE
X`009`009value (type=terminal_types)
$ GoSub Convert_File
$ File_is="NEW_WINDOW.HLP_DIFF"
$ Check_Sum_is=1728421820
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X    1   1 SPAWN
X    2   Creates a subprocess.
X    3    
X    4   Format
X    5    SPAWN [command-string]
X    6   
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X    1   1 NEW_WINDOW
X    2   Creates a subprocess in a new window on the VAXStation Screen.
X    3    
X    4   Format
X    5    NEW_WINDOW [command-string]
X    6   
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X    9    The SPAWN and ATTACH commands cannot be used if your terminal has an
X   10    associated mailbox.
X   11   2 Parameters
X   12   command-string
X   13    A command string of less than 132 characters that is to be executed in
X   14    the context of the created subprocess. When the command completes
X   15    execution, the subprocess terminates and control returns to the parent
X   16    process. If both a command string and the /INPUT qualifier are
X   17    specified, the specified command string executes before additional
X   18    commands are obtained from the /INPUT qualifier.
X   19   2 Qualifiers
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X    9   2 Parameters
X   10   command-string
X   11    A command string which is to be executed by the created subprocess.
V   12    If the /INPUT qualifier is omitted, additional commands can be execute
Xd
X   13    interactively in the new window.
X   14    Specify /INPUT=NL: if you want the subprocess to exit and the window
X   15    to close after the command has been executed.
X   16   2 Qualifiers
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X   25    /NOCLI
X   26    Specifies the command language interpreter (CLI) that will be used by
X   27    the subprocess. The default CLI is that defined in SYSUAF. If you
X   28    specify /CLI, context is copied to the subprocess.
X   29   /INPUT=file-spec
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X   22    Specifies the command language interpreter (CLI) that will be used by
X   23    the subprocess. The default CLI is that defined in SYSUAF.
X   24   /INPUT=file-spec
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X   35    the /INPUT qualifier.  If none is specified, SYS$INPUT is assumed
X   36    (in which case a SPAWN/NOWAIT is aborted if CTRL/Y is typed to
X   37    abort something running in your parent process).
X   38   /KEYPAD (default)
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X   30    the /INPUT qualifier.  If none is specified, SYS$INPUT is assumed.
X   31   /KEYPAD (default)
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X   42   /LOG (default)
X   43    /NOLOG
X   44    Displays the assigned subprocess name and any messages indicating
X   45    transfer of control between processes.
X   46   /LOGICAL_NAMES (default)
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X   35   /LOGICAL_NAMES (default)
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X   59    are written. (Do not specify SYS$COMMAND as a file specification with
X   60    the /NOWAIT qualifier; both parent and subprocess output will be
X   61    displayed simultaneously on your terminal.)
X   62   /PROCESS=subprocess-name
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X   48    are written.
X   49   /PROCESS=subprocess-name
X************
X************
XFile $DISK1:[PENGO.VS]HELPLIB.HLP;1
X   77   /WAIT (default)
X   78    /NOWAIT
X   79    Requires that you wait for the subprocess to terminate before you
X   80    issue another DCL command. The /NOWAIT qualifier allows you to issue
X   81    new commands while the subprocess is running. (Use the /OUTPUT
X   82    qualifier with the /NOWAIT qualifier to avoid displaying both parent
X   83    and subprocess output on the terminal simultaneously.)
X******
XFile $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
X   64   /TITLE=title
X   65    Specifies a string to use as the new window's title. Default is
X   66    "Spawned DCL Window".
X   67   /WAIT
X   68    /NOWAIT (default)
X   69    Requires that you wait for the subprocess to terminate before you
X   70    issue another DCL command. The /NOWAIT qualifier allows you to issue
X   71    new commands while the subprocess is running.
X************
X
XNumber of difference sections found: 7
XNumber of difference records found: 37
X
XDIFFERENCES /IGNORE=()/MERGED=1/OUTPUT=$DISK1:[PENGO.VS]NEW_WINDOW.HLP_DIFF;1-
X    $DISK1:[PENGO.VS]HELPLIB.HLP;1-
X    $DISK1:[PENGO.VS]NEW_WINDOW.HLP;6
$ GoSub Convert_File
$ Exit
-- 
Hans H. Huebner, netmbx     | Telex:  186672 net d
Woerther Str. 36            | DOMAIN: pengo@netmbx.UUCP (sigh)
D-1000 Berlin 20, W.Germany | ..!{{pyramid,unido}!tub,altger}!netmbx!pengo
Phone: (+49 30) 332 40 15   | BITNET: huebner@db0tui6

-------

