home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
_tr_gete.asm
< prev
next >
Wrap
Assembly Source File
|
1990-10-21
|
5KB
|
142 lines
; _TR_GETE.ASM
;
; by Ralph Davis
; modified by Leonard Zerman
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
PUBLIC __TR_GETENV
EXTRN __PSP:WORD ; C global variable keeps track
; of the program segment prefix
; We'll use this if user has
; DOS 2.x
; Otherwise, we go generic and use
; DOS function 62H
;===================
;
IN_PARMS STRUC
OLD_BP DW ?
DD ? ; Return address
ENV_STR DD ? ; Pointer to requested environment variable
IN_PARMS ENDS
;
;===================
;*****************************************
_TR_GETE_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TR_GETE_TEXT
;-----------------------------------------
;
; __tr_getenv( environment_string);
;
; char *_tr_getenv();
; char *environment_string;
;
; Returns: pointer to requested environment variable
;
;----------
__TR_GETENV PROC FAR
JMP SHORT GO
;
ENV_STR_LEN DW ? ; Length of environmental variable requested
;
GO: PUSH BP ; We'll probably use everybody
MOV BP,SP ; and his Uncle Willie
PUSH DS
PUSH ES
PUSH CX
PUSH SI
PUSH DI
MOV AH,30H ; Get user's DOS version
INT 21H
CMP AL,3 ; 3.0 or better?
JGE _TR_GETENV_COOLDOS
MOV AX,__PSP
MOV DS,AX ; and now in DS
XOR SI,SI
JMP SHORT _TR_GETENV2
;
_TR_GETENV_COOLDOS:
MOV AH,62H ; Get PSP address
INT 21H ; Returns segment address in BX
MOV DS,BX
XOR SI,SI ; DS:SI now points to PSP
;
_TR_GETENV2:
; DS:SI is pointing to the program segment prefix
; Segment address of the environment string is at offset 2CH
; so we add 2CH to SI.
ADD SI,2CH
MOV AX,[SI] ; Pick up segment of env string
MOV ES,AX
XOR DI,DI ; ES:DI now points to environment string
MOV CS:ENV_STR_LEN,DI ; Initialize length counter
LDS SI,[BP].ENV_STR ; Get address of requested variable
PUSH SI ; Save it
XOR AX,AX
_TR_GETENV_FINDNULL:
CMP [SI],AL ; Look for null terminator
JE _TR_GETENV3
CMP BYTE PTR [SI],'a' ; Do we need to convert to uppercase?
JL _TR_GETENV_NEXTCHAR
CMP BYTE PTR [SI],'z'
JG _TR_GETENV_NEXTCHAR
AND BYTE PTR [SI],0DFH ; Convert to uppercase
_TR_GETENV_NEXTCHAR:
INC CS:ENV_STR_LEN ; Bump length count
INC SI
JMP SHORT _TR_GETENV_FINDNULL
_TR_GETENV3:
POP SI ; Restore pointer to parameter passed
CMP CS:ENV_STR_LEN,0 ; Was a null string passed?
JZ _TR_GETENV_ERR
_TR_GETENV4:
MOV CX,CS:ENV_STR_LEN ; CX has length of passed string
PUSH SI ; save its address
REPE CMPSB
POP SI ; and restore it for next time
JNE _TR_GETENV5 ; not this one
INC DI ; move past equal sign
MOV DX,ES ; segment pointer to AX
MOV AX,DI ; offset to BX
JMP SHORT _TR_GETENV_RET
_TR_GETENV5:
MOV CX,255
REPNE SCASB ; AL still contains 00H
CMP BYTE PTR ES:[DI],0 ; are we at the end of environment?
JNE _TR_GETENV4
_TR_GETENV_ERR:
XOR AX,AX ; Return NULL pointer
XOR DX,DX
_TR_GETENV_RET:
POP DI
POP SI
POP CX
POP ES
POP DS
POP BP
RET
__TR_GETENV ENDP
;--------------------------------------------------
_TR_GETE_TEXT ENDS
;*******************************************************
END