home *** CD-ROM | disk | FTP | other *** search
- ;void delete_spc_left(strg);
- ; char *strg;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _delete_spc_left
- _delete_spc_left proc near
- pushf ;
- push di ;
- push si ;
- push ds ;
- mov bx,sp ;BX pts to stack
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bx ;else add 2 to BX
- inc bx ;jump if near
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,ss:dword ptr[bx+10] ;ES:DI pts to string
- lds si,ss:dword ptr[bx+10] ;DS:SI also
- jmp short L00 ;jump ahead
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,ss:[bx+2] ;DI and SI point to Strg
- mov si,di ;
- L00: mov bl,1 ;errorcode 1 = null string
- cmp byte ptr es:[di],0 ;null string?
- je L2 ;quit if null
- cld ;direction forward
- mov al,32 ;seek space char
- mov cx,255 ;max string length
- inc bl ;errorcode 2 = no spaces found
- repe scasb ;seek last of leftmost spaces
- jcxz L2 ;quit if no leading spaces
- dec di ;pull back to char following last space
- L1: mov al,es:[di] ;get char
- mov [si],al ;shift down
- inc di ;forward pointers
- inc si ;
- cmp al,0 ;end of string?
- jne L1 ;loop till finished
- mov bl,0 ;0 = spaces found and deleted
- L2: pop ds ;restore DS and quit
- mov _error_code,bl ;set _error_code
- pop si ;
- pop di ;
- popf ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _delete_spc_left ENDP
- _TEXT ENDS
- END