[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
__PARGRAB
Retrieve char parameters and Allocate memory
------------------------------------------------------------------------------
Function:
__PARGRAB:FAR
Description:
This procedure will return a pointer to the (char) parameter, whose
number must be passed in AX (not pushed!), in the registers DS:SI,
furthermore, CX will reflect the length of the parameter passed and
the registers ES:DI will point to a memory location (grabbed) of length CX.
Also, CLD will be set and DX:BX will also point to the ES:DI memory
location.
The whole idea is that __PARGRAB makes it easy to work on strings passed
by the function. You can use LODSB and STOSB to work on the string, and
finally pass the string to Clipper using __RETFREE, which also free's the
space grabbed earlier.
Note that it can ONLY be used in Assembly, not in C!
Example:
An Example function will probably be the best way to show how to work
with this function:
Let's define SlashToBack(), a Clipper function that convert's all '/'
characters in a string to '\'. Not very useful but very illustrative
for the ease of use of the Expand Interface Function:
Syntax in Clipper: SlashToBack(cSomeSlashes) --> cSlashesAreBackSlashes
Ok, here we go:
PUBLIC SlashToBac ; 10 char max!
EXTRN __PARGRAB:FAR ; Expand: Get string and grab Memory
EXTRN __RETFREE:FAR ; Expand: Return string and free memory.
SLASH segment 'CODE' ; Start of code segment.
ASSUME cs:SLASH
SlashToBac PROC FAR
push ds
push es
push si
push di
mov ax,1 ; get specifed parameter
call __PARGRAB ; CX,DS:SI,ES:DI and BX...
push cx ; keep CX here..
jcxz s3 ; nothing to do on Zero length..
s1: lodsb ; Actual Work is here..
cmp al,'/'
jne s2
mov al,'\'
s2: stosb
loop s1
s3: pop cx ; restore length
pop di
pop si
pop es
pop ds
call __RETFREE ; CX, DX:BX are used.
ret
SlashToBac ENDP
SLASH ENDS
END
That's it! This is a Clipper callable function that does some work
on a string! And, when Assembly is used, the speed gained is tremendous.
See Also:
__RETFREE
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson