.TITLE LIB_ARGUTILS Subprogram argument list utilities .IDENT /V5.0/ ;++ARGUTILS.MAR ; ; Facility: ; Fermilab Acclerator Control System - ACNET. ; ; Abstract: ; Utility routines to return number of arguments in a subprogram ; call or to test for the existance of an argument. ; ; Environment: ; Called in user mode from a FORTRAN/PASCAL/C routine (usually). ; In FERMILIB.OLB object library. ;-- ; ; Author: F. Nagy ; Modification History: ; ; V1.0 07-Jun-82 FJN Created ; V2.0 08-Jun-82 FJN Changed names. ; V3.0 15-Apr-83 FJN Editted help comments and modified the ; LIB_NARGS routine to use an argument ; V4.0 02-Sep-83 FJN Added routine to return pointer to argument ; list (or to portion of it). ; V5.0 19-Oct-84 FJN Added LIB_FRAMEP routine to return stack frame ; pointer; edited HELP comments ; .PAGE .SUBTITLE Declarations ; ; Include Files: ; ; NONE ; ; Library Macros: ; .NOCROSS $SFDEF ;Stack frame offsets .CROSS ; ; Local Macros: ; ; NONE ; ; Equated Symbols: ; ; NONE ; ; Program section for code ; .PSECT _LIB_CODE,PIC,USR,CON,REL,LCL,SHR,EXE,NOWRT,RD .SHOW BINARY .PAGE .SUBTITLE LIB_NARGS Return number of arguments of caller ;+ LIB_NARGS ; Return the number of arguments in the call to the outer procedure ; (caller of LIB_NARGS). ; ; number.wl.v = LIB_NARGS( [number.wl.r] ) ; ; number longword returning number of arguments (0-255) in ; the argument list passed to the outer procedure (the ; procedure in which LIB_NARGS is called). ; ; The result may be returned in the optional argument as well as via ; the function value. The argument pointer (AP) saved in the stack ; frame is assumed to point to the caller's argument list. ;- .ENTRY LIB_NARGS,^M<> MOVZBL @SF$L_SAVE_AP(FP),R0 ;Get number of arguments using old AP ; value (argument list to caller) TSTB (AP) ;Test for optional argument BEQL 9$ ;If no arguments, just leave now TSTL 4(AP) ;Check for address of longword BEQL 9$ ;If none, really is no argument MOVL R0,@4(AP) ;Return also via argument 9$: RET .PAGE .SUBTITLE LIB_TST_ARG_DFT Test for existant non-default argument ;+ LIB_TST_ARG_DFT ; Test that a specific argument in the argument list of the outer ; (caller of LIB_TST_ARG_DFT) procedure exists and is not defaulted. ; ; exists.wlu.v = LIB_TST_ARG_DFT( n.rbu.r ) ; ; n byte which contains the argument number to tested for. ; Passed by reference. ; ; exists longword value returned as -1 (TRUE) if the n'th argument ; is given in the outer procedure argument list and is not ; defaulted (argument value is non-zero). If n is greater ; than the number of arguments to the outer procedure or if ; the value of the n'th argument is zero, then 0 (FALSE) is ; returned. Passed by value. ; ; The argument pointer (AP) saved in the stack frame is assumed to ; point to the caller's argument list. ;- .ENTRY LIB_TST_ARG_DFT,^M CLRL R0 ;Initialize to return FALSE MOVL SF$L_SAVE_AP(FP),R1 ;Get old AP MOVZBL @4(AP),R2 ;Get argument number for previous call CMPB R2,(R1) ;Compare against (old) number of args. BGTRU 9$ ;If >number arguments, return FALSE TSTL (R1)[R2] ;Check value of the (old) argument BEQL 9$ ;If =0 (default), return FALSE MCOML #0,R0 ;Return TRUE, arg n exists, not default 9$: RET .PAGE .SUBTITLE LIB_ARGPTR Return pointer to argument list ;+ LIB_ARGPTR ; Return a pointer to the argument list in the call to the outer ; (caller) procedure. ; ; address.wl.v = LIB_ARGPTR( [number.rl.v] ) ; ; address longword return the virtual memory address of the part ; of the argument list as specified by the argument to ; this procedure. ; ; number longword determining which argument's address is to be ; returned. If not specified or defaulted (value of 0), ; the address of the argument count (start of the argument ; list) is returned. Otherwise this is the number of the ; argument whose address is returned (as a pointer to a ; portion of the argument list). Passed by value. ; ; If the number parameter exceeds the count of the arguments in the ; argument list being referenced, then 0 is returned as the pointer. ; The argument pointer (AP) saved in the stack frame is assumed to ; point to the caller's argument list. ;- .ENTRY LIB_ARGPTR,^M<> MOVL SF$L_SAVE_AP(FP),R0 ;Get old AP value (points to the ; argument list of our caller) TSTB (AP) ;Test for optional argument BEQL 9$ ;If no arguments, just leave now MOVL 4(AP),R1 ;Get number of argument to point to BEQL 9$ ;Already gotten it if arg. #0 CMPB R1,(R0) ;Check against argument count BGTRU 19$ ;Return 0 (failure) if too large MOVAL (R0)[R1],R0 ;Get pointer to nth argument 9$: RET ; 19$: CLRL R0 ;Argument number out of range! RET .PAGE .SUBTITLE LIB_FRAMEP Return pointer to caller's stack frame ;+ LIB_FRAMEP ; Return a pointer to the stack frame of the outer procedure (the ; caller to LIB_FRAMEP). ; ; framep.wl.va = LIB_FRAMEP() ; ; framep longword returning the virtual memory address of the stack ; frame of the caller of this procedure. ; ; The argument pointer (FP) saved in the stack frame is assumed to ; point to the caller's stack frame. ;- .ENTRY LIB_FRAMEP,^M<> MOVL SF$L_SAVE_FP(FP),R0 ;Get caller's frame pointer RET .END