.TITLE ARGPROCS ROUTINES TO EXAMINE ARGUMENT LISTS ;; ; INTEGER FUNCTION NARGS() ; ; ; Returns, as the function result, the number of actual arguments ; passed to the routine which called NARGS. Omitted actual arguments ; [as in 'CALL X(A,,B)' ] are counted in this total. ; ; .INDEX ARGUMENTS>> ; ; Alan L. Zirkle Naval Surface Weapons Center ; Code K53 ; 28 Jun 1982 Dahlgren, Virginia 22448 ; .PSECT $CODE, LONG,PIC,SHR,EXE,RD,NOWRT .ENTRY NARGS, ^M<> MOVZBL @8(FP),R0 ; 8(FP) IS CALLER'S AP RET ;; ; LOGICAL FUNCTION ARG_EXIST( n ) ; ; ; Returns, as the function result, an indication of whether the Nth ; argument passed to the routine which called ARG_EXIST actually ex- ; ists. The Nth argument will not exist if N > the total number of ; arguments passed or if the Nth argument was omitted [as is the ; second argument in 'CALL X(A,,B)' ]. 'N' is an integer in the ; range (1,255). ; ; NOTE--Character string arguments to FORTRAN subprograms cannot ; ever be omitted unless the corresponding dummy argument is ; either non-existent or not of character data type. This ; means that such arguments can only be 'passed through' to ; another subprogram, as described in routine 'ARG_ADDRESS' ; below. ; ; .INDEX ARGUMENTS>> ; ; Alan L. Zirkle Naval Surface Weapons Center ; Code K53 ; 28 Jun 1982 Dahlgren, Virginia 22448 ; .ENTRY ARG_EXIST, ^M<> MOVZBL @4(AP),R0 ; VALUE OF N IS NOW IN R0 BEQL FALSE ; ZERO IS NOT LEGAL VALUE FOR N CMPB R0,@8(FP) ; 8(FP) IS CALLER'S AP BGTRU FALSE ; BRANCH IF N > TOTAL NUMBER OF ACTUAL ARGS TSTL @8(FP)[R0] ; TEST Nth ACTUAL ARGUMENT ADDRESS--IT WILL ; BE ZERO IF THE ARGUMENT DOESN'T EXIST BEQL FALSE MOVL #1,R0 ; THE ARGUMENT DOES EXIST--RETURN .TRUE. RET FALSE: CLRL R0 ; THE ARGUMENT DOESN'T EXIST--RETURN .FALSE. RET ;; ; INTEGER FUNCTION ARG_ADDRESS( n ) ; ; ; Returns, as the function result, the virtual address of the Nth ; argument passed to the routine which called ARG_ADDRESS. This ; address will be zero if N > the total number of arguments passed ; or if the Nth argument was omitted [as is the second argument in ; 'CALL X(A,,B)' ]. 'N' is an integer in the range (1,255). ; ; NOTE--Character string arguments to FORTRAN subprograms cannot ; ever be omitted unless the corresponding dummy argument is ; either non-existent or not of character data type. This ; means that such arguments can only be 'passed through' to ; another subprogram, by using the mechanism: ; ; SUBROUTINE A ; ADDR=ARG_ADDRESS(1) ; IF (ADDR.NE.0) CALL B(%VAL(ADDR)) ; ; (This does work for character constant strings, since the ; FORTRAN compiler and the linker conspire to change actual ; character string arguments to hollerith when the formal ; argument is not of type CHARACTER. This is documented in ; the FORTRAN manual.) ; ; .INDEX ARGUMENTS>> ; ; Alan L. Zirkle Naval Surface Weapons Center ; Code K53 ; 28 Jun 1982 Dahlgren, Virginia 22448 ; .ENTRY ARG_ADDRESS, ^M<> MOVZBL @4(AP),R0 ; VALUE OF N IS NOW IN R0 BEQL BAD ; ZERO IS NOT LEGAL VALUE FOR N CMPB R0,@8(FP) ; 8(FP) IS CALLER'S AP BGTRU BAD ; BRANCH IF N > TOTAL NUMBER OF ACTUAL ARGS MOVL @8(FP)[R0],R0 ; GET Nth ACTUAL ARGUMENT ADDRESS--IT WILL ; BE ZERO IF THE ARGUMENT DOESN'T EXIST RET BAD: CLRL R0 ; THE ARGUMENT DOESN'T EXIST--RETURN ZERO RET ;; ; INTEGER FUNCTION DEFAULT_ARG( arg_number , default_value ) ; ; ; Returns, as the function result, one of the following values rel- ; ated to the actual arguments passed to the routine which called ; DEFAULT_ARG: ; ; * If the N'th argument (where N = ARG_NUMBER) exists, then its ; actual value is returned. An argument doesn't exist if it is ; nulled out [as in 'CALL X(A,,B)' ] or if the argument list is ; shorter than N. The value is assumed to be a longword. ; ; * If the argument does not exist, the value of DEFAULT_VALUE is ; returned as the function result. It is also assumed to be a ; longword. ; ; .INDEX ARGUMENTS>> ; ; Alan L. Zirkle Naval Surface Weapons Center ; Code K53 ; 10 Apr 1985 Dahlgren, Virginia 22448 ; .ENTRY DEFAULT_ARG,^M<> MOVZBL @4(AP), R0 ; Argument number --> R0 MOVL 8(FP), R1 ; Saved AP --> R1 CMPB R0, (R1) ; Compare requested arg number with no. of args BGTR USEDEF ; Branch if arg number > actual number of args MOVL (R1)[R0], R0 ; Address of requested argument --> R0 BEQL USEDEF ; Address is zero; requested argument is null MOVL (R0), R0 ; Actual value of requested argument --> R0 RET ; Return, function result is in R0 USEDEF: MOVL @8(AP), R0 ; Default value --> R0 RET ; Return, function result is in R0 ;; ; INTEGER FUNCTION DESCRIPTOR( string , strdesc ) ; ; Builds a descriptor for a character string and returns the address ; of this descriptor as the function result. The STRING argument is ; the character string for which the descriptor is desired. The ; argument STRDESC is a quadword (or a two-longword array) in which ; the descriptor is to be built. The functional result returned is ; the address of STRDESC. ; ; STRING must be a character constant or a character string variable ; or a substring; it may not be a character expression with concate- ; nation operators. ; ; One use for this function is in building an argument list array to ; be the first argument to LIB$CALLG. ; ; .INDEX STRING MANIPULATION>> ; ; Alan L. Zirkle Naval Surface Weapons Center ; Code K53 ; 18 Jun 1985 Dahlgren, Virginia 22448 ; .ENTRY DESCRIPTOR, ^M<> MOVL 8(AP), R0 MOVQ @4(AP),(R0) RET .END