OpenVMS Source-Code Demos

GETJPI_DEMO.BAS

1000	%title "getjpi_demo_xxx.bas"						!
	%ident                      "version 101.1"				! <<<---+--- these must match
	declare string constant k_version = "101.1"		,		! <<<---+			&
				k_program = "getjpi_demo"			!
	!=======================================================================
	! title  : getjpi_demo_xxx.bas
	! author : Neil Rieck (n.rieck@sympatico.ca)
	! created: 2000.05.30
	! ver who when     what
	! --- --- -------- -----------------------------------------------------
	! 100 NSR 20000530 1. original work
	! 101 NSR 20120322 1. renovated before publishing to public domain
	!
	!	remember to update k_version above
	!=======================================================================
	option type=explicit							! no kid stuff
	!
	declare long rc%
	!
	!	pull in some stuff from STARTLET (the compiler is our friend)
	!
	%include "starlet"      %from %library "sys$library:basic$starlet"      ! system services
	%include "$ssdef"       %from %library "sys$library:basic$starlet"      ! ss$
	%include "$jpidef"      %from %library "sys$library:basic$starlet"      ! jpi$
	!
	!	create a new record called ItemRec
	!	(I did this just to show how it could be done,
	!	 it would be better if you used a predefined structure in starlet)
	!
%if %declared (%ITEMREC) = 0 %then
        record ItemRec								! structure of item record
            variant
		case
		    group one
		        word    BuffLen
		        word    ItemCode
		        long    BuffAddr
		        long    RtnLenAdr
		    end group one
		case
		    group two
		        long    List_Terminator
		        long    Junk1
		        long    Junk2
		    end group two
            end variant
        end record ItemRec
%let %ITEMREC = 1
%end %if
	!
	!	create a new datatype called JpiRec
	!
	record JpiRec								! structure of Jpi Record
	   ItemRec ItemVar(0)							! 0 -> 0 items (increase as necessary)
	   long    list_term							! for end-of-list marker
	end record JpiRec							!
	!
	!	now use the new datatype in a declaration statement
	!
	declare	JpiRec	JpiBuf							! Now declare a variable using it
	!
	!	Storage for info returned by GETJpi
	!
	MAP(Jpi)string	ProcName = 15	,					! process name				&
		long	ProcName_L						! length of data written to PROC NAME
	!
	!=======================================================================
	!	Main
	!=======================================================================
	main:
	print k_program +"_"+ k_version
	print string$(len(k_program +"_"+ k_version), asc("="))			! what will the optimizer do with this?
	!
	!	now data-fill the request
	!
	JpiBuf::ItemVar(0)::BuffLen	= 15					! byte-size of our data buffer
	JpiBuf::ItemVar(0)::ItemCode	= Jpi$_Prcnam				! requested data or operation
	JpiBuf::ItemVar(0)::BuffAddr	= LOC( ProcName)			! address of our data buffer
	JpiBuf::ItemVar(0)::RtnLenAdr	= LOC( ProcName_L)			! addr of bytes returned (0 = don't care)
	!
	JpiBuf::LIST_TERM		= Jpi$C_ListEnd				! end of list
	!
	!	Okay, now make the call
	!
	rc% = sys$GetJpiW(,0,,JpiBuf,,,)					!
	!
	!	Okay, now display the results
	!
	print "getjpi-rc: "+str$(rc%)						!
	print "getjpi-ProcName: "+ left$(ProcName,ProcName_L)			!
	!
	end									!