.TITLE DTR_CHKCVT Octal/hexadecimal check/conversion functions .IDENT /V3.1/ ;++DTRCVTHTB.MAR ; ; Facility: ; VAX-11 Datatrieve ; ; Abstract: ; Convert and octal or hexadecimal character string to binary, or ; check for valid octal or hexadecimal character string. ; ; Environment: ; DTRSHR shareable image. ; ;-- ; ; Modification History: ; ; Author: F. Nagy Creation date: 14-Aug-82 ; ; V1.0 14-Aug-82 FJN Created as DTRCVTHTB ; V2.0 16-Aug-82 FJN Changed to DTRCHKCVT ; V3.0 26-Sep-82 FJN Added DTR___CVT_BIN function. ; V3.1 02-Mar-83 FJN Added DTR___QHEX and DTR___CVT_QHTB functions ; ; ; Program section for code ; .PSECT _DTR_CODE,PIC,USR,CON,REL,LCL,SHR,EXE,NOWRT,RD .SHOW BINARY .PAGE .SUBTITLE Check hexadecimal string syntax ;+0DTR___CHK_HEX ; ; Functional Description: ; Checks for valid hexadecimal character string. ; ; Calling Sequence: ; valid.wlu.v = DTR___CHK_HEX(inp-str.rt.dx) ; ; Input Parameters: ; inp-str is the address of the string descriptor for the character ; string to be checked for hexadecimal syntax. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; valid is TRUE (1) if the character string has valid hexadecimal ; syntax. Otherwise is FALSE (0). ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; NONE ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___CHK_HEX,^M<> MOVAQ -(SP),R0 ;Reserve stack space and get its addr PUSHL #1 ;Flag to ignore blanks PUSHL #8 ;Return quadword value (8 bytes) PUSHL R0 ;Address of output longword (ignored) PUSHAQ @4(AP) ;Address of input string descriptor CALLS #4,G^OTS$CVT_TZ_L BLBS R0,10$ ;Exit with TRUE (=1=SS$_NORMAL) CLRL R0 ;Return FALSE if not valid 10$: RET .PAGE .SUBTITLE Check octal string syntax ;+0DTR___CHK_OCT ; ; Functional Description: ; Checks for valid octal character string. ; ; Calling Sequence: ; valid.wlu.v = DTR___CHK_OCT(inp-str.rt.dx) ; ; Input Parameters: ; inp-str is the address of the string descriptor for the character ; string to be checked for octal syntax. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; valid is TRUE (1) if the character string has valid octal ; syntax. Otherwise is FALSE (0). ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; NONE ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___CHK_OCT,^M<> MOVAL -(SP),R0 ;Reserve stack space and get its addr PUSHL #1 ;Flag to ignore blanks PUSHL #4 ;Return longword value (4 bytes) PUSHL R0 ;Address of output longword (ignored) PUSHAQ @4(AP) ;Address of input string descriptor CALLS #4,G^OTS$CVT_TO_L BLBS R0,10$ ;Exit with TRUE (=1=SS$_NORMAL) CLRL R0 ;Return FALSE if not valid 10$: RET .PAGE .SUBTITLE Convert hexadecimal string to binary ;+0DTR___CVT_HTB ; ; Functional Description: ; Converts a string of hexadecimal characters to binary for Datatrieve ; by providing an interface to the OTS$CVT_TZ_L routine. ; ; Calling Sequence: ; ret-status.wlc.v = DTR___CVT_HTB(value.wl.r,inp-str.rt.dx) ; ; Input Parameters: ; inp-str is the address of the string descriptor for the hexadecimal ; character string. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; value is the address of the longword in which the binary value is ; returned. ; ret-status is the returned condition code. ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; SS$_NORMAL routine successfully completed. ; OTS$_INPCONERR Input conversion error (invalid character, overflow, ; or invalid value-size occurred). ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___CVT_HTB,^M<> PUSHL #1 ;Flag to ignore blanks PUSHL #4 ;Return longword value (4 bytes) PUSHAL @4(AP) ;Address of output longword PUSHAQ @8(AP) ;Address of input string descriptor CALLS #4,G^OTS$CVT_TZ_L RET .PAGE .SUBTITLE Convert hexadecimal string to binary ;+0DTR___CVT_QHTB ; ; Functional Description: ; Converts a string of hexadecimal characters to binary for Datatrieve ; by providing an interface to the OTS$CVT_TZ_L routine. ; ; Calling Sequence: ; ret-status.wlc.v = DTR___CVT_HTB(value.wqu.r,inp-str.rt.dx) ; ; Input Parameters: ; inp-str is the address of the string descriptor for the hexadecimal ; character string. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; value is the address of the quadword in which the binary value is ; returned. ; ret-status is the returned condition code. ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; SS$_NORMAL routine successfully completed. ; OTS$_INPCONERR Input conversion error (invalid character, overflow, ; or invalid value-size occurred). ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___CVT_QHTB,^M<> PUSHL #1 ;Flag to ignore blanks PUSHL #8 ;Return quadword value (8 bytes) PUSHAL @4(AP) ;Address of output longword PUSHAQ @8(AP) ;Address of input string descriptor CALLS #4,G^OTS$CVT_TZ_L RET .PAGE .SUBTITLE Convert octal string to binary ;+0DTR___CVT_OTB ; ; Functional Description: ; Converts a string of octal characters to binary for Datatrieve ; by providing an interface to the OTS$CVT_TO_L routine. ; ; Calling Sequence: ; ret-status.wlc.v = DTR___CVT_OTB(value.wl.r,inp-str.rt.dx) ; ; Input Parameters: ; inp-str is the address of the string descriptor for the octal ; character string. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; value is the address of the longword in which the binary value is ; returned. ; ret-status is the returned condition code. ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; SS$_NORMAL routine successfully completed. ; OTS$_INPCONERR Input conversion error (invalid character, overflow, ; or invalid value-size occurred). ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___CVT_OTB,^M<> PUSHL #1 ;Flag to ignore blanks PUSHL #4 ;Return longword value (4 bytes) PUSHAL @4(AP) ;Address of output longword PUSHAQ @8(AP) ;Address of input string descriptor CALLS #4,G^OTS$CVT_TO_L RET .PAGE .SUBTITLE Convert binary to a hexadecimal string ;+0DTR___QHEX ; ; Functional Description: ; Converts an unsigned quadword value to a string of hexadecimal ; characters for Datatrieve by providing an interface to the ; OTS$CVT_L_TZ routine. ; ; Calling Sequence: ; ret-status.wlc.v = DTR___QHEX(value.rqu.r,out-str.wt.dx) ; ; Input Parameters: ; value is the address of the quadword in which the unsigned binary ; value is found. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; out-str is the address of the string descriptor for the hexadecimal ; character string. ; ret-status is the returned condition code. ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; SS$_NORMAL routine successfully completed. ; OTS$_OUTCONERR output conversion error. ; ; Side Effects: ; Blanks in the input string are ignored. ; ;- .ENTRY DTR___QHEX,^M<> PUSHL #8 ;Convert quadword value (8 bytes) PUSHL #16 ;Sixteen digits, zero filled PUSHAQ @8(AP) ;Address of output string descriptor PUSHAQ @4(AP) ;Address of input quadword CALLS #4,G^OTS$CVT_L_TZ RET .PAGE .SUBTITLE Convert unsigned byte/word to signed longword ;+0DTR___CVT_BIN ; ; Functional Description: ; Converts an unsigned byte/word/longword value into a signed longword. ; ; Calling Sequence: ; ret-status.wlc.v = DTR___CVT_BIN(outval.wl.r,inval,rlu.v,[type.rbu.v]) ; ; Input Parameters: ; inval is an unsigned longword (or byte or word) value to be converted ; to a signed longword value. ; type is an unsigned byte value determining the actual size in bytes ; of the input argument: ; 0 (or missing) is treated as 4, ; 1 uses only the low-order byte of the input longword ; 2 uses only the low-order word of the input longword ; 4 uses the entire input longword ; all other values are treated as illegal arguments. ; ; Implicit Inputs: ; NONE ; ; Output Parameters: ; outval is the address of the longword in which the signed value is to ; be returned. ; ret-status is the returned condition code. ; ; Implicit Outputs: ; NONE ; ; Condition Codes: ; SS$_NORMAL routine successfully completed ; LIB$_INVARG invalid type argument (value not 0,1,2, or 4). ; SS$_INTOVF integer overflow, input longword contained a value ; that (unsigned) was larger than a byte/word value. ; ; Side Effects: ; The low-order byte/word of the input is converted to a signed longword ; even if the SS$_INTOVF condition code is returned. ; ;- .ENTRY DTR___CVT_BIN,^M<> CLRB R0 ;Default to longword-to-longword CMPB (AP),#3 ;Are there 3 arguments? BLSSU 10$ ;If not, use default input type MOVB 12(AP),R0 ;Else get input type from arguments 10$: CASEB R0,#0,#4 ;Casing on input type 19$: .SIGNED_WORD 20$ - 19$ .SIGNED_WORD 21$ - 19$ .SIGNED_WORD 22$ - 19$ .SIGNED_WORD 23$ - 19$ .SIGNED_WORD 24$ - 19$ ; ; Here if type is or >4: illegal argument ; 23$: MOVL #LIB$_INVARG,R0 RET ; ; Here if type=1, convert unsigned byte to signed longword ; 21$: CVTBL 8(AP),@4(AP) ;Convert byte value CMPL 8(AP),#255 ;Check for input overflow of byte value BRB 27$ ; ; Here if type=2, convert unsigned word to signed longword ; 22$: CVTWL 8(AP),@4(AP) ;Convert word value CMPL 8(AP),#65535 ;Check for input overflow of word value 27$: BLEQU 29$ ;If no overflow, return success MOVZWL #SS$_INTOVF,R0 ;Return integer overflow indication RET ; ; Here if type=0 or 4, convert longword to longword ; 20$: 24$: MOVL 8(AP),@4(AP) ;Just copy longword value 29$: MOVZWL #SS$_NORMAL,R0 ;Return success RET .END