From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 18-MAY-1993 08:31:52.08
To:	EVERHART
CC:	
Subj:	Unique process names / parameters in Pascal.

Via: uk.ac.middlesex.vaxa; Tue, 18 May 1993 11:31:21 +0100
Date: Tue, 18 May 93 11:33 GMT
From: "My MIDI is waiting, your DSX's at hand. The AMS is crashing in this sample wonderland." <ANTHONY5@VAXA.MIDDLESEX.AC.UK>
To: INFO-VAX <INFO-VAX@SRI.COM>
Subject: Unique process names / parameters in Pascal.

    I recently wrote the Pascal  routine  that follows my footer which
    sets  the calling processes' process name to an unique string, and
    I thought I'd share it with you because it  shows  one  method  of
    passing  parameters  to  Pascal  from  DCL,  which  was  a  recent
    question.  
    The program also has a  neat  feature  of setting the process name
    with  additional spaces if it is less than 15 characters, so  that
    VMS sees it as different, but we don't.  If that doesn't  give  an
    unique process name, then digits are appended.
    The program takes  the  value  of  the  DCL  symbol SET_PRN as the
    desired process name string.  If the symbol isn't set, the callers
    username is used.
    Therefore the calling sequence should be something like:
    	$ SET_PRN == "Anything."
    	$ RUN <disk>:<directory>SETPRN.EXE
    It shouldn't be too hard to follow what the program does ( despite
    it's klugey nature :-) ), or rewrite it as an individual procedure
    for inclusion  into  other  programs,  or  recode  it into another
    language.   Any problems, feel free to contact me.  All  comments,
    and improvements will also be welcomed.

    Yours virtually,
                                Anthony.
    ____  ____ ______                           >Anthony5@Mdx.Ac.Uk<
    -| | _/ _/_/ ___/ V I R T U A L              ^^^^^^^^^^^^^^^^^^
    -| |/ _/_/ __/ F A N T A S Y           Virtual Fantasy Productions is a
    -|___/_/__/ P R O D U C T I O N S .    non-prophet making organization.

    ----8<----8<----CUT HERE----8<----8<----CUT HERE----8<----8<----

    [ INHERIT ( 'sys$library:starlet',
    		'sys$library:pascal$str_routines',
    		'sys$library:pascal$lib_routines' ) ]
    { Anthony Bowyer-Lowe. Virtual Fantasy Productions. 1993 }
    PROGRAM SetPrn ( Input, Output );

    { This program will set an users' process name to an unique string
    created from the translation of the symbol 'Set_Prn'.  The process
    name will either be the unmodified  string, the string with spaces
    appended to it ( up to the limit of 15 characters ), or the string
    with  a  number appended.  If a number has to be appended  to  the
    string, the string will  be  truncated  to  be  within  the  total
    process name length limit of 15. }

    VAR	Status	:	Unsigned;
    	Pname	:	Varying [ 80 ] of char;
    	Sett	:	Boolean := False;

    Procedure Try_Spaces;

    VAR	Temp	:	Varying [ 15 ] of char;
    	Loop	:	Unsigned := 0;

    Begin
    Temp := Pname;
    While ( not Sett ) and ( ( Temp.length ) < 15 ) do
    	Begin
    	Temp := Temp + ' ';
    	Status := $SetPrn ( Temp );
    	Sett := odd ( Status );
	End;
    End;

    Procedure Append_Digits;

    VAR	Prno	:	Unsigned := 1;
    	Temp	:	Varying [ 15 ] of char;
    	Num	:	Varying [ 15 ] of char;

    Begin
    Temp := Pname;
    While ( not Sett ) do
    	Begin
    	WriteV ( Num, Prno:0 );
    	While ( Temp.length + Num.Length + 1 ) > 15 do
    		Temp.Length := Temp.Length - 1;
    	Status := $SetPrn ( Temp + ' ' + Num );
    	Sett := odd ( Status );
    	Prno := Prno + 1;
    	End;
    End;

    BEGIN
     { Get prefered process name from symbol 'Set_Prn'. }
    Status := Lib$Get_Symbol ( 'Set_Prn', Pname.Body, Pname.Length );
    If not odd ( Status ) then Lib$Stop ( Status );
     { Use the users username if no process name is specified. }
    If Pname.Length = 0 then
    	Begin
    	Lib$GetJPI ( 514, , , , Pname.Body, Pname.Length );
    	If not odd ( Status ) then Lib$Stop ( Status );
    	End;
    Status := Str$Trim ( Pname.Body, Pname, Pname.Length );
    If not odd ( Status ) then Lib$Stop ( Status );
     { Ensure process name is within acceptable length limits. }
    If ( Pname.Length > 15 ) then Pname.Length := 15;
     { Check to see if unmodified process name works. }
    Status := $SetPrn ( Pname );
    Sett := odd ( Status );
     { Check to see if multiple appended spaces give an unique process
       name. }
    If ( not Sett ) then Try_Spaces;
     { Add successive digits to the string until an unique process
       name is created. }
    If ( not Sett ) then Append_Digits;
    END.
    ---8<----8<--- CUT HERE ---8<----8<--- CUT HERE ---8<----8<---

