[comp.os.vms] Using sys services/lib routines/message stuff from Pascal.

KEMPKEC@carleton.EDU (Editor's Horror) (11/10/87)

> From:	IN%"'Christopher F. Chiesa' <iuvax!bsu-cs!cfchiesa@rutgers.edu>" 10-NOV-1987 02:27
> 
> Regarding use of assorted system-defined status codes in Vax Pascal, 
> doesn't the statement
> 
> [INHERIT ('SYS$LIBRARY:STARLET')]
> 
> at the top of the program, automatically include for you most, if not
> all, the system-defined status-code values, labels, etc. ?  I found this
> in the Pascal Reference Manual and/or User's Guide (can never quite keep
> the two straight), and it seems to work fine for most everything, EXCEPT:
>

 	Most of them, yes.  A few of the system services are not defined
for you there, but they seem to be a minority.  Also, a lot of the "special"
function masks and bit vectors for the various services aren't in there
-- for these you can get them by SEARCHing everything in SYS$LIBRARY for
the value you need -- you ought to find the symbol name and a value -- just
hardcode these into your program.  (The other, cleaner way is to link in
a macro file that does a $???DEF, but it's more difficult).

> 
> *  SYS$LIBRARY:STARLET (.PEN) ("environment file" - anyone know just what
> THAT means?) does NOT include definitions for the numerous LIB$ routines.
> Annoyingly, one seems forced to "puzzle out" on one's own the appropriate
> declarations for most of these.  Can anyone suggest some "general guide-
> lines" for creating the appropriate declarations?  Specifically, I've had
> trouble getting LIB$GETJPI to return the USERNAME of the person executing
> the program.  Don't want to use pure $GETJPI as defined in STARLET -- too
> many "mysterious" (to me) parameters and data structures needed.
>
> 
> Part of the problem would be solved if someone can tell me how to declare
> a PROCEDURE or FUNCTION so as to allow "optional" parameters - i.e., so
> that you can omit a parameter when actually calling the routine.  I know
> it's possible because the system-service routines defined in STARLET.PEN
> allow you to omit parameters, but I haven't been able to get this to
> work in my own declarations, particularly for LIB$ routines.  Any informa-
> tion would be greatly appreciated; I feel like it shouldn't take much to
> clarify this for me - I feel that I'm just misunderstanding the effects
> of an "attribute" or two somewhere.
> 
> Chris Chiesa,
> Ball State University CS Dept.
> Muncie, IN

[external,asynchronous] function LIB$||whatever|| (
			||declare parameters here||
                        ): unsigned; external;

	will do it for you.  To declare an argument as optional, just:

	paramname : paramtype := %immed 0;

	in the delaration.  This works regardless of type.  For example,
the declaration of LIB$GETJPI is:

[asynchronous, external] function lib$getjpi
  (     item_code       : unsigned;
    var process_id      : unsigned := %immed 0;
        process_name    : packed array[l1..u1: integer] of char := %immed 0;
    var out_value       : [unsafe] unsigned := %immed 0;
    var out_string      : packed array[l2..u2 : integer] of char := %immed 0;
    var out_len         : lib$_word_signed := %immed 0)
                        : unsigned; external;
  
The call would be something like 

  return_status := LIB$GETJPI(JPI$_USERNAME,,,,username);

	where USERNAME is declared as a PACKED ARRAY [1..12] OF CHAR
        and JPI$_USERNAME : [external, value] unsigned;

  Delaring things as [unsafe] is a nifty little trick that allows you to
assign to that parameter anythink that's the same bit size as the parameter
declared.  For example, and [unsafe] UNSIGNED will hold an INTEGER, an
UNSIGNED, a PACKED ARRAY [1..32] OF BOOLEAN, or a pointer to anything. 
With this information most of the declarations in STARLET should be
understandable, except where they try to do "funny" things like declare
procedures as parameters.

	BTW, ".PEN" stands for Pascal ENvirontment, and is a collection
of predeclared routines, types, constants, and variables that get added
to any program which "inherits" them at compile-time.  It's similar in function
(though not in the mechanics) to a %include file.

	I hope this helps.

		--Chris Kempke
		VAX Lab Coordinator
		Carleton College, Northfield MN 55057 (USA)
		KEMPKEC@CARLETON.EDU