Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 552 → Rev 553

/programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm
0,0 → 1,99
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
.8087
modstart _7fu8386
 
xdefp __FSU87
xdefp __FDU87
 
defpe __FSU87
sub esp,12
mov [esp],eax
fld dword ptr [esp]
jmp short convert
 
defpe __FDU87
sub esp,12
mov [esp],eax
mov 4[esp],edx
fld qword ptr [esp]
 
; fall through
 
convert:
push ecx
fstp tbyte ptr 4[esp] ; get number out in memory
mov ax,12[esp] ; pick up sign/exponent
and ax,7fffh ; isolate exponent
sub ax,16383 ; remove bias
jl ret_zero ; if less than .5, return zero
cmp ax,64 ; are we too big?
jae ret_inf ; if so, return infinity
mov cl,63 ; calculate shift count
sub cl,al ; ...
mov eax,4[esp] ; pick up mantissa
mov edx,8[esp] ; ...
je negate ; skip out if no shifting
L2:
shr edx,1 ; shift down one bit
rcr eax,1 ; ...
dec cl ; are we done?
jne L2 ; do it again if not
negate:
test byte ptr 13[esp],80h ; is number negative?
jns done ; if not, we're done
neg edx ; negate number
neg eax ; ...
sbb edx,0 ; ...
done:
pop ecx ; ...
add esp,12 ; outta here
ret ; ...
 
ret_zero:
xor edx,edx
xor eax,eax
jmp done
 
ret_inf:
mov edx,0ffffffffh
mov eax,edx
jmp done
endproc __FDU87
endproc __FSU87
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm
0,0 → 1,81
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
.8087
modstart _7u8f386
 
xdefp __U8FD7
xdefp __U8FS7
 
;;;;two_to_64 dw 0000h, 0000h, 0000h, 43f0h ; removed by JBS
 
ULLMXP1:
DB 00H, 00H, 80H, 5FH ; (float)(ULONGLONG_MAX +1)
; (only exponent set)
 
defpe __U8FS7
push edx ; save unsigned int64 (hi)
push eax ; save unsigned int64 (lo)
fild qword ptr [esp] ; load as int64
test byte ptr 07H[esp],80H ; most significant bit set?
jns L$2 ; no, jump
fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as
; as float (because expression is exact
; in powers of 2, so save 4 bytes)
L$2:
pop eax ; correct stack
fstp dword ptr [esp] ; save float and pop coproc stack
pop eax ; return float in eax
ret
endproc __U8FS7
 
defpe __U8FD7
push edx ; save unsigned int64 (hi)
push eax ; save unsigned int64 (lo)
fild qword ptr [esp] ; load as int64
test byte ptr 07H[esp],80H ; most significant bit set?
jns L$3 ; no, jump
fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as
; as float (because expression is exact
; in powers of 2, so save 4 bytes)
L$3:
fstp qword ptr [esp] ; save double and pop coproc stack
pop eax ; return double (lo)
pop edx ; return double (hi)
ret
endproc __U8FD7
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm
0,0 → 1,68
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
; char *__COPY( char *dst, char *src, unsigned len );
;
;
include mdef.inc
 
name __copy
_TEXT segment use32 para public 'CODE'
assume cs:_TEXT
 
public __COPY
public __COPY_
 
__COPY proc near
__COPY_ proc near
push edi ; save regs
push esi ; ...
push ecx ; ...
mov edi,16+0[esp] ; get dst
mov esi,16+4[esp] ; get src
mov ecx,16+8[esp] ; get len
mov eax,edi ; return with dst ptr in eax
shr ecx,2 ; calc. # of dwords
rep movsd ; do the copy
mov ecx,16+8[esp] ; get len
and ecx,3 ; plus extra bytes
rep movsb ; do the copy
pop ecx ; restore regs
pop esi ; ...
pop edi ; ...
ret 12 ; return and remove parms
__COPY_ endp
__COPY endp
 
_TEXT ends
end
/programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm
0,0 → 1,143
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
; __STOSB( char *EAX, int EDX, unsigned ECX );
; __STOSD( char *EAX, int EDX, unsigned ECX );
;
include mdef.inc
include struct.inc
 
modstart __stos,para
 
xdefp __STOSB
xdefp __STOSD
 
 
defpe __STOSB
or ECX,ECX ; if length not zero
_if ne ; then
cmp [EAX],DL ; - access cache line
_loop ; - loop (get onto 4-byte boundary)
test AL,3 ; - - quit if on 4-byte boundary
_quif e ; - - ...
mov [EAX],DL ; - - store byte
inc EAX ; - - increment address
ror EDX,8 ; - - (DH can be different from DL)
dec ECX ; - - decrement length
_until e ; - until done
push ECX ; - save length
shr ECX,2 ; - calculate number of dwords
call __STOSD ; - store dwords
pop ECX ; - restore length
_guess ; - guess: some bytes left to do
and ECX,3 ; - - calculate number of bytes left
_quif e ; - - quit if done
mov [EAX],DL ; - - store a byte
dec ECX ; - - decrement length
_quif e ; - - quit if done
mov 1[EAX],DH ; - - store a byte
dec ECX ; - - decrement length
_quif e ; - - quit if done
mov 2[EAX],DL ; - - store a byte
_endguess ; - endguess
_endif ; endif
ret ; return
endproc __STOSB
 
nop
nop
nop
nop
nop
nop
 
defpe __STOSD
or ECX,ECX ; if length not zero
_if ne ; then
_loop ; - loop (get onto 32-byte boundary)
test AL,1Fh ; - - quit if on 32-byte boundary
_quif e ; - - ...
mov [EAX],EDX ; - - store dword
lea EAX,4[EAX] ; - - increment address
dec ECX ; - - decrement length
_until e ; - until done
push ECX ; - save length
shr ECX,2 ; - calculate number of paragraphs
_if ne ; - if at least one paragraph
dec ECX ; - - decrement # of paragraphs
_if ne ; - - if still have paragraphs to do
_loop ; - - - loop
mov [EAX],EDX ; - - - - store dword
mov 4[EAX],EDX ; - - - - ...
dec ECX ; - - - - decrement count
mov 8[EAX],EDX ; - - - - store dword
mov 12[EAX],EDX ; - - - - ...
je short add16 ; - - - - quit if done
cmp 32[EAX],DL ; - - - - access next cache line
mov 16[EAX],EDX ; - - - - store dword
mov 20[EAX],EDX ; - - - - ...
dec ECX ; - - - - decrement count
mov 24[EAX],EDX ; - - - - store dword
mov 28[EAX],EDX ; - - - - ...
lea EAX,32[EAX] ; - - - - advance to next 32-byte chunk
_until e ; - - - until done
lea EAX,-16[EAX] ; - - - back up 16
add16: lea EAX,16[EAX] ; - - - advance 16
_endif ; - - endif
mov [EAX],EDX ; - - fill last full paragraph
mov 4[EAX],EDX ; - - ...
mov 8[EAX],EDX ; - - ...
mov 12[EAX],EDX ; - - ...
lea EAX,16[EAX] ; - - advance pointer
_endif ; - endif
pop ECX ; - restore length
_guess ; - guess: some dwords left to do
and ECX,3 ; - - calculate number of dwords left
_quif e ; - - quit if done
mov [EAX],EDX ; - - store dword
lea EAX,4[EAX] ; - - advance pointer
dec ECX ; - - decrement length
_quif e ; - - quit if done
mov [EAX],EDX ; - - store dword
lea EAX,4[EAX] ; - - advance pointer
dec ECX ; - - decrement length
_quif e ; - - quit if done
mov [EAX],EDX ; - - store dword
lea EAX,4[EAX] ; - - advance pointer
_endguess ; - endguess
_endif ; endif
ret ; return
endproc __STOSD
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm
0,0 → 1,237
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
; double modf( double value, double *iptr );
;
; Description:
; The modf function breaks the argument value into integral and
; fractional parts, each of which has the same sign as the argument.
; It stores the integral part as a double in the object pointed to
; by iptr.
;
; Returns:
; The modf function returns the signed fractional part of value.
;
; 18-oct-86 ... Fraction in Modf not computed right
; significant digits
;
include mdef.inc
include struct.inc
 
modstart amodf386
 
xdefp __ModF
xdefp __ZBuf2F
 
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
;[]
;[] __ModF
;[]
;[] void __ModF( double near *AX, double near *DX );
;[] Input: EAX - pointer to double precision float
;[] EDX - place to store integral part
;[] Output: [EAX] - fractional part of value.
;[] [EDX] - integral part of value
;[]
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
 
defpe __ModF
push EBP ; save BP
push ESI ; save SI
push EDI ; save DI
push ECX ; save CX
push EBX ; save BX
mov ESI,EDX ; get address for ipart
mov EBP,EAX ; get address of float
mov EAX,0[EBP] ; get float
mov EDX,4[EBP] ; . . .
xchg ESI,EBP ; flip pointers
mov 0[EBP],EAX ; store integral part of value
mov 4[EBP],EDX ; . . .
_guess ; guess: fraction is zero
mov ECX,EDX ; - get exponent
and ECX,7FF00000h ; - get exponent part of R into DI
je short done ; - set integer part to 0 if exponent = 0
cmp ECX,(3FFh+52) shl 20; - check for exponent > 52
_quif b ; - quit if fraction not zero
xchg EBP,ESI ; - get address of fractional part
done: sub EAX,EAX ; - set fraction(or integer) to 0
mov 4[EBP],EAX ; - . . .
mov 0[EBP],EAX ; - . . .
pop EBX ; - restore BX
pop ECX ; - restore CX
pop EDI ; - restore DI
pop ESI ; - restore SI
pop EBP ; - restore BP
ret ; - return
_endguess ; endguess
mov EDI,ECX ; save exponent
shr ECX,20 ; move exponent to bottom
sub CX,03FFh ; remove bias
jb done ; quit if number < 1.0
push EDX ; save sign
sub EAX,EAX ; initialize mask to 0
mov EDX,0FFF00000h ; ...
cmp CL,20 ; if exponent > 20
_if a ; then
sar EDX,21 ; - set ESI to all ones
rcr EAX,1 ; - set high bit of EBX
sub CL,21 ; - get shift count for second part
sar EAX,CL ; - create rest of mask
_else ; else
sar EDX,CL ; - create mask in high part only
_endif ; endif
and 4[EBP],EDX ; mask off the remaining fraction bits
and 0[EBP],EAX ; . . .
not EDX ; complement the mask to get fractional part
not EAX ; . . .
mov EBP,ESI ; get address of fractional part
and EDX,4[EBP] ; get fraction bits
and EAX,0[EBP] ; . . .
call Norm ; normalize the fraction
pop ESI ; restore sign
or EDX,EDX ; if fraction is not 0
_if ne ; then
and ESI,80000000h ; - isolate sign
or EDX,ESI ; - set sign in fractional part
_endif ; endif
mov 4[EBP],EDX ; store fractional part
mov 0[EBP],EAX ; . . .
pop EBX ; restore BX
pop ECX ; restore CX
pop EDI ; restore DI
pop ESI ; restore SI
pop EBP ; restore BP
ret ; return
endproc __ModF
 
 
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;<> <>
;<> __ZBuf2F - convert buffer of significant digits into floating <>
;<> void __ZBuf2F( char near *buf, double near *value ) <>
;<> <>
;<> input: EAX - address of buffer of significant digits <>
;<> EDX - place to store value <>
;<> output: [EDX] - floating point number <>
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
 
defpe __ZBuf2F
push EBP ; save BP
push ESI ; save SI
push EDI ; save DI
push ECX ; save CX
push EBX ; save BX
push EDX ; save pointer to result
mov ESI,EAX ; get address of buffer
sub EDX,EDX ; set 54-bit integer to 0
sub ECX,ECX ; . . .
sub EAX,EAX ; zero out EAX
_loop ; loop (convert digits into 54-bit int)
mov AL,[ESI] ; - get next digit
cmp AL,0 ; - quit if at end of buffer
_quif e ; - . . .
 
;[] multiply current value in EDX:ECX by 10
 
mov EDI,EDX ; - save current value
mov EBX,ECX ; - ...
_shl ECX,1 ; - multiply number by 4
_rcl EDX,1 ; - by shifting left 2 places
_shl ECX,1 ; - . . .
_rcl EDX,1 ; - . . .
add ECX,EBX ; - add original value
adc EDX,EDI ; - (this will make it times 5)
_shl ECX,1 ; - shift left to make it times 10
_rcl EDX,1 ; - . . .
and AL,0Fh ; - isolate binary digit
add ECX,EAX ; - add in current digit
adc EDX,0 ; - . . .
inc ESI ; - point to next digit in buffer
_endloop ; endloop
mov EAX,ECX ; get low order word into EAX
 
;[] Turn the integer in EDX:EAX into a real number
 
mov EDI,(3FFh+52) shl 20; set exponent
call Norm ; convert the 52 bit integer to a float
pop EBP ; restore pointer to result
mov 4[EBP],EDX ; store result
mov 0[EBP],EAX ; . . .
pop EBX ; restore BX
pop ECX ; restore CX
pop EDI ; restore DI
pop ESI ; restore SI
pop EBP ; restore BP
ret ; return to caller
endproc __ZBuf2F
 
 
;[] Norm normalizes an unsigned real in EDX:EAX
;[] expects the exponent to be in EDI. The real returned is in 'packed'
;[] format
;[] ESI is destroyed
 
Norm proc near ; normalize floating point number
sub ESI,ESI ; clear out SI
or ESI,EAX ; see if the integer is zero
or ESI,EDX ; . . .
je short Z_52ret ; if integer is zero, return to caller
test EDX,0FFF00000h ; see if we have to shift forward or backward
_if e ; if (we haven't shifted msb into bit 53)
_loop ; - loop
sub EDI,00100000h ; - - exp <-- exp - 1
_shl EAX,1 ; - - shift integer left by 1 bit
_rcl EDX,1 ; - - . . .
test EDX,0FFF00000h;
_until ne ; - until( msb is shifted into bit 53 )
_else ; else (we must shift to the right)
test EDX,0FFE00000h ; -
je short done1 ; - if msb is bit 53, we are done
_loop ; - loop
add EDI,00100000h ; - - exp <-- exp + 1
shr EDX,1 ; - - shift integer right by 1 bit
rcr EAX,1 ; - - . . .
rcr ESI,1 ; - - save lsb
test EDX,0FFE00000h; -
_until e ; - until( msb is bit 53 )
_rcl ESI,1 ; - get lsb
adc EAX,0 ; - and use it to round off the number
adc EDX,0 ; - . . .
_endif ; endif
done1: and EDX,000FFFFFh ; clear out implied bit
or EDX,EDI ; put in exponent
Z_52ret:ret ; return
endproc Norm
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/bufld386.asm
0,0 → 1,159
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
; This module converts a string to long_double
; void __ZBuf2LD( char *buf, long_double *value );
;
include mdef.inc
include struct.inc
 
modstart bufld386
 
xdefp __ZBuf2LD
 
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;<> <>
;<> __ZBuf2LD - convert buffer of significant digits into floating <>
;<> void __ZBuf2LD( char *buf, long_double *value ) <>
;<> <>
;<> input: EAX - address of buffer of significant digits <>
;<> EDX - place to store value <>
;<> output: [EDX] - floating-point number <>
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
 
defpe __ZBuf2LD
push EBP ; save EBP
push ESI ; save ESI
push EDI ; save EDI
push ECX ; save ECX
push EBX ; save EBX
push EDX ; save pointer to result
mov ESI,EAX ; get address of buffer
sub EDX,EDX ; set 96-bit integer to 0
sub ECX,ECX ; ...
sub EBP,EBP ; ...
sub EAX,EAX ; zero out EAX
_loop ; loop (convert digits into 64-bit int)
mov AL,[ESI] ; - get next digit
cmp AL,0 ; - quit if at end of buffer
_quif e ; - . . .
 
;[] multiply current value in EDX:ECX:EBP by 10
 
mov EDI,EDX ; - save current value
mov EBX,ECX ; - ...
mov EAX,EBP ; - ...
_shl EBP,1 ; - multiply number by 4
_rcl ECX,1 ; - by shifting left 2 places
_rcl EDX,1 ; - ...
_shl EBP,1 ; - ...
_rcl ECX,1 ; - ...
_rcl EDX,1 ; - ...
add EBP,EAX ; - add original value
adc ECX,EBX ; - (this will make it times 5)
adc EDX,EDI ; - ...
_shl EBP,1 ; - shift left to make it times 10
_rcl ECX,1 ; - ...
_rcl EDX,1 ; - ...
sub EAX,EAX ; - zero eax
mov AL,[ESI] ; - get next digit
and AL,0Fh ; - isolate binary digit
add EBP,EAX ; - add in current digit
adc ECX,0 ; - ...
adc EDX,0 ; - ...
inc ESI ; - point to next digit in buffer
_endloop ; endloop
mov EAX,ECX ; get low order word into EAX
 
;[] Turn the integer in EDX:EAX:EBP into a real number
 
mov EDI,3FFFh+63+32 ; set exponent
call Norm ; convert the 64 bit integer to a float
pop EBP ; restore pointer to result
mov 4[EBP],EDX ; store result
mov 0[EBP],EAX ; ...
mov 8[EBP],SI ; ...
pop EBX ; restore EBX
pop ECX ; restore ECX
pop EDI ; restore EDI
pop ESI ; restore ESI
pop EBP ; restore EBP
ret ; return to caller
endproc __ZBuf2LD
 
 
;[] Norm normalizes an unsigned real in EDX:EAX:EBP i.e grab top 64 bits
;[] expects the exponent to be in EDI.
;[] SI contains the new exponent
 
Norm proc near ; normalize floating point number
sub ESI,ESI ; clear out SI
or ESI,EAX ; see if the integer is zero
or ESI,EDX ; ...
or ESI,EBP ; ...
_if ne ; if number is non-zero
or EDX,EDX ; - see if high word is 0
_if e ; - if high word is 0
mov EDX,EAX ; - - shift by 32-bits
mov EAX,EBP ; - - ...
sub EBP,EBP ; - - ...
sub EDI,32 ; - - adjust exponent by 32
_endif ; - endif
or EDX,EDX ; - see if high word is 0
_if e ; - if high word is 0
mov EDX,EAX ; - - shift by 32-bits
mov EAX,EBP ; - - ...
sub EBP,EBP ; - - ...
sub EDI,32 ; - - adjust exponent by 32
_endif ; - endif
_loop ; - loop
or EDX,EDX ; - - quit if high bit is on
_quif s ; - - ...
dec EDI ; - - decrement exponent
_shl EBP,1 ; - - shift integer left by 1 bit
_rcl EAX,1 ; - - ...
_rcl EDX,1 ; - - ...
_endloop ; - endloop
_shl EBP,1 ; - get top bit of extra word
adc EAX,0 ; - round up
adc EDX,0 ; - ...
_if c ; - if carry out the top
rcr EDX,1 ; - - shift fraction back 1
inc EDI ; - - increment exponent
_endif ; - endif
mov ESI,EDI ; - get exponent
_endif ; endif
ret ; return
endproc Norm
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/div386.asm
0,0 → 1,307
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
include mdef.inc
include struct.inc
 
.8087
modstart div386
 
xref __8087 ; indicate that NDP instructions are present
 
datasegment
extrn __real87 : byte ; 8087.asm
extrn __chipbug: byte
enddata
 
xref F8DivZero ; Fstatus
xref F8OverFlow ; Fstatus
xref F8UnderFlow ; Fstatus
xref __fdiv_m64
 
xdefp __FDD
 
; double __FDD( double , double )
sign equ -12
den equ sign-8
quot equ den-12
lo equ 0
hi equ 4
 
defpe __FDD
or EBX,EBX ; if low word of divisor is 0
_if e ; then
_shl ECX,1 ; - shift sign of divisor into carry
_if e ; - if divisor is zero
jmp F8DivZero ; - - handle divide by zero
_endif ; - endif
rcr ECX,1 ; - restore sign of divisor
_endif ; endif
or EAX,EAX ; check dividend for zero
_if e ; if so then
_shl EDX,1 ; - save sign of dividend
_if e ; - if dividend is 0
ret ; - - return
_endif ; - endif
rcr EDX,1 ; - restore sign of dividend
_endif ; endif
 
cmp byte ptr __real87,0 ; if no 80x87 is present
je short __FDDemu ; then emulate
 
__FDD87:
push EDX ; push operand 1
push EAX ; . . .
fld qword ptr [ESP] ; load operand 1
push ECX ; push operand 2
push EBX ; . . .
test byte ptr __chipbug,1 ; have we got a bad divider?
_if ne ; then
call __fdiv_m64 ; - call support rtn for divide
_else ; else
fdiv qword ptr [ESP] ; - divide operand 1 by operand 2
add ESP,8 ; - clean up stack
_endif ; endif
fstp qword ptr [ESP] ; store result
fwait ; wait
pop EAX ; load result into DX:AX
pop EDX ; . . .
cmp EDX,80000000H ; is it a negative zero?
_if e ; if it is then
sub EDX,EDX ; - make it positive 0.0
mov EAX,EDX ; - ...
_endif ; endif
ret ; return
 
__FDDemu:
push EBP ; save EBP
mov EBP,ESP ; get access to stack
push EDI ; save EDI
push ESI ; and ESI
 
mov EDI,EDX ; get high part of op1
mov ESI,ECX ; get high part of op2
sar EDI,20 ; shift exponent to bottom, duplicating sign
sar ECX,20 ; shift exponent to bottom, duplicating sign
and EDI,0800007FFh ; isolate signs and exponent
and ECX,0800007FFh ; ...
rol EDI,16 ; rotate signs to bottom
rol ECX,16 ; ...
add DI,CX ; calc sign of result
rol EDI,16 ; rotate signs to top
rol ECX,16 ; ...
and EDX,000FFFFFh ; isolate fraction
and ESI,000FFFFFh ; isolate fraction
or DI,DI ; if op1 is not a denormal
_if ne ; then
or EDX,00100000h ; - turn on implied 1 bit
_else ; else (denormal)
_loop ; - loop (normalize it)
_shl EAX,1 ; - - shift fraction left
_rcl EDX,1 ; - - . . .
dec DI ; - - decrement exponent
test EDX,00100000h ; - - until implied 1 bit is on
_until ne ; - until implied 1 bit is on
_endif ; endif
or CX,CX ; if op2 is not a denormal
_if ne ; then
or ESI,00100000h ; - turn on implied 1 bit
_else ; else (denormal)
_loop ; - loop (normalize it)
_shl EBX,1 ; - - shift fraction left
_rcl ESI,1 ; - - . . .
dec CX ; - - decrement exponent
test ESI,00100000h ; - - until implied 1 bit is on
_until ne ; - until implied 1 bit is on
_endif ; endif
 
sub DI,CX ; calculate exponent of result
add DI,03ffh ; add in removed bias
_guess ; guess: overflow
_quif s ; - quit if exponent is negative
cmp DI,07FFh ; - quit if not overflow
_quif b ; - . . .
mov EAX,ECX ; - put sign into EAX
pop ESI ; - restore ESI
pop EDI ; - restore EDI
pop EBP ; - restore EBP
jmp F8OverFlow ; - handle overflow
_endguess ; endguess
cmp DI,-52 ; if exponent is too small
_if l ; then underflow
pop ESI ; - restore ESI
pop EDI ; - restore EDI
pop EBP ; - restore EBP
jmp F8UnderFlow ; - handle underflow
_endif ; endif
 
push EDI ; save sign and exponent
mov CL,11 ; shift fractions to top of registers
shld EDX,EAX,CL ; ...
shld EAX,EBP,CL ; ...
and EAX,0FFFFF800h ; ...
shld ESI,EBX,CL ; ...
shld EBX,EBP,CL ; ...
and EBX,0FFFFF800h ; ...
push ESI ; save divisor
push EBX ; ...
mov ECX,ESI ; get top part of divisor
mov EDI,EDX ; get dividend
mov ESI,EAX ; ...
sub EAX,EAX ; assume top bit is 0
cmp ECX,EDX ; check high parts
_if be ; if hi(divisor) <= hi(dividend)
sub EDX,ECX ; - subtract divisor from dividend
inc EAX ; - set quotient to 1
_endif ; endif
push EAX ; save high word of quotient
mov EAX,ESI ; get low part of dividend
div ECX ; estimate next word of quotient
push EAX ; save estimate of quotient (quot+4[EBP])
xchg EAX,EBX ; save quot., get low word of divisor
mul EBX ; calc. estimate * lo(divisor)
xchg EAX,ECX ; ...
xchg EBX,EDX ; save partial product
mul EDX ; calc. estimate * hi(divisor)
add EAX,EBX ; add to partial product
adc EDX,0 ; ...
mov EBX,den+lo[EBP] ; get low word of divisor
test byte ptr quot+8[EBP],1 ; if high word of quot is 1
_if ne ; then
add EAX,EBX ; - add in divisor
adc EDX,den+hi[EBP] ; - ...
_endif ; endif
; subtract estimate * divisor from dividend
neg ECX ; 0 - ECX
sbb ESI,EAX ; ...
sbb EDI,EDX ; ...
_if ne ; if high word not 0 (quotient too big)
_loop ; - loop (find correct quotient)
sub dword ptr quot+4[EBP],1; - - decrement quotient
sbb dword ptr quot+8[EBP],0; - - ...
add ECX,EBX ; - - add divisor back to dividend
adc ESI,den+hi[EBP] ; - - ...
adc EDI,0 ; - - ...
_until e ; - until done
_endif ; endif
mov EDI,ESI ; get new dividend
mov ESI,ECX ; ...
mov ECX,den+hi[EBP] ; get divisor
cmp ECX,EDI ; check high parts 13-aug-90
_if be ; if hi(divisor) <= hi(dividend)
sub EDI,ECX ; - subtract divisor from dividend
add dword ptr quot+4[EBP],1 ; - increment quotient
adc dword ptr quot+8[EBP],0 ; - ...
_endif ; endif
mov EDX,EDI ; get dividend into EDX:EAX
mov EAX,ESI ; ...
div ECX ; estimate next word of quotient
push EAX ; save estimate of quotient (-4[EBP])
or EAX,EAX ; if quotient non-zero
_if ne ; then
xchg EAX,EBX ; - save quot., get low word of divisor
mul EBX ; - calc. estimate * lo(divisor)
xchg EAX,ECX ; - ...
xchg EBX,EDX ; - save partial product
mul EDX ; - calc. estimate * hi(divisor)
add EAX,EBX ; - add to partial product
adc EDX,0 ; - ...
; - subtract estimate * divisor from dividend
neg ECX ; - 0 - ECX
sbb ESI,EAX ; - ...
sbb EDI,EDX ; - ...
_if ne ; - if high word not 0 (quotient too big)
_loop ; - - loop (find correct quotient)
sub dword ptr quot+0[EBP],1; - - - decrement quotient
sbb dword ptr quot+4[EBP],0; - - - ...
sbb dword ptr quot+8[EBP],0; - - - ...
add ECX,den+lo[EBP] ; - - - add divisor back to dividend
adc ESI,den+hi[EBP] ; - - - ...
adc EDI,0 ; - - - ...
_until e ; - - until done
_endif ; - endif
_endif ; endif
pop EAX ; get quotient
pop EDX ; ...
pop EBX ; get high bit
add ESP,8 ; remove divisor
pop EDI ; restore sign and exponent
dec DI ; decrement exponent
shr EBX,1 ; if non-zero
_if c ; then
rcr EDX,1 ; - shift answer right
rcr EAX,1 ; - ...
inc EDI ; - increment exponent
_endif ; endif
sub ESI,ESI ; get zero for zero fill
mov CL,11 ; shift result over
shrd EAX,EDX,CL ; ...
rcr ESI,1 ; save carry
shrd EDX,ESI,CL ; ...
 
or EDX,0FFF00000h ; turn top bits all on
_shl ESI,1 ; get guard bit
adc EAX,0 ; round up
adc EDX,0 ; ...
adc EDI,0 ; increment exponent if required
or DI,DI ; if exponent <= 0
_if le ; then (denormal result)
_if e ; - if exponent = 0
mov CL,1 ; - - set shift count to 1
_else ; - else
neg DI ; - - negate to get shift count
mov CX,DI ; - - ...
_endif ; - endif
and EDX,001FFFFFh ; - isolate fraction
sub EBX,EBX ; - for zero fill
shrd EAX,EDX,CL ; - align the fraction
shrd EDX,EBX,CL ; - ...
sub DI,DI ; - set exponent to 0
_endif ; endif
 
and EDX,000FFFFFh ; isolate fraction
mov ESI,EDI ; get copy of sign
ror EDI,11 ; get exponent
_shl ESI,1 ; get sign
rcr EDI,1 ; put it in
and EDI,0FFF00000h ; isolate sign and exponent
or EDX,EDI ; place it in result
 
pop ESI ; restore registers
pop EDI ; ...
pop EBP ; ...
ret ; return
endproc __FDD
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm
0,0 → 1,85
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;<>
;<> __FDC - floating double comparison
;<> input: EDX:EAX - operand 1
;<> ECX:EBX - operand 2
;<> if op1 > op2, 1 is returned in EAX
;<> if op1 < op2, -1 is returned in EAX
;<> if op1 = op2, 0 is returned in EAX
;<>
;<>
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
include mdef.inc
include struct.inc
 
modstart fdc386
 
xdefp __FDC
 
defpe __FDC
push EBP ; save BP
test EDX,07ff00000h ; check for zero
_if e ; if it is then
sub EDX,EDX ; - make whole damn thing a zero
_endif ; endif
test ECX,07ff00000h ; check op2 for zero
_if e ; if it is then
sub ECX,ECX ; - make whole damn thing a zero
_endif ; endif
mov EBP,ECX ; save op2 exponent
xor EBP,EDX ; see about signs of the operands
mov EBP,0 ; clear result
js short cmpdone ; quif arg1 & arg2 have diff signs
_guess ; guess
cmp EDX,ECX ; - compare high words of arg1, arg2
_quif ne ; - quif not equal
cmp EAX,EBX ; - compare 2nd words of arg1, arg2
_endguess ; endguess
_if ne ; if arg1 <> arg2
rcr ECX,1 ; - save carry in CX
xor EDX,ECX ; - sign of BX is sign of result
 
cmpdone: _shl EDX,1 ; - get sign of result into carry
sbb EBP,0 ; - BP gets sign of result
_shl EBP,1 ; - double BP
inc EBP ; - make BP -1 or 1
_endif ; endif
mov EAX,EBP ; get result
pop EBP ; restore BP
ret ; return to caller
endproc __FDC
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm
0,0 → 1,84
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;=========================================================================
;== Name: FDFS ==
;== Operation: Float double to float single conversion ==
;== Inputs: EDX:EAX double precision float ==
;== Outputs: EAX single precision float ==
;== Volatile: EDX destroyed ==
;=========================================================================
include mdef.inc
include struct.inc
 
modstart fdfs386
 
xdefp __FDFS
 
defpe __FDFS
push EBX ; save EBX
test EDX,07ff00000h ; check exponent
je short retzero ; if exponent = 0 then just return 0
sub EBX,EBX ; set to 0
_shl EAX,1 ; shift number over
_rcl EDX,1 ; ...
rcr EBX,1 ; save sign
add EAX,20000000h ; round floating point number
adc EDX,0 ; ...
je oflow ; overflow if exponent went to 0
cmp EDX,(03ffh+80h) shl 21 ; check for maximum exponent
jae oflow ; overflow if above or equal
cmp EDX,(03ffh-7eh) shl 21 ; check for minimum exponent
jb uflow ; underflow if below
sub EDX,(03ffh-7fh) shl 21 ; correct bias
_shl EAX,1 ; do rest of shift
_rcl EDX,1 ; ...
_shl EAX,1 ; ...
_rcl EDX,1 ; ...
or EDX,EBX ; put in sign bit
mov EAX,EDX ; get result into EAX
pop EBX ; restore EBX
ret ; return
 
oflow: mov EAX,7F800000h ; return maximum possible number
or EAX,EBX ; put in sign bit
pop EBX ; restore EBX
ret ; and return
 
uflow:
retzero:sub EAX,EAX ; set result to 0
pop EBX ; restore EBX
ret
endproc __FDFS
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm
0,0 → 1,144
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
include mdef.inc
include struct.inc
 
modstart fdi4386
 
xdefp __FDI4
xdefp __RDI4
 
xdefp __FDU4
xdefp __RDU4
 
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
;[]
;[] __FDU4 convert double float EDX:EAX into 32-bit integer EAX
;[] Input: EDX:EAX - double precision floating point number
;[] Output: EAX - 32-bit integer
;[]
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
; convert floating double to 4-byte integer with rounding
 
defpe __RDU4
mov AL,80h+20h ; indicate we are rounding
jmp short DtoI ; do it
 
defpe __RDI4
mov AL,80h+1Fh ; indicate we are rounding
jmp short DtoI ; do it
 
defpe __FDI4
mov AL,1Fh ; indicate we are truncating
jmp short DtoI ; do it
 
; convert floating double to 4-byte integer with truncation
 
defpe __FDU4
mov AL,20h ; indicate we are truncating
 
DtoI: _shl EDX,1 ; get sign
rcr AH,1 ; AH <-- sign
shr AH,1 ; shift sign bit over 1
or AH,AL ; get rounding bit
shr EDX,1 ; restore exponent to its place
 
; high bit of AH is rounding bit
; next bit is the sign bit
 
;<~> Shift real right four places so that exponent occupies an entire
;<~> word and the mantissa occupies the remaining words. We do not need
;<~> AX because we only need 32 sig digits
 
push ECX ; save ECX
mov ECX,EDX ; get high part
sar ECX,20 ; get exponent to the bottom
and CX,07FFh ; isolate exponent
sub CX,03FEh ; remove bias from exponent
jl short DIzero ; if |real| < .5 goto DIzero
cmp CX,20h ; if exponent > 32
jg short DIo_f ; goto DIo_flow
and AL,3Fh ; isolate # of significant bits
cmp CL,AL ; quit if number too big
jg short DIo_f ; goto DIo_flow
mov CH,AH ; save rounding/truncation bit
and EDX,000FFFFFh ; isolate top 20 bits of fraction
and EAX,0FFF00000h ; isolate next 12 bits of fraction
or EDX,EAX ; glue them together
rol EDX,12 ; and rotate into position
 
stc ; set carry and
rcr EDX,1 ; restore implied 1/2 bit
 
rcr CH,1 ; save rounding bit
cmp CL,32 ; if want 32 bits
_if e ; then
mov EAX,EDX ; - get them
_shl CH,1 ; - get rounding bit
_else ; else
sub EAX,EAX ; - zero result register
shld EAX,EDX,CL ; - shift answer into EAX
shl EDX,CL ; - shift rounding bit into position
_shl CH,1 ; - get rid of rounding bit from CH
_shl EDX,1 ; - get proper rounding bit
_endif ; endif
mov CL,0FFh ; get mask
rcr CL,1 ; get rounding bit
and CH,CL ; mask it with rounding control bit
_shl CH,1 ; get rounding bit
adc EAX,0 ; add it to the integer to round it up
_shl CH,1 ; get sign
_if c ; if negative
neg EAX ; - negate integer
_endif ; endif
pop ECX ; restore ECX
ret ; return
 
DIo_f:
mov EAX,80000000h ; set answer to largest negative number
pop ECX ; restore ECX
ret ; return
; jmp I4OverFlow ; report overflow
 
DIzero: sub EAX,EAX ; set result to zero
pop ECX ; restore ECX
ret
 
endproc __FDU4
endproc __FDI4
endproc __RDI4
endproc __RDU4
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm
0,0 → 1,151
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
; from double to signed/unsigned int64
;
include mdef.inc
include struct.inc
 
modstart fdi8386
 
xref __U8LS
xref __U8RS
 
; Convert double precision float to unsigned 64-bit integer with truncation
; Input: [EDX, EAX] = 64-bit float
; Output: [EDX, EAX] = 64-bit integer
 
xdefp __FDU8
defp __FDU8
push ECX ; save ECX
mov CX,3ffh+64 ; maximum number 2^64-1
call __FDU ; convert float to unsigned __int64
pop ECX ; restore ECX
ret ; return
endproc __FDU8
 
; Convert double precision float to signed 64-bit integer with truncation
; Input: [EDX, EAX] = 64-bit float
; Output: [EDX, EAX] = 64-bit integer
 
xdefp __FDI8
defp __FDI8
push ECX ; save ECX
mov CX,3ffh+63 ; maximum number 2^63-1
call __FDI ; convert float to signed __int64
pop ECX ; restore ECX
ret ; return
endproc __FDI8
 
__FDI proc near
__FDU: ; what? they both do the same thing
or EDX,EDX ; check sign bit
jns short __FDAbs ; treat as unsigned if positive
call __FDAbs ; otherwise convert number
neg EDX ; negate the result
neg EAX ;
sbb EDX,0 ;
ret ; return
endproc __FDI
 
__FDAbs proc near
or EAX,EAX ; check if number 0
jne short notzero ;
or EDX,EDX ; check if number 0
jne short notzero ;
ret
notzero:
push EBX ; save EBX
_shl EDX,1 ; shift mantissa over
rol EDX,11 ; get exponent to bottom
mov BX,DX ; copy and isolate
and BX,07ffh ; exponent
cmp BX,3ffh ; quit if number < 1.0
jb short dbluflow ; ...
stc ; set carry for implied bit
rcr EDX,1 ; put implied '1' bit in
shr EDX,11 ; remove exponent and extra bit
cmp BX,CX ; check if exponent exceeds maximum
jae short dblmax ; return maximum value if so
sub BX,3ffh+52 ; calculate amount to shift (+ve -> left)
jae short dblm_left ; jump if left shift/no shift
neg BX ; make positive
call __U8RS ; shift mantissa right
pop EBX ; restore EBX
ret ; return
 
dblm_left:
_if ne ; done if exponent exactly 55
call __U8LS ; - shift mantissa left
_endif ; endif
pop EBX ; restore EBX
ret ; return
 
; CX = 3ffh+64 for unsigned
; 3ffh+63 for signed
dblmax:
mov EAX,0FFFFFFFFh ; return maximum value
mov EDX,EAX ;
sub CX,3fFh+64 ; subtract bias + 64, results in 0 or -1
neg CX ; get shift count
mov BX,CX ; set shift count
call __U8RS ; shift mantissa right 1 bit for signed
pop EBX ; restore EBX
ret ; return
 
dbluflow:
sub EAX,EAX ; ensure entire number 0
sub EDX,EDX ;
pop EBX ; restore EBX
ret ; return
 
endproc __FDAbs
 
; Convert double precision float to unsigned 64-bit integer with rounding
; Input: [EDX, EAX] = 64-bit float
 
; xdefp __RDU8
; defp __RDU8
; not implemented
; endproc __RDU8
 
; Convert double precision float to signed 64-bit integer with rounding
; Input: [EDX, EAX] = 64-bit float
 
; xdefp __RDI8
; defp __RDI8
; not implemented
; endproc __RDI8
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm
0,0 → 1,150
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
; These compiler support routines are called by the Fast code generator
; when compiling with the -fpc option.
;
name fdmath
 
extrn __FDA : near
extrn __FDS : near
extrn __FDM : near
extrn __FDD : near
extrn __FDC : near
 
_TEXT segment use32 dword public 'CODE'
assume cs:_TEXT
 
public __FADD
__FADD proc near
push ecx ; save regs
push ebx ; ...
mov ebx,12[esp] ; load op2
mov ecx,16[esp] ; ...
call __FDA ; do the add
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op2
__FADD endp
 
public __FSUB
__FSUB proc near
push ecx ; save regs
push ebx ; ...
mov ebx,12[esp] ; load op2
mov ecx,16[esp] ; ...
call __FDS ; do the subtract
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op2
__FSUB endp
 
public __FSUBR
__FSUBR proc near
push ecx ; save regs
push ebx ; ...
mov ecx,edx ; load op2
mov ebx,eax ; ...
mov eax,12[esp] ; load op1
mov edx,16[esp] ; ...
call __FDS ; do the subtract
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op1
__FSUBR endp
 
public __FMUL
__FMUL proc near
push ecx ; save regs
push ebx ; ...
mov ebx,12[esp] ; load op2
mov ecx,16[esp] ; ...
call __FDM ; do the multiply
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op2
__FMUL endp
 
public __FDIV
__FDIV proc near
push ecx ; save regs
push ebx ; ...
mov ebx,12[esp] ; load op2
mov ecx,16[esp] ; ...
call __FDD ; do the divide
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op2
__FDIV endp
 
public __FDIVR
__FDIVR proc near
push ecx ; save regs
push ebx ; ...
mov ecx,edx ; load op2
mov ebx,eax ; ...
mov eax,12[esp] ; load op1
mov edx,16[esp] ; ...
call __FDD ; do the divide
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op1
__FDIVR endp
 
public __FCMP
__FCMP proc near
push ecx ; save regs
push ebx ; ...
mov ebx,12[esp] ; load op2
mov ecx,16[esp] ; ...
call __FDC ; do the compare
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op2
__FCMP endp
 
public __FCMPR
__FCMPR proc near
push ecx ; save regs
push ebx ; ...
mov ecx,edx ; load op2
mov ebx,eax ; ...
mov eax,12[esp] ; load op1
mov edx,16[esp] ; ...
call __FDC ; do the compare
pop ebx ; restore regs
pop ecx ; ...
ret 8 ; return and remove op1
__FCMPR endp
 
_TEXT ends
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm
0,0 → 1,484
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: REAL*8 math library.
;*
;*****************************************************************************
 
 
;
; inputs: EDX,EAX - operand 1 (high word, low word resp. ) (op1)
; ECX,EBX - operand 2 (op2)
;
; operations are performed as op1 (*) op2 where (*) is the selected
; operation
;
; output: EDX,EAX - result (high word, low word resp. )
;
;
include mdef.inc
include struct.inc
 
.8087
modstart fdmth386
 
xref __8087 ; indicate that NDP instructions are present
 
datasegment
extrn __real87 : byte ; 8087.asm
enddata
 
xref F8DivZero ; Fstatus
xref F8OverFlow ; Fstatus
xref F8UnderFlow ; Fstatus
 
xdefp __FDA ; add real*8 to real*8
xdefp __FDS ; subtract real*8 from real*8
xdefp __FDM ; 8-byte real multiply
 
 
defpe __FDS
xor ECX,80000000h ; flip the sign of op2 and add
 
defpe __FDA
or EBX,EBX ; if low word of op2 is 0
_if e ; then
_shl ECX,1 ; - place sign in carry
je ret_op1 ; - if op2 is 0 then return operand 1
rcr ECX,1 ; - put sign back
_endif ; endif
or EAX,EAX ; if op1 is 0
_if e ; then
_shl EDX,1 ; - place sign in carry
_if e ; - if op1 really is 0
mov EDX,ECX ; - - return operand 2
mov EAX,EBX ; - - . . .
ret_op1: ret ; - - return
_endif ; - endif
rcr EDX,1 ; - put sign back
_endif ; endif
 
cmp byte ptr __real87,0; if 8087 not to be used
je short __FDAemu ; then emulate
 
__FDA87:
push EDX ; push operand 1
push EAX ; . . .
fld qword ptr [ESP] ; load operand 1
push ECX ; push operand 2
push EBX ; . . .
fadd qword ptr [ESP] ; add operand 2 to operand 1
_ret87:
fstp qword ptr 8[ESP]; store result
add ESP,8 ; clean up stack
fwait ; wait
pop EAX ; load result into EDX:EAX
pop EDX ; . . .
cmp EDX,80000000H ; is it a negative zero?
_if e ; if it is then
sub EDX,EDX ; - make it positive 0.0
mov EAX,EDX ; - ...
_endif ; endif
ret ; return
 
__FDAemu:
push EBP ; save EBP
push EDI ; save EDI
push ESI ; save EDI
mov EDI,EDX ; get high part of op1
mov ESI,ECX ; get high part of op2
sar EDI,20 ; shift exponent to bottom, duplicating sign
sar ECX,20 ; shift exponent to bottom, duplicating sign
and EDI,0800007FFh ; isolate signs and exponent
and ECX,0800007FFh ; ...
mov EBP,ECX ; assume op1 < op2
rol EDI,16 ; rotate signs to bottom
rol ECX,16 ; ...
add CX,DI ; calc sign of result
rol EDI,16 ; rotate signs to top
rol ECX,16 ; ...
and EDX,000FFFFFh ; isolate fraction
and ESI,000FFFFFh ; isolate fraction
or DI,DI ; if op1 is not a denormal
_if ne ; then
or EDX,00100000h ; - turn on implied 1 bit
_endif ; endif
or CX,CX ; if op2 is not a denormal
_if ne ; then
or ESI,00100000h ; - turn on implied 1 bit
_endif ; endif
_shl EAX,1 ; shift left 1 to make room for guard bit
_rcl EDX,1 ; ...
_shl EBX,1 ; ...
_rcl ESI,1 ; ...
sub CX,DI ; calculate difference in exponents
_if ne ; if different
_if b ; - if op1 < op2
mov EBP,EDI ; - - get larger exponent for result
neg CX ; - - negate the shift count
xchg EAX,EBX ; - - flip operands
xchg EDX,ESI ; - - . . .
_endif ; - endif
cmp CX,53+1 ; - if shift count too big
_if a ; - then, return operand 1
mov EDX,ESI ; - - get value in correct registers
mov EAX,EBX ; - - . . .
_shl EBP,1 ; - - get sign
rcr EDX,1 ; - - rebuild operand 1
rcr EAX,1 ; - - ...
and EDX,800FFFFFh ; - - ...
ror EBP,13 ; - - rotate exponent into position
and EBP,7FF00000h ; - - ...
or EDX,EBP ; - - put in exponent
pop ESI ; - - restore ESI
pop EDI ; - - restore EDI
pop EBP ; - - restore EBP
ret ; - - return
_endif ; - endif
_endif ; endif
or ECX,ECX ; get bit 0 of sign word - value is 0 if
; both operands have same sign, 1 if not
_if s ; if signs are different
neg ESI ; - negate the fraction of op2
neg EBX ; - . . .
sbb ESI,0 ; - . . .
xor EBP,80000000h ; - flip sign
_endif ; endif
sub EDI,EDI ; get a zero for sticky bits
cmp CL,0 ; if shifting required
_if ne ; then
push EBX ; - save EBX
sub EBX,EBX ; - for zero fill
cmp CL,32 ; - if shift count >= 32
_if ae ; - then
or EAX,EAX ; - - check low order word for 1 bits
setne BL ; - - BL=1 if EAX non zero
mov EDI,EBX ; - - save sticky bits
sub EBX,EBX ; - - for zero fill
mov EAX,EDX ; - - shift right 32
sub EDX,EDX ; - - zero high word
;;; sub CL,32 ; - - adjust shift count
_endif ; - endif
shrd EBX,EAX,CL ; - get the extra sticky bits
or EDI,EBX ; - save them
sub EBX,EBX ; - for zero fill
shrd EAX,EDX,CL ; - align the fractions
shrd EDX,EBX,CL ; - ...
pop EBX ; - restore EBX
_endif ; endif
 
add EAX,EBX ; add the fractions
adc EDX,ESI ; . . .
_if s ; if answer is negative
cmp CL,53 ; - if shift count >= 53
_if ae ; - then
test EDI,7FFFFFFFh ; - - check the sticky bits
setne BL ; - - make single sticky bit
shr EBX,1 ; - - carry set if sticky=1
adc EAX,0 ; - - round up fraction if required
adc EDX,0 ; - - . . .
_endif ; - endif
neg EDX ; - negate the fraction
neg EAX ; - . . .
sbb EDX,0 ; - . . .
xor EBP,80000000h ; - flip the sign
_endif ; endif
mov EBX,EAX ; get result
or EBX,EDX ; if not zero
_if ne ; then
or BP,BP ; - if exponent is 0
je short denormal ; - denormal when exponent hits 0
_loop ; - loop (normalize)
test EDX,7FE00000h ; - - stop when bit slides into exponent field
_quif ne ; - - ...
dec BP ; - - decrement exponent
je short denormal; - - denormal when exponent hits 0
_shl EAX,1 ; - - shift fraction left one bit
_rcl EDX,1 ; - - ...
_endloop ; - endloop
test EDX,00400000h ; - if we got a carry
_if ne ; - then
shr EDX,1 ; - - shift fraction right 1
rcr EAX,1 ; - - ...
adc EDI,0 ; - - keep sticky bit
inc BP ; - - increment exponent
cmp BP,07FFh ; - - quit if overflow
je add_oflow ; - - . . .
_endif ; - endif
; normalize the fraction
shr EDX,1 ; - get guard bit
rcr EAX,1 ; - ...
_if c ; - if guard bit is on
or EDI,EDI ; - - check the sticky bits
setne BL ; - - make single sticky bit
or EBX,EAX ; - - or sticky bit with bottom bit
shr EBX,1 ; - - carry set if sticky=1 or bottom=1
adc EAX,0 ; - - round up fraction if required
adc EDX,0 ; - - . . .
test EDX,00200000h ; - - if we got a carry (02-nov-90)
_if ne ; - - then
shr EDX,1 ; - - - shift fraction right 1
rcr EAX,1 ; - - - ...
inc BP ; - - - increment exponent
cmp BP,07FFh ; - - - quit if overflow
je add_oflow ; - - - . . .
_endif ; - - endif
_endif ; - endif
and EDX,000FFFFFh ; - get rid of implied 1 bit
mov ECX,EBP ; - get sign
shl EBP,21 ; - shift exponent to top
_shl ECX,1 ; - get sign
rcr EBP,1 ; - put it in
or EDX,EBP ; - put exponent and sign into result
_endif ; endif
pop ESI ; restore ESI
pop EDI ; restore EDI
pop EBP ; restore EBP
ret ; return
 
denormal: ; handle denormal
_shl EBP,1 ; get sign
rcr EDX,1 ; put it in result
rcr EAX,1 ; ...
pop ESI ; restore ESI
pop EDI ; restore EDI
pop EBP ; restore EBP
ret ; return
 
add_oflow: ; handle overflow
mov EAX,EBP ; get proper sign for infinity
pop ESI ; restore ESI
pop EDI ; restore EDI
pop EBP ; restore EBP
jmp F8OverFlow ; handle overflow
endproc __FDA
endproc __FDS
;=====================================================================
;<> multiplies X by Y and places result in C.
;<> X2 and X1 represent the high and low words of X. Similarly for Y and C
;<> Special care is taken to use only six registers, so the code is a bit
;<> obscure
 
defpe __FDM
_guess ; guess: one of the operands is 0
or EAX,EAX ; - see if first arg is zero
_quif ne ; - quit if op1 is not 0
_shl EDX,1 ; - place sign in carry
_if e ; - if operand one is 0
ret ; - - return
_endif ; - endif
rcr EDX,1 ; - restore sign
_endguess ; endguess
_guess ; guess: op2 is 0
or EBX,EBX ; - quit if op2 is not 0
_quif ne ; - . . .
_shl ECX,1 ; - place sign in carry
_if e ; - if operand 2 is 0
sub EAX,EAX ; - - set result to 0
sub EDX,EDX ; - - . . .
ret ; - - return
_endif ; - endif
rcr ECX,1 ; - restore sign of op2
_endguess ; endguess
 
cmp byte ptr __real87,0; if 8087 not to be used
je short __FDMemu ; then emulate
 
__FDM87:
push EDX ; push operand 1
push EAX ; . . .
fld qword ptr [ESP] ; load operand 1
push ECX ; push operand 2
push EBX ; . . .
fmul qword ptr [ESP] ; multiply operand 1 by operand 2
jmp _ret87 ; goto common epilogue
 
__FDMemu:
push EBP ; save EBP
push EDI ; save EDI
push ESI ; save EDI
mov EDI,EDX ; get high part of op1
mov ESI,ECX ; get high part of op2
sar EDI,20 ; shift exponent to bottom, duplicating sign
sar ECX,20 ; shift exponent to bottom, duplicating sign
and EDI,0800007FFh ; isolate signs and exponent
and ECX,0800007FFh ; ...
rol EDI,16 ; rotate signs to bottom
rol ECX,16 ; ...
add CX,DI ; calc sign of result
rol EDI,16 ; rotate signs to top
rol ECX,16 ; ...
and EDX,000FFFFFh ; isolate fraction
and ESI,000FFFFFh ; isolate fraction
or DI,DI ; if op1 is a denormal
_if e ; then
inc DI ; - adjust exponent by 1
_loop ; - loop (normalize it) 27-jul-90
dec DI ; - - decrement exponent
_shl EAX,1 ; - - shift left 1
_rcl EDX,1 ; - - ...
test EDX,00100000h ; - - check for implied 1 bit
_until ne ; - until normalized
_endif ; endif
or EDX,00100000h ; turn on implied 1 bit
or CX,CX ; if op2 is a denormal
_if e ; then
inc CX ; - adjust exponent by 1
_loop ; - loop (normalize it) 27-jul-90
dec CX ; - - decrement exponent
_shl EBX,1 ; - - shift left 1
_rcl ESI,1 ; - - ...
test ESI,00100000h ; - - check for implied 1 bit
_until ne ; - until normalized
_endif ; endif
or ESI,00100000h ; turn on implied 1 bit
 
_guess ; guess: overflow
add CX,DI ; - determine exponent of result
sub CX,03ffh ; - remove extra bias
_quif s ; - quit if exponent is negative
cmp CX,07FFh ; - quit if not overflow
_quif b ; - . . .
mov EAX,ECX ; - put sign into EAX
pop ESI ; - restore ESI
pop EDI ; - restore EDI
pop EBP ; - restore EBP
jmp F8OverFlow ; - handle overflow
_endguess ; endguess
cmp CX,-53 ; if exponent is too small
_if l ; then underflow
pop ESI ; - restore ESI
pop EDI ; - restore EDI
pop EBP ; - restore EBP
jmp F8UnderFlow ; - handle underflow
_endif ; endif
push ECX ; save sign and exponent
mov CL,11 ; shift fractions to top of registers
shld EDX,EAX,CL ; ...
shld EAX,EBP,CL ; ...
and EAX,0FFFFF800h ; ...
shld ESI,EBX,CL ; ...
shld EBX,EBP,CL ; ...
and EBX,0FFFFF800h ; ...
 
sub EBP,EBP ; zero EBP
push ESI ; save high part of op2
push EDX ; save high part of op1
push EAX ; save low part of op1
mul EBX ; low part of op1 * low part of op2
xchg EAX,ESI ; ESI becomes start of the sticky bits
mov ECX,EDX ; save high part of result
pop EDX ; restore low part of op1
mul EDX ; low part of op1 * high part of op2
mov EDI,EDX ; save high part of product
add ECX,EAX ; add partial product
adc EDI,EBP ; ...
adc EBP,EBP ; ...
pop EAX ; restore high part of op1
xchg EAX,EBX ; flip with low part of op2
mul EBX ; high part of op1 * low part of op2
add ECX,EAX ; add partial product
adc EDI,EDX ; ...
adc EBP,0 ; ...
mov EAX,EBX ; get high part of op1
pop EDX ; restore high part of op2
mul EDX ; high part of op1 * high part of op2
add EAX,EDI ; add partial product
adc EDX,EBP ; ...
sub EBX,EBX ; get zero for zero fill
mov CL,10 ; shift result over
shrd EBX,EAX,CL ; ... get sticky bits 18-feb-91
shrd EAX,EDX,CL ; ...
shrd EDX,EBX,CL ; ...
pop ECX ; restore sign and exponent
 
_loop ; loop
test EDX,00200000h ; - test to see if bit in exponent field
_quif e ; - quit if not
shr EDX,1 ; - shift result right
rcr EAX,1 ; - . . .
rcr EBX,1 ; - save carry
inc CX ; - inc exponent for every shift
cmp CX,07FFh ; - quit if overflow
je mul_oflow ; - . . .
_endloop ; endloop
_shl EBX,1 ; get guard bit
_if c ; if set
_if e ; - if rest of sticky bits are 0
or ESI,ESI ; - - check the bottom sticky bits
setne BL ; - - ...
shr EBX,1 ; - - if all sticky bits are zero
_if nc ; - - then
mov ESI,EAX ; - - - get bottom bit of result
shr ESI,1 ; - - - as rounding bit
_endif ; - - endif
_endif ; - endif
adc EAX,0 ; - round up
adc EDX,0 ; - ...
test EDX,00200000h ; - test to see if bit in exponent field
_if ne ; - if fraction overflowed
shr EDX,1 ; - - shift right
rcr EAX,1 ; - - ...
inc CX ; - - increment exponent
cmp CX,07FFh ; - - quit if overflow
je mul_oflow ; - - . . .
_endif ; - endif
_endif ; endif
or CX,CX ; if exponent <= 0
_if le ; then (denormal result)
_if e ; - if exponent = 0
mov CL,1 ; - - set shift count to 1
_else ; - else
neg CX ; - - negate to get shift count
dec CX ; - - adjust
_endif ; - endif
sub EBX,EBX ; - for zero fill
shrd EAX,EDX,CL ; - align the fraction
shrd EDX,EBX,CL ; - ...
sub CX,CX ; - set exponent to 0
_endif ; endif
and EDX,000FFFFFh ; isolate fraction
mov ESI,ECX ; get copy of sign
ror ECX,11 ; get exponent
_shl ESI,1 ; get sign
rcr ECX,1 ; put it in
and ECX,0FFF00000h ; isolate sign and exponent
or EDX,ECX ; place it in result
pop ESI ; restore ESI
pop EDI ; restore EDI
pop EBP ; restore EBP
ret ; return
 
mul_oflow: ; overflow
mov EAX,ECX ; get sign of infinity
pop ESI ; restore ESI
pop EDI ; restore EDI
pop EBP ; restore EBP
jmp F8OverFlow ; handle overflow
endproc __FDM
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm
0,0 → 1,59
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: FDN ==
;== Operation: Floating double negate ==
;== Inputs: EDX high word of float ==
;== Outputs: EDX new high word of float ==
;== Volatile: none ==
;========================================================================
include mdef.inc
include struct.inc
 
modstart fdn386
 
xdefp __FDN
 
defpe __FDN
test EDX,EDX ; if non zero number then
_if e
test EAX,EAX
_endif
_if ne ; ...
xor EDX,80000000h ; - flip the sign bit
_endif ; endif
ret ; and return!!!
endproc __FDN
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm
0,0 → 1,180
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
modstart fprem386
 
xdefp __fprem_
 
;
; EDX:EAX ECX:EBX
; void fprem( double x, double modulus, int *quot, double *rem )
;
defpe __fprem_
push EBP ; save BP
mov EBP,ESP ; get access to parms
push EDX ; save registers
push ECX ; ...
push EBX ; ...
push EAX ; ...
mov EAX,8[EBP] ; get argument x
mov EDX,12[EBP] ; ...
mov EBX,16[EBP] ; get modulus
mov ECX,20[EBP] ; ...
or ECX,ECX ; if modulus is zero
_if e ; then
sub EAX,EAX ; - set result to 0
mov EBX,24[EBP] ; - quot = 0
mov [EBX],EAX ; - ...
mov EBX,28[EBP] ; - remainder = 0
mov [EBX],EAX ; - ...
mov 4[EBX],EAX ; - ...
pop EAX ; - restore registers
pop EBX ; - ...
pop ECX ; - ...
pop EDX ; - ...
pop EBP ; - restore EBP
ret ; - return
_endif ; endif
push ESI ; save ESI
push EDI ; save EDI
push EDX ; save sign of operand
push ECX ; save high part of modulus
 
mov ESI,EDX ; get most sig word of op1
mov EDI,ECX ; get most sig word of op2
and ESI,7FF00000h ; isolate exponent
and EDI,7FF00000h ; isolate exponent of modulus
and EDX,000FFFFFh ; isolate mantissa of op1
and ECX,000FFFFFh ; isolate mantissa of modulus
or EDX,00100000h ; set implied 1 bit
or ECX,00100000h ; ...
sub ESI,EDI ; calculate difference in exponents
_if ge ; if operand >= modulus
sub EDI,EDI ; - set quotient to 0
_loop ; - loop
_guess ; - - guess
cmp ECX,EDX ; - - - The purpose of this guess is to
_quif ne ; - - - determine if the divisor will subtract
cmp EBX,EAX ; - - -
je try ; - - -
_endguess ; - - endguess
_if c ; - - if the carry is set (ie the modulus will
; - - - definitely subtract from the dividend
; - - - without a borrow
try:
sub EAX,EBX ; - - - subtract divisor from dividend
sbb EDX,ECX ; - - - . . .
stc ; - - - set carry to indicate that modulus was
; - - - successfully subtracted from dividend
_endif ; - - endif
didnt_go: _rcl EDI,1 ; - - rotate 1 (if carry set) into quotient word
sub ESI,00100000h ; - - adjust difference in exponents
jl _done ; - - quit if done
_shl EAX,1 ; - - shift dividend left
_rcl EDX,1 ; - - . . .
cmp EDX,00200000h
jae try
 
; If bit 5 of dividend is set here, we didnt subtract the modulus from the
; dividend (recall that the divisor has a 1 in the msb -- if we subtracted
; it from the dividend without a borrow, the dividend would not have a one
; in its msb to be shifted into bit 5 tested for in the condition above. If
; we are rotating a bit into bit 5, the dividend is now big enough that we
; can be sure of subtracting out the divisor without a borrow, as we have
; shifted it left one digit.
 
cmp EDX,00100000h
_until b ; - until
 
cmc ; - flip the carry bit
jmp short didnt_go ; - continue
_done: sub ESI,ESI ; - set SI to 0
; normalize the remainder in AL:BX:CX:DX
_guess ; - guess: number is zero
or EAX,EAX ; - - quit if not zero
_quif ne ; - - ...
or EDX,EDX ; - - ...
_quif ne ; - - ...
_admit ; - admit: not zero
_loop ; - - loop
test EDX,00200000h; - - - quit if number is normalized
_quif ne ; - - - . . .
_rcl EAX,1 ; - - - shift result left
_rcl EDX,1
sub ESI,00100000h; - - - decrement exponent
_endloop ; - - endloop
shr EDX,1 ; - - put in correct position
rcr EAX,1 ; - - . . .
add ESI,00100000h ; - - increment exponent
pop ECX ; - - get high part of modulus
push ECX ; - - save it again
and ECX,7FF00000h ; - - isolate exponent of modulus
add ESI,ECX ; - - adjust exponent of result
_endguess ; - endguess
_else ; else
add ESI,EDI ; - restore exponent
sub EDI,EDI ; - set quotient to 0
_endif ; endif
and EDX,000FFFFFh ; keep just the fraction
add EDX,ESI ; update high order word
pop ECX ; restore high part of modulus
pop ESI ; restore sign
and ESI,080000000h ; isolate sign bit
or EDX,EDX ; test high word of remainder
_if ne ; if remainder is non-zero
or EDX,ESI ; - make remainder same sign as original opnd
_endif ; endif
xor ESI,ECX ; calc sign of quotient
_if s ; if quotient should be negative
neg EDI ; - negate quotient
_endif ; endif
mov ESI,24[EBP] ; get address of quotient
mov [ESI],EDI ; store quotient
mov ESI,28[EBP] ; get address of remainder
mov [ESI],EAX ; store remainder
mov 4[ESI],EDX ; ...
pop EDI ; restore EDI
pop ESI ; restore ESI
pop EAX ; restore registers
pop EBX ; ...
pop ECX ; ...
pop EDX ; ...
pop EBP ; restore EBP
ret ; return
endproc __fprem_
 
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm
0,0 → 1,71
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;<>
;<> __FSC compares EAX with EDX
;<> if EAX > EDX, 1 is returned in EAX
;<> if EAX = EDX, 0 is returned in EAX
;<> if EAX < EDX, -1 is returned in EAX
;<>
;<> ========= === =======
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
include mdef.inc
include struct.inc
 
modstart fsc386
 
xdefp __FSC
 
defpe __FSC
_guess have_cmp ; guess - comparison done
xor EAX,EDX ; - check if signs differ
_if ns ; - if signs are the same
xor EAX,EDX ; - - restore EAX
sub EAX,EDX ; - - find difference, EAX=0 if equal
_quif e,have_cmp ; - - done if mantissas also equal
; - - carry=1 iff |EAX| < |EDX|
rcr EAX,1 ; - - EAX sign set iff |EAX| < |EDX|
xor EDX,EAX ; - - EDX sign set iff EAX < EDX
not EDX ; - - EDX sign set iff EAX > EDX
_endif ; - endif
sub EAX,EAX ; - clear result
_shl EDX,1 ; - carry=1 iff EAX > EDX
adc EAX,EAX ; - EAX = 1 iff EAX > EDX, else EAX = 0
_shl EAX,1 ; - EAX = 2 iff EAX > EDX, else EAX = 0
dec EAX ; - EAX = 1 iff EAX > EDX, else EAX = -1
_endguess ; endguess
ret ; return with sign in EAX, conditions set
endproc __FSC
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm
0,0 → 1,89
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;=========================================================================
;== Name: FSFD ==
;== Operation: Float single to float double conversion ==
;== Inputs: EAX single precision float ==
;== Outputs: EDX:EAX double precision float ==
;== Volatile: none ==
;=========================================================================
include mdef.inc
include struct.inc
 
modstart fsfd386
 
xdefp __FSFD
 
defpe __FSFD
_guess ; guess: number is 0.0 or -0.0
mov EDX,EAX ; - get float
and EAX,7fffffffh ; - remove sign
_quif ne ; - quit if number is not +0.0 or -0.0
_admit ; guess: number is +-infinity
cmp EAX,7f800000h ; - quit if not +-infinity
_quif ne ; - ...
or EDX,7ff00000h ; - set double precision infinity
sub EAX,EAX ; - ...
_admit ; admit: not a special number
test EAX,7f800000h ; - if exponent is 0 (denormal number)
_if e ; - then
or EDX,7F800000h ; - - set exponent to 0xFF
_loop ; - - loop (normalize the fraction)
sub EDX,00800000h ; - - - subtract 1 from exponent adjustment
_shl EAX,1 ; - - - shift fraction left
test EAX,00800000h ; - - - check to see if fraction is normalized
_until ne ; - - until normalized
and EDX,0FF800000h ; - - copy fraction back to EDX
and EAX,007FFFFFh ; - - ...
or EDX,EAX ; - - ...
sar EDX,3 ; - shift over 3
and EDX,8FFFFFFFh ; - reset exponent extended bits
add EDX,28200000h ; - adjust exponent by (3FF - FF -7F + 1) shl 20
_else ; - else
sar EDX,3 ; - shift over 3
and EDX,8FFFFFFFh ; - reset exponent extended bits
cmp EAX,7F800000h ; - if number is not number (NaN)
_if a ;
or EDX,7FF00000h; - adjust exponent to NaN 7FF shl 20
_else
add EDX,38000000h; - adjust exponent by (3FF-7F) shl 20
_endif
_endif ; - endif
and EAX,7 ; - get bottom 3 bits of fraction
ror EAX,3 ; - shift them to the top
_endguess ; endguess
ret ; return
endproc __FSFD
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm
0,0 → 1,171
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: FSI4, FSU4, FSI2, FSU2, FSI1, FSU1 ==
;== Operation: Convert single precision to integer ==
;== Inputs: EAX single precision floating point ==
;== Outputs: EAX integer value ==
;== Volatile: none ==
;== ==
;== ==
;== handle -1.0 -> 0xffffffff ==
;========================================================================
include mdef.inc
include struct.inc
 
modstart fsi4386
 
xdefp __FSI4
xdefp __FSU4
xdefp __FSI2
xdefp __FSU2
xdefp __FSI1
xdefp __FSU1
 
defpe __FSI4
push ECX ; save cx
mov cl,7fh+31 ; maximum number 2^31-1
call __FSI ; convert to integer
pop ECX ; restore cx
ret ; return (overflow already handled
endproc __FSI4
 
defpe __FSU4
push ECX ; save cx
mov cl,7fh+32 ; maximum number 2^32-1
call __FSU ; convert to integer
pop ECX ; restore cx
ret ; return if no overflow
endproc __FSU4
 
defpe __FSI2
push ECX ; save cx
mov cl,7fh+15 ; maximum number 2^15-1
call __FSI ; convert to integer
pop ECX ; restore cx
ret ; return (overflow already handled
endproc __FSI2
 
defpe __FSU2
push ECX ; save cx
mov cl,7fh+16 ; maximum number 2^16-1
call __FSU ; convert to integer
pop ECX ; restore cx
ret ; return if no overflow
endproc __FSU2
 
defpe __FSI1
push ECX ; save cx
mov cl,7fh+7 ; maximum number 2^7-1
call __FSI ; convert to integer
pop ECX ; restore cx
ret ; return (overflow already handled
endproc __FSI1
 
 
defpe __FSU1
push ECX ; save cx
mov cl,7fh+8 ; maximum number 2^8-1
call __FSU ; convert to integer
pop ECX ; restore cx
ret ; return if no overflow
endproc __FSU1
 
__FSI proc near
__FSU:
or EAX,EAX ; check sign bit
jns short __FSAbs ; treat as unsigned if positive
call __FSAbs ; otherwise convert number
neg EAX ; negate the result
ret ; and return
endproc __FSI
 
; 18-nov-87 AFS (for WATCOM C)
;__FSU proc near
; jmp
; or dx,dx ; check sign bit
; jns __FSAbs ; just convert if positive
; sub ax,ax ; return 0 if negative
; sub dx,dx ; ...
; ret
; endproc __FSU
 
;========================================================================
;== Name: FSAbs_ ==
;== Inputs: EAX float ==
;== CL maximum exponent excess $7f ==
;== Outputs: EAX integer, absolute value of float ==
;== if exponent >= maximum then 2^max - 1 ==
;== returned ==
;========================================================================
 
__FSAbs proc near
or EAX,EAX ; check if number 0
je short retzero ; if so, just return it
_shl EAX,1 ; shift mantissa over
rol EAX,8 ; get exponent to bottom
cmp AL,7fh ; quit if number < 1.0 15-apr-91
jb short uflow ; ...
mov CH,AL ; save exponent
stc ; set carry for implied bit
rcr EAX,1 ; put implied '1' bit in
shr EAX,8 ; remove exponent
cmp CH,CL ; check if exponent exceeds maximum
jae short retmax ; return maximum value if so
sub CH,7fh+23 ; calculate amount to shift (+ve -> left)
jae short m_left ; jump if left shift/no shift
xchg CH,CL ; get shift count
neg CL ; make positive
shr EAX,CL ; shift mantissa
ret ; return with number
 
m_left:
_if ne ; done if exponent exactly 23
mov CL,CH ; - get shift count
shl EAX,CL ; - shift number left
_endif ; endif
ret ; return
 
retmax: mov EAX,0FFFFFFFFh ; return maximum value
sub CL,7Fh+32 ; subtract bias + 32
neg CL ; get shift count
shr EAX,CL ; compute value
ret ; return
 
uflow:
retzero:sub EAX,EAX ; ensure entire number 0
ret ; return
endproc __FSAbs
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm
0,0 → 1,150
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
; from float to signed/unsigned int64
;
include mdef.inc
include struct.inc
 
modstart fsi8386
 
xref __U8LS
xref __U8RS
 
; Convert single precision float to unsigned 64-bit integer with truncation
; Input: [EAX] = 32-bit float
; Output: [EDX, EAX] = 64-bit integer
 
xdefp __FSU8
defp __FSU8
push ECX ; save ECX
mov CL,7fh+64 ; maximum number 2^64-1
call __FSU ; convert float to unsigned __int64
pop ECX ; restore ECX
ret ; return
endproc __FSU8
 
; Convert single precision float to signed 64-bit integer with truncation
; Input: [EAX] = 32-bit float
; Output: [EDX, EAX] = 64-bit integer
 
xdefp __FSI8
defp __FSI8
push ECX ; save ECX
mov CL,7fh+63 ; maximum number 2^63-1
call __FSI ; convert float to signed __int64
pop ECX ; restore ECX
ret ; return
endproc __FSI8
 
__FSI proc near
__FSU: ; what? they both do the same thing
or EAX,EAX ; check sign bit
jns short __FSAbs ; treat as unsigned if positive
call __FSAbs ; otherwise convert number
neg EDX ; negate the result
neg EAX ;
sbb EDX,0 ;
ret ; return
endproc __FSI
 
__FSAbs proc near
or EAX,EAX ; check if number 0
je short fltzero ; if so, just return 0
_shl EAX,1 ; shift mantissa over
rol EAX,8 ; get exponent to bottom
cmp AL,7fh ; quit if number < 1.0
jb short fltuflow ; ...
push EBX ; save EBX
mov CH,AL ; save exponent
stc ; set carry for implied bit
rcr EAX,1 ; put implied '1' bit in
shr EAX,8 ; remove exponent and extra bit
mov EDX,EAX ; put into 64-bit hi part
xor EAX,EAX ; zero 64-bit lo part
cmp CH,CL ; check if exponent exceeds maximum
jae short fltmax ; return maximum value if so
sub CH,7fh+55 ; calculate amount to shift (+ve -> left)
jae short fltm_left ; jump if left shift/no shift
xchg CH,CL ; get shift count
neg CL ; make positive
mov BX,CX
call __U8RS ; shift mantissa right
pop EBX ; restore EBX
ret ; return
 
fltm_left:
_if ne ; done if exponent exactly 55
mov BL,CH ; - get shift count
call __U8LS ; - shift mantissa left
_endif ; endif
pop EBX ; restore EBX
ret ; return
 
; CL = 7fh+64 for unsigned
; 7fh+63 for signed
fltmax:
mov EAX,0FFFFFFFFh ; return maximum value
mov EDX,EAX ;
sub CL,7fh+64 ; subtract bias + 64, results in 0 or -1
neg CL ; get shift count
mov BL,CL ; set shift count
call __U8RS ; shift mantissa right 1 bit for signed
pop EBX ; restore EBX
ret ; return
 
fltuflow:
sub EAX,EAX ; ensure entire number 0
fltzero:
sub EDX,EDX ;
ret ; return
endproc __FSAbs
 
; Convert single precision float to unsigned 64-bit integer with rounding
; Input: [EAX] = 32-bit float
 
; xdefp __RSU8
; defp __RSU8
; not implemented
; endproc __RSU8
 
; Convert single precision float to signed 64-bit integer with rounding
; Input: [EAX] = 32-bit float
 
; xdefp __RSI8
; defp __RSI8
; not implemented
; endproc __RSI8
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm
0,0 → 1,453
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: REAL*4 math library.
;*
;*****************************************************************************
 
 
;
; inputs: EAX - operand 1 (high word, low word resp. ) (op1)
; EDX - operand 2 (op2)
;
; operations are performed as op1 (*) op2 where (*) is the selected
; operation
;
; output: EAX - result
;
; F4Add, F4Sub - written 28-apr-84
; - modified by A.Kasapi 15-may-84
; - to: Calculate sign of result
; - Guard bit in addition for extra accuracy
; Add documentation
; F4Mul - written 16-may-84
; - by Athos Kasapi
; F4DIV - written may-84 by "
;
include mdef.inc
include struct.inc
 
.287
modstart fsmth386
 
xref __8087 ; indicate that NDP instructions are present
 
xref __fdiv_m32
 
datasegment
extrn __real87 : byte ; cstart
extrn __chipbug : byte
fsadd dd _chkadd
fsmul dd _chkmul
fsdiv dd _chkdiv
enddata
 
 
xref F4DivZero ; Fstatus
xref F4OverFlow ; Fstatus
xref F4UnderFlow ; Fstatus
 
xdefp __FSA ; add real*4 to real*4
xdefp __FSS ; subtract real*4 from real*4
xdefp __FSM ; 4-byte real multiply
xdefp __FSD ; 4-byte real divide
 
 
defpe __FSS
or EDX,EDX ; if op2 is 0
je short ret_op1 ; then return operand 1
xor EDX,80000000h ; flip the sign of op2 and add
 
defpe __FSA
or EDX,EDX ; if op2 is 0
je short ret_op1 ; then return operand 1
or EAX,EAX ; if op1 is 0
_if e ; then
mov EAX,EDX ; - return operand 2
ret_op1: ret ; - return
_endif ; endif
jmp fsadd
 
__FSA87:
push EBP ; save EBP
mov EBP,ESP ; get access to stack
push EAX ; push operand 1
fld dword ptr -4[EBP]; load operand 1
push EDX ; push operand 2
fadd dword ptr -8[EBP]; add operand 2 to operand 1
_ret87:
fstp dword ptr -4[EBP]; store result
add ESP,4 ; clean up stack
fwait ; wait
pop EAX ; load result into EAX
cmp EAX,80000000H ; is result -0.0
_if e ; if it is then
xor EAX,EAX ; - make it positive
_endif ; endif
pop EBP ; restore EBP
ret ; return
 
__FSAemu:
push ECX ; save ECX
push EBX ; save EBX
;<> Scheme for calculating sign of result:
;<> The sign word is built and kept in CL
;<> Bits 0 and 1 hold the sum of the sign bits
;<> shifted out of op_1 and op_2
;<> Bit 2 holds the sign of the larger operand. It is assumed to be
;<> op_1 until op_2 is found larger
 
sub ECX,ECX ; clear ECX
_shl EAX,1 ; get sign of op1
_rcl CL,1 ;
mov CH,CL ;
_shl CL,1 ;
_shl CL,1 ;
add CL,CH ;
rol EAX,8 ; get exponent of op1 into AL
_shl EDX,1 ; get sign of op2
adc CL,0 ; place in CL
rol EDX,8 ; get exponent of op2 in DL
mov BL,AL ; get exponent of op1
mov BH,DL ; get exponent of op2
 
mov AL,0 ; zero rest of fraction
stc ; put implied 1 bit into top bit of
rcr EAX,1 ; ... fraction
mov DL,0 ; zero rest of fraction
stc ; put implied 1 bit into top bit
rcr EDX,1 ; ... of fraction
 
mov CH,BL ; assume op1 > op2
sub BL,BH ; calculate difference in exponents
_if ne ; if different
_if b ; - if op1 < op2
mov CH,BH ; - - get larger exponent for result
neg BL ; - - negate the shift count
xchg EAX,EDX ; - - flip operands
xor CL,4
 
;<> op_2 is larger, so its sign now occupies bit 2 of sign word. This
;<> information is only correct if the signs of op-1 and op-2 are different.
;<> Since we look past bit 1 for sign only if the signs are different, bit2
;<> will supply the correct information when it is needed. We get the sign of
;<> op_2 by flipping the sign of op_1, already in bit 2
 
_endif ; - endif
xchg CL,BL ; - get shift count
cmp CL,32 ; - if count >= 32
_if ge ; - then
sub EDX,EDX ; - - answer is 0
_else ; - else
shr EDX,CL ; - - align fraction
_endif ; - endif
xchg CL,BL ; - put back
_endif ; endif
shr CL,1 ; get bit 0 of sign word - value is 0 if
; both operands have same sign, 1 if not
_if nc ; if signs are the same
add EAX,EDX ; - add the fractions
_if c ; - if carry
rcr EAX,1 ; - - shift fraction right 1 bit
inc CH ; - - increment exponent
_if z ; - - if we overflowed
ror CL,1 ; - - - set sign of infinity
rcr EAX,1 ; - - - . . .
jmp short add_oflow;- - - handle overflow
_endif ; - - endif
_endif ; - endif
_else ; else (signs are different)
shr CL,1 ; - skip junk bit
sub EAX,EDX ; - subtract the fractions
_guess ; - guess
_quif nc ; - - quit if no borrow
inc CL ; - - sign := sign of op_2
neg EAX ; - - negate the fraction
_admit ; - admit
or EAX,EAX ; - - quit if answer is not 0
_quif ne ; - - . . .
pop EBX ; - - restore EBX
pop ECX ; - - restore ECX
ret ; - - return (answer is 0)
_endguess ; - endguess
_endif ; endif
 
; normalize the fraction
add EAX,00000080h ; round up fraction if required
mov AL,0 ; zero bottom 8 bits 10-jul-89
_guess underflow ; guess
_quif nc ; - quit if round up didn't overflow frac
inc CH ; - adjust exponent
_admit ; admit
_loop ; - loop (shift until high bit appears)
_shl EAX,1 ; - - shift fraction left
_quif c,underflow ; - - quit if carry has appeared
dec CH ; - - decrement exponent
_until e ; - until underflow
jmp short add_uflow ; - handle underflow
_endguess ; endguess
mov AL,CH ; get exponent
ror EAX,8 ; rotate into position
ror CL,1 ; get sign bit
rcr EAX,1 ; shift it into result
pop EBX ; restore EBX
pop ECX ; restore ECX
ret ; return
 
add_uflow: ; handle underflow
pop EBX ; restore EBX
pop ECX ; restore ECX
jmp F4UnderFlow ; goto underflow routine
 
add_oflow: ; handle overflow
pop EBX ; restore EBX
pop ECX ; restore ECX
jmp F4OverFlow ; handle overflow
endproc __FSA
endproc __FSS
 
;=====================================================================
 
defpe __FSM
 
;<> multiplies X by Y and places result in C.
;<> X2 and X1 represent the high and low words of X. Similarly for Y and C
;<> Special care is taken to use only six registers, so the code is a bit
;<> obscure
 
_guess ; guess: answer not 0
or EAX,EAX ; - see if first arg is zero
_quif e ; - quit if op1 is 0
or EDX,EDX ; - quit if op2 is 0
_quif e ; - . . .
jmp fsmul ; - perform multiplication
_endguess ; endguess
sub EAX,EAX ; set answer to 0
ret ; return
 
__FSM87:
push EBP ; save EBP
mov EBP,ESP ; get access to stack
push EAX ; push operand 1
fld dword ptr -4[EBP]; load operand 1
push EDX ; push operand 2
fmul dword ptr -8[EBP]; mulitply operand 1 by operand 2
jmp _ret87 ; goto common epilogue
 
__FSMemu:
push ECX ; save ECX
_shl EAX,1 ; get sign of op1
_rcl ECX,1 ; save it
_shl EDX,1 ; get sign of op2
adc ECX,0 ; calc sign of result
ror ECX,1 ; move to the top
rol EAX,8 ; move exponent of op1 into AL
rol EDX,8 ; move exponent of op2 into DL
sub AL,7Fh ; remove bias from exponents
sub DL,7Fh ; . . .
add DL,AL ; add exponents
_if o ; if over or underflow
js short mul_oflow ; - report overflow if signed
jmp short mul_uflow ; - handle underflow
_endif ; endif
cmp DL,81h ; check for underflow
jle short mul_uflow ; quit if underflow
add DL,7fh+1 ; bias exponent
mov CL,DL ; save exponent
mov AL,0 ; zero rest of fraction
mov DL,0 ; ...
stc ; turn on implied 1 bit in fraction
rcr EAX,1 ; ...
stc ; turn on implied 1 bit in fraction
rcr EDX,1 ; ...
mul EDX ; calc fraction
or EDX,EDX ; check top bit
_if ns ; if not set
_shl EDX,1 ; - move left 1
dec CL ; - decrement exponent
_endif ; endif
sar EDX,8 ; place fraction in correct location
adc EDX,0 ; round up
adc CL,0 ; increment exponent if necessary
jz short mul_oflow ; report overflow if required
shl EDX,9 ; get rid of implied 1 bit
mov DL,CL ; get exponent
ror EDX,8 ; rotate into position except for sign
_shl ECX,1 ; get sign
rcr EDX,1 ; place sign in result
mov EAX,EDX ; place in correct register
pop ECX ; restore ECX
ret ; return
 
mul_uflow: ; underflow
pop ECX ; restore ECX
jmp F4UnderFlow ; . . .
 
mul_oflow: ; overflow
mov EAX,ECX ; get sign
pop ECX ; restore ECX
jmp F4OverFlow ; report overflow
endproc __FSM
 
;====================================================================
 
defpe __FSD
jmp fsdiv
 
__FSDbad_div:
push EBP ; save EBP
mov EBP,ESP ; get access to stack
push EAX ; push operand 1
fld dword ptr -4[EBP]; load operand 1
push EDX ; push operand 2
call __fdiv_m32 ; divide operand 1 by operand 2
push EDX ; __fdiv_m32 popped operand 2, _ret87 wants it
jmp _ret87 ; goto common epilogue
 
__FSD87:
push EBP ; save EBP
mov EBP,ESP ; get access to stack
push EAX ; push operand 1
fld dword ptr -4[EBP]; load operand 1
push EDX ; push operand 2
fdiv dword ptr -8[EBP]; divide operand 1 by operand 2
jmp _ret87 ; goto common epilogue
 
 
__FSDemu:
_shl EDX,1 ; shift sign of divisor into carry
_if e ; if divisor is zero
jmp F4DivZero ; - handle divide by zero
_endif ; endif
push ECX ; save ECX
_rcl ECX,1 ; save sign in ECX
_shl EAX,1 ; shift sign of dividend into carry
_if e ; if dividend is 0, then
pop ECX ; - restore ECX
ret ; - return
_endif ; endif
adc ECX,0 ; now calculate save sign of result in ECX
ror ECX,1 ; rotate sign to top
rol EAX,8 ; get exponent into AL
rol EDX,8 ; get exponent into DL
sub AL,7Fh ; calculate exponent of result
sub DL,7Fh ; . . .
sub AL,DL ; . . .
_if o ; if over or underflow
jns short div_uflow ; - handle underflow
_shl ECX,1 ; - get sign of infinity
rcr EAX,1 ; - . . .
jmp short div_oflow ; - handle overflow
_endif ; endif
cmp AL,81h ; check for underflow
jle short div_uflow ; . . .
add AL,7Fh ; restore bias to exponent
mov CH,AL ; save calculated exponent
mov AL,0 ; zero bottom of fraction
mov DL,0 ; ...
stc ; rotate implied '1'bit back into divisor
rcr EDX,1 ; . . .
stc ; rotate implied '1' bit into dividend
rcr EAX,1 ; . . .
push ECX ; save sign and exponent
mov ECX,EDX ; save divisor
mov EDX,EAX ; place dividend into EDX
sub EAX,EAX ; set rest to 0
shr EDX,1 ; so we don't get a divide overflow trap
div ECX ; do the divide
pop ECX ; restore sign and exponent
or EAX,EAX ; check top bit
_if ns ; if not set
_shl EAX,1 ; - move left 1
dec CH ; - decrement exponent
_endif ; endif
sar EAX,8 ; place fraction in correct location
adc EAX,0 ; round up
_guess ; guess have to inc exponent
_quif nc ; - quit if no carry
inc CH ; - increment exponent
_quif nz ; - quit if no overflow
mov EAX,ECX ; - get sign of infinity
jmp short div_oflow ; - handle overflow
_endguess ; endguess
shl EAX,9 ; get rid of implied 1 bit
mov AL,CH ; get exponent
ror EAX,8 ; rotate into position except for sign
_shl ECX,1 ; get sign
rcr EAX,1 ; place sign in result
pop ECX ; restore ECX
ret ; return to caller
 
div_uflow: ; handle underflow
pop ECX ; restore ECX
jmp F4UnderFlow ; handle underflow
 
 
div_oflow: ; handle overflow
pop ECX ; restore ECX
jmp F4OverFlow ; handle overflow
endproc __FSD
 
 
_chkadd: call _chk8087
jmp fsadd
 
_chkmul: call _chk8087
jmp fsmul
 
_chkdiv: call _chk8087
jmp fsdiv
 
 
_chk8087 proc near
push eax ; save AX
cmp byte ptr __real87,0 ; if real 80x87 NDP present
_if ne ; then
mov eax,offset __FSA87 ; - get addr of add rtn
mov fsadd,eax ; - ...
mov eax,offset __FSM87 ; - get addr of mul rtn
mov fsmul,eax ; - ...
test byte ptr __chipbug, 1 ; - if we've got a bad divider
_if ne ; - then
mov eax,offset __FSDbad_div ; - - get addr of div rtn
_else ; - else
mov eax,offset __FSD87 ; - - get addr of div rtn
_endif ; - endif
mov fsdiv,eax ; - ...
_else ; else
mov eax,offset __FSAemu ; - get addr of add rtn
mov fsadd,eax ; - ...
mov eax,offset __FSMemu ; - get addr of mul rtn
mov fsmul,eax ; - ...
mov eax,offset __FSDemu ; - get addr of div rtn
mov fsdiv,eax ; - ...
_endif ; endif
pop eax ; restore AX
ret ; return
endproc _chk8087
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm
0,0 → 1,56
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: FSN ==
;== Operation: Floating single negate ==
;== Inputs: EAX flaot value ==
;== Outputs: EAX new float value ==
;== Volatile: none ==
;========================================================================
include mdef.inc
include struct.inc
 
modstart fsn386
 
xdefp __FSN
 
defpe __FSN
or EAX,EAX ; if number not zero
_if ne ; then
xor EAX,80000000h ; - flip the sign bit
_endif ; endif
ret ; and return!!!
endproc __FSN
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm
0,0 → 1,136
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
; of AX:DX
;
include mdef.inc
include struct.inc
include fstatus.inc
 
modstart fstat386
 
xref "C",__set_ERANGE
xref __FPE_exception_
 
datasegment
enddata
assume ss:nothing
 
 
FPS_OK = 0
FPS_UNDERFLOW = 1
FPS_OVERFLOW = 2
FPS_DIVIDE_BY_0 = 3
FPS_BAD_ARG = 4
 
jmps macro dsym
jmp short dsym
endm
 
 
xdefp F8UnderFlow
xdefp F4UnderFlow
xdefp F8InvalidOp
xdefp F8DivZero
xdefp F4DivZero
xdefp F8OverFlow
xdefp F4OverFlow
xdefp F8RetInf_
xdefp _F8RetInf_
 
defpe F8UnderFlow
sub EDX,EDX ; . . .
 
defpe F4UnderFlow
;; mov EAX,FPE_UNDERFLOW; indicate underflow
;; call __FPE_exception_;
sub EAX,EAX ; return a zero
ret ; return
endproc F4UnderFlow
endproc F8UnderFlow
 
 
defpe F8InvalidOp
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
call __FPE_exception_;
jmps F8RetInf9 ; return infinity
endproc F8InvalidOp
 
defpe F8DivZero
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
call __FPE_exception_;
jmps F8RetInf9 ; return infinity
endproc F8DivZero
 
defpe F8OverFlow
;
; F8RetInf( sign : int ) : reallong
;
defpe F8RetInf_
defpe _F8RetInf_
push EAX ; save sign of result
call __set_ERANGE ; errno = ERANGE
mov EAX,FPE_OVERFLOW ; indicate overflow
call __FPE_exception_;
pop EAX ; restore sign of result
F8RetInf9: and EAX,80000000h ; get sign
or EAX,7FF00000h ; set infinity
mov EDX,EAX ;
sub EAX,EAX ; ...
ret ; return
endproc _F8RetInf_
endproc F8RetInf_
endproc F8OverFlow
 
 
defpe F4DivZero
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
call __FPE_exception_;
jmps F4RetInf9 ; return infinity
endproc F4DivZero
 
defpe F4OverFlow
defp F4RetInf ; return infinity
push EAX ; save sign of result
call __set_ERANGE ; errno = ERANGE
mov EAX,FPE_OVERFLOW ; indicate overflow
call __FPE_exception_;
pop EAX ; restore sign of result
F4RetInf9: and EAX,80000000h ; get sign
or EAX,7F800000h
ret
endproc F4RetInf
endproc F4OverFlow
 
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm
0,0 → 1,90
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;
include mdef.inc
include struct.inc
 
modstart i4fd386
 
xdefp __I4FD
xdefp __U4FD
 
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
;[]
;[] __I4FD convert signed 32-bit integer in EAX into double float
;[] __U4FD convert unsigned 32-bit integer in EAX into double float
;[] Input: EAX - 32-bit integer
;[] Output: EDX:EAX - double precision representation of integer
;[]
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
 
defpe __I4FD
or EAX,EAX ; if number is negative
_if s ; then
neg EAX ; - negate number
mov EDX,00000BFFh ; - set exponent
_else ; else
 
; convert unsigned 32-bit integer to double
 
defpe __U4FD
mov EDX,000003FFh ; - set exponent
_endif ; endif
or EAX,EAX ; if number is not zero
_if ne ; then
push ECX ; - save ECX
bsr ECX,EAX ; - find most significant non-zero bit
mov CH,CL ; - save shift count
mov CL,31 ; - calculate # of bits to shift by
sub CL,CH ; - ...
shl EAX,CL ; - shift bits into position
_shl EAX,1 ; - one more to get rid of implied 1 bit
mov CL,CH ; - get shift count
movzx ECX,CH ; - get shift count
add ECX,EDX ; - calculate exponent
mov EDX,EAX ; - get the bits
and EDX,0FFFFF000h ; - keep 20 bits
or EDX,ECX ; - get exponent in there
ror EDX,12 ; - rotate into position
shl EAX,20 ; - get last 12 bits into place
pop ECX ; - restore ECX
ret ; - return
_endif ; endif
sub EDX,EDX ; zero EDX
ret ; return
 
endproc __U4FD
endproc __I4FD
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm
0,0 → 1,82
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: I4FS, U4FS ==
;== Operation: Convert Integer types to single precision ==
;== Inputs: EAX, unsigned or signed integer ==
;== Outputs: EAX single precision floating point ==
;== Volatile: none ==
;== ==
;========================================================================
include mdef.inc
include struct.inc
 
modstart i4fs386
 
xdefp __I4FS
xdefp __U4FS
 
 
defpe __U4FS
or EAX,EAX ; if number is not zero
_if ne ; then
push ECX ; - save ECX
bsr ECX,EAX ; - find most significant non-zero bit
mov CH,CL ; - save shift count
neg CL ; - calculate # of bits to rotate by
add CL,23 ; - ...
and CL,1fh ; - just keep last 5 bits
rol EAX,CL ; - shift bits into position
and EAX,007FFFFFh ; - mask out sign and exponent bits
mov CL,CH ; - get shift count
add CL,7Fh ; - calculate exponent
and ECX,0FFh ; - isolate exponent
shl ECX,23 ; - shift exponent into position
or EAX,ECX ; - place into result
pop ECX ; - restore ECX
_endif ; endif
ret ; return
 
endproc __U4FS
 
defpe __I4FS
or EAX,EAX ; check sign
jns __U4FS ; if positive, just convert
neg EAX ; take absolute value of number
call __U4FS ; convert to FS
or EAX,80000000h ; set sign bit on
ret ; and return
endproc __I4FS
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm
0,0 → 1,224
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: I8D ==
;== Operation: Signed 8 byte divide ==
;== Inputs: EDX;EAX Dividend ==
;== ECX;EBX Divisor ==
;== Outputs: EDX;EAX Quotient ==
;== ECX;EBX Remainder (same sign as dividend) ==
;== Volatile: none ==
;== same sign as dividend for ==
;== consistency with 8086 idiv ==
;== and so (a/b)*b + a%b == a ==
;== to get a 64-bit version for 386==
;========================================================================
include mdef.inc
include struct.inc
 
modstart i8d
 
xdefp __I8D
 
defpe __I8D
or edx,edx ; check sign of dividend
js divneg ; handle case where dividend < 0
or ecx,ecx ; check sign of divisor
js notU8D ; easy case if it is also positive
 
; dividend >= 0, divisor >= 0
docall __U8D ; - ...
ret ; - ...
 
; dividend >= 0, divisor < 0
notU8D: neg ecx ; take positive value of divisor
neg ebx ; ...
sbb ecx,0 ; ...
docall __U8D ; do unsigned division
neg edx ; negate quotient
neg eax ; ...
sbb edx,0 ; ...
ret ; and return
 
divneg: ; dividend is negative
neg edx ; take absolute value of dividend
neg eax ; ...
sbb edx,0 ; ...
or ecx,ecx ; check sign of divisor
jns negres ; negative result if divisor > 0
 
; dividend < 0, divisor < 0
neg ecx ; negate divisor too
neg ebx ; ...
sbb ecx,0 ; ...
docall __U8D ; and do unsigned division
neg ecx ; negate remainder
neg ebx ; ...
sbb ecx,0 ; ...
ret ; and return
 
; dividend < 0, divisor >= 0
negres: docall __U8D ; do unsigned division
neg ecx ; negate remainder
neg ebx ; ...
sbb ecx,0 ; ...
neg edx ; negate quotient
neg eax ; ...
sbb edx,0 ; ...
ret ; and return
 
endproc __I8D
 
;========================================================================
;== Name: U8D ==
;== Operation: Unsigned 8 byte divide ==
;== Inputs: EDX;EAX Dividend ==
;== ECX;EBX Divisor ==
;== Outputs: EDX;EAX Quotient ==
;== ECX;EBX Remainder ==
;== Volatile: none ==
;========================================================================
 
xdefp __U8D
 
defpe __U8D
or ecx,ecx ; check for easy case
jne noteasy ; easy if divisor is 16 bit
dec ebx ; decrement divisor
_if ne ; if not dividing by 1
inc ebx ; - put divisor back
cmp ebx,edx ; - if quotient will be >= 64K
_if be ; - then
;
; 12-aug-88, added thanks to Eric Christensen from Fox Software
; divisor < 64K, dividend >= 64K, quotient will be >= 64K
;
; *note* this sequence is used in ltoa's #pragmas; any bug fixes
; should be reflected in ltoa's code bursts
;
mov ecx,eax ; - - save low word of dividend
mov eax,edx ; - - get high word of dividend
sub edx,edx ; - - zero high part
div ebx ; - - divide bx into high part of dividend
xchg eax,ecx ; - - swap high part of quot,low word of dvdnd
_endif ; - endif
div ebx ; - calculate low part
mov ebx,edx ; - get remainder
mov edx,ecx ; - get high part of quotient
sub ecx,ecx ; - zero high part of remainder
_endif ; endif
ret ; return
 
 
noteasy: ; have to work to do division
;
; check for divisor > dividend
;
_guess ; guess: divisor > dividend
cmp ecx,edx ; - quit if divisor <= dividend
_quif b ; - . . .
_if e ; - if high parts are the same
cmp ebx,eax ; - - compare the lower order words
_if be ; - - if divisor <= dividend
sub eax,ebx ; - - - calulate remainder
mov ebx,eax ; - - - ...
sub ecx,ecx ; - - - ...
sub edx,edx ; - - - quotient = 1
mov eax,1 ; - - - ...
ret ; - - - return
_endif ; - - endif
_endif ; - endif
sub ecx,ecx ; - set divisor = 0 (this will be quotient)
sub ebx,ebx ; - ...
xchg eax,ebx ; - return remainder = dividend
xchg edx,ecx ; - and quotient = 0
ret ; - return
_endguess ; endguess
push ebp ; save work registers
push esi ; ...
push edi ; ...
sub esi,esi ; zero quotient
mov edi,esi ; ...
mov ebp,esi ; and shift count
moveup: ; loop until divisor > dividend
_shl ebx,1 ; - divisor *= 2
_rcl ecx,1 ; - ...
jc backup ; - know its bigger if carry out
inc ebp ; - increment shift count
cmp ecx,edx ; - check if its bigger yet
jb moveup ; - no, keep going
ja divlup ; - if below, know we're done
cmp ebx,eax ; - check low parts (high parts equal)
jbe moveup ; until divisor > dividend
divlup: ; division loop
clc ; clear carry for rotate below
_loop ; loop
_loop ; - loop
_rcl esi,1 ; - - shift bit into quotient
_rcl edi,1 ; - - . . .
dec ebp ; - - quif( -- shift < 0 ) NB carry not changed
js donediv ; - - ...
backup: ; - - entry to remove last shift
rcr ecx,1 ; - - divisor /= 2 (NB also used by 'backup')
rcr ebx,1 ; - - ...
sub eax,ebx ; - - dividend -= divisor
sbb edx,ecx ; - - c=1 iff it won't go
cmc ; - - c=1 iff it will go
_until nc ; - until it won't go
_loop ; - loop
_shl esi,1 ; - - shift 0 into quotient
_rcl edi,1 ; - - . . .
dec ebp ; - - going to add, check if done
js toomuch ; - - if done, we subtracted to much
shr ecx,1 ; - - divisor /= 2
rcr ebx,1 ; - - ...
add eax,ebx ; - - dividend += divisor
adc edx,ecx ; - - c = 1 iff bit of quotient should be 1
_until c ; - until divisor will go into dividend
_endloop ; endloop
toomuch: ; we subtracted too much
add eax,ebx ; dividend += divisor
adc edx,ecx ; ...
donediv: ; now quotient in di;si, remainder in dx;ax
mov ebx,eax ; move remainder to cx;bx
mov ecx,edx ; ...
mov eax,esi ; move quotient to dx;ax
mov edx,edi ; ...
pop edi ; restore registers
pop esi ; ...
pop ebp ; ...
ret ; and return
endproc __U8D
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm
0,0 → 1,101
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
modstart i8fd386
 
xref __I8LS
xref __I8RS
 
; Convert signed 64-bit integer to double precision float
; Input: [EDX, EAX] = 64-bit integer
; Output: [EDX, EAX] = double
 
xdefp __I8FD
defp __I8FD
or EDX,EDX ; check sign
jns __U8FD ; if positive, just convert
neg EDX ;
neg EAX ; take absolute value of number
sbb EDX,0 ;
call __U8FD ; convert to FD
or EDX,80000000h ; set sign bit on
ret ; return
endproc __I8FD
 
; Convert unsigned 64-bit integer to double precision float
; Input: [EDX, EAX] = 64-bit integer
; Output: [EDX, EAX] = double
 
xdefp __U8FD
defp __U8FD
or EAX,EAX ; if lo is zero
_if e ;
or EDX,EDX ; and if hi is zero
_if e ;
ret ; - return
_endif
_endif ; endif
push ECX ; save ECX
push EBX ; save EBX
bsr ECX,EDX ; find most significant non-zero bit in hi
_if e ; if all zero bits
bsr ECX,EAX ; - find most significant non-zero bit in lo
_else ; else
add CL,32 ; - adjust shift count since hi was not 0
_endif ; endif
push ECX ; save shift count
neg CL ; calculate # of bits to shift by
add CL,63-11 ; ...
mov EBX,ECX ; set up for call
or CL,CL ; if mantissa should move left
_if ge ; then
call __I8LS ; - shift left
_else ; else
neg BL ; - make positive
call __I8RS ; - shift right
_endif ; endif
pop ECX ; restore shift count
and EDX,000FFFFFh ; mask out sign and exponent bits
add CX,1023 ; calculate exponent (excess 1023)
; and ECX,0FFFh ; isolate exponent (not required)
shl ECX,20 ; shift exponent into position
or EDX,ECX ; place into result
pop EBX ; restore EBX
pop ECX ; restore ECX
ret ; return
endproc __U8FD
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm
0,0 → 1,102
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
modstart i8fs386
 
xref __I8LS
xref __I8RS
 
; Convert signed 64-bit integer to single precision float
; Input: [EDX, EAX] = 64-bit integer
; Output: [EAX] = 32-bit float
 
xdefp __I8FS
defp __I8FS
or EDX,EDX ; check sign
jns __U8FS ; if positive, just convert
neg EDX ;
neg EAX ; take absolute value of number
sbb EDX,0 ;
call __U8FS ; convert to FS
or EAX,80000000h ; set sign bit on
ret ; return
endproc __I8FS
 
; Convert unsigned 64-bit integer to single precision float
; Input: [EDX, EAX] = 64-bit integer
; Output: [EAX] = 32-bit float
 
xdefp __U8FS
defp __U8FS
or EAX,EAX ; if lo is zero
_if e ;
or EDX,EDX ; and if hi is zero
_if e ;
ret ; - return
_endif
_endif ; endif
push ECX ; save ECX
push EBX ; save EBX
bsr ECX,EDX ; find most significant non-zero bit in hi
_if e ; if all zero bits
bsr ECX,EAX ; - find most significant non-zero bit in lo
_else ; else
add CL,32 ; - adjust shift count since hi was not 0
_endif ; endif
push ECX ; save shift count
neg CL ; calculate # of bits to shift by
add CL,63-8 ; ...
mov EBX,ECX ; set up for call
or CL,CL ; if mantissa should move left
_if ge ; then
call __I8LS ; - shift left
_else ; else
neg BL ; - make positive
call __I8RS ; - shift right
_endif ; endif
pop ECX ; restore shift count
and EDX,007FFFFFh ; mask out sign and exponent bits
add CL,127 ; calculate exponent (excess 127)
; and ECX,0FFh ; isolate exponent (not required)
shl ECX,23 ; shift exponent into position
or EDX,ECX ; place into result
mov EAX,EDX ; single precision is only 32 bits
pop EBX ; restore EBX
pop ECX ; restore ECX
ret ; return
endproc __U8FS
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i8m386.asm
0,0 → 1,75
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: I8M,U8M ==
;== Operation: integer eight byte multiply ==
;== Inputs: EDX;EAX integer M1 ==
;== ECX;EBX integer M2 ==
;== Outputs: EDX;EAX product ==
;== Volatile: ECX, EBX destroyed ==
;========================================================================
include mdef.inc
include struct.inc
 
modstart i8m
 
xdefp __I8M
xdefp __U8M
 
defpe __I8M
defpe __U8M
 
test edx,edx ; first check for easy (hiwords == 0) case
jnz L1
test ecx,ecx
jnz L1
mul ebx
ret
 
L1: push eax ; save M1.l
push edx ; save M1.h
mul ecx ; calc M1.l * M2.h -> eax
mov ecx,eax ; save M1.l * M2.h in ecx
pop eax ; get M1.h in eax
mul ebx ; calc M1.h * M2.l -> eax
add ecx,eax ; add above to previous total
pop eax ; get M1.l in eax
mul ebx ; calc M1.l * M2.l -> edx:eax
add edx,ecx ; add previous hiword contribs to hiword
ret ; and return!!!
 
endproc __U8M
endproc __I8M
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/i8rs386.asm
0,0 → 1,118
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
;========================================================================
;== Name: I8S ==
;== Operation: integer eight byte shift ==
;== Inputs: EDX;EAX integer M1 ==
;== ECX;EBX integer M2 (ECX contents ignored) ==
;== Outputs: EDX;EAX product ==
;== Volatile: ECX, EBX destroyed ==
;========================================================================
; Special Note:
; If ECX ever takes on a meaningful use (i.e., is no longer ignored)
; then several routines that call these shift routines will require fixing.
; At present, the following routines ignore what is in ECX.
 
 
modstart i8s
 
xdefp __U8RS
 
defpe __U8RS
 
mov ecx,ebx ; get shift-count into cl
and cl,03fH ; get mod 64 shift count
test cl,020H ; see if count >= 32
jnz L1
shrd eax,edx,cl
shr edx,cl
ret ; and return!!!
 
L1:
mov eax,edx
sub ecx,020H ; knock off 32-bits of shifting
xor edx,edx ; zero extend result
shr eax,cl
ret
 
endproc __U8RS
 
xdefp __I8RS
 
defpe __I8RS
 
mov ecx,ebx ; get shift-count into cl
and cl,03fH ; get mod 64 shift count
test cl,020H ; see if count >= 32
jnz L2
shrd eax,edx,cl
sar edx,cl
ret ; and return!!!
 
L2:
mov eax,edx ; shift hi into lo (1st 32 bits now shifted)
sub cl,020H ; knock off 32-bits of shifting
sar edx,31 ; sign extend hi-word
sar eax,cl ; shift remaining part
ret
 
endproc __I8RS
 
xdefp __I8LS
xdefp __U8LS
 
defpe __I8LS
defpe __U8LS
 
mov ecx,ebx ; get shift-count into cl
and cl,03fH ; get mod 64 shift count
test cl,020H ; see if count >= 32
jnz L3
shld edx,eax,cl
shl eax,cl
ret ; and return!!!
 
L3:
mov edx,eax ; shift lo into hi (1st 32 bits now shifted)
sub cl,020H ; knock off 32-bits of shifting
xor eax,eax ; lo 32 bits are now zero
shl edx,cl ; shift remaining part
ret ; and return!!!
 
endproc __U8LS
endproc __I8LS
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm
0,0 → 1,79
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: Signed 4-byte division for 386.
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: LDIV ==
;== Operation: Signed 4 byte divide ==
;== Inputs: EAX Dividend ==
;== EDX/ECX Divisor ==
;== SS:ESI pointer to result structure ==
;== Volatile: none ==
;========================================================================
 
include mdef.inc
include struct.inc
 
ifdef _PROFILE
include p5prof.inc
endif
modstart ldiv386
 
defpe div
xdefp "C",div
defpe ldiv
xdefp "C",ldiv
ifdef _PROFILE
P5Prolog
endif
ifdef __STACK__
mov EAX,4[ESP] ; get numerator
mov ECX,8[ESP] ; get divisor
; we don't need to save/restore ECX
else
push ECX ; save ECX
mov ECX,EDX ; get divisor
endif
cdq ; sign extend dividend
idiv ECX ; do the divide
mov [ESI],EAX ; store quotient
mov 4[ESI],EDX ; store remainder
ifndef __STACK__
pop ECX ; restore ECX
endif
ifdef _PROFILE
P5Epilog
endif
ret ; return
endproc ldiv
endproc div
 
endmod
end
/programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm
0,0 → 1,82
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: Signed 64-bit division for 386.
;*
;*****************************************************************************
 
 
;========================================================================
;== Name: LLDIV ==
;== Operation: Signed 8 byte divide ==
;== Inputs: EAX;EDX Dividend ==
;== ECX;EBX Divisor ==
;== SS:ESI pointer to result structure ==
;== Volatile: none ==
;========================================================================
 
include mdef.inc
include struct.inc
 
ifdef _PROFILE
include p5prof.inc
endif
modstart lldiv386
 
xref __I8D
 
; defpe imaxdiv
; xdefp "C",imaxdiv
defpe lldiv
xdefp "C",lldiv
ifdef _PROFILE
P5Prolog
endif
ifdef __STACK__
push EBX ; save EBX
mov EAX,08[ESP] ; get numerator
mov EDX,12[ESP]
mov EBX,16[ESP] ; get denominator
mov ECX,20[ESP]
endif
docall __I8D ; call long division routine
 
mov [ESI],EAX ; store quotient
mov 4[ESI],EDX
mov 8[ESI],EBX ; store remainder
mov 12[ESI],ECX
ifdef __STACK__
pop EBX ; restore EBX
endif
ifdef _PROFILE
P5Epilog
endif
ret ; return
endproc lldiv
; endproc imaxdiv
 
endmod
end
/programs/develop/open watcom/trunk/clib/heap/amblksiz.c
0,0 → 1,48
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Defines the minimum block size requested from the OS for
* the heap manager.
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include <limits.h>
 
#if defined(__NT__)
_WCRTLINKD unsigned _WCNEAR _amblksiz = 64*1024;
#elif defined(__WINDOWS_386__)
_WCRTLINKD unsigned _WCNEAR _amblksiz = 32*1024;
#elif defined(__WINDOWS__)
_WCRTLINKD unsigned _WCNEAR _amblksiz = 8*1024;
#elif INT_MAX < 65535
_WCRTLINKD unsigned _WCNEAR _amblksiz = 16;
#else
_WCRTLINKD unsigned _WCNEAR _amblksiz = 4*1024;
#endif
 
/programs/develop/open watcom/trunk/clib/heap/ambsptr.c
0,0 → 1,39
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include "rtdata.h"
 
_WCRTLINK unsigned *__get_amblksiz_ptr( void ) {
return &_amblksiz;
}
/programs/develop/open watcom/trunk/clib/heap/calloc.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
 
_WCRTLINK void *calloc( size_t n, size_t el_size )
{
void *mem;
unsigned long chk_size;
 
chk_size = (unsigned long) n * el_size;
el_size = chk_size;
#if defined(M_I86)
if( el_size != chk_size ) {
return( NULL );
}
#endif
mem = malloc( el_size );
if( mem == NULL ) {
return( NULL );
}
return( memset( mem, 0, el_size ) );
}
/programs/develop/open watcom/trunk/clib/heap/freect.c
0,0 → 1,68
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
/* return the number of times that _nmalloc can be called to allocate
and item "size" bytes from the near heap. */
 
_WCRTLINK unsigned int _freect( size_t size )
{
unsigned int count;
size_t memsize;
size_t size_of_chunk;
frlptr pnext;
mheapptr mhp;
 
count = 0;
size_of_chunk = (size + TAG_SIZE + ROUND_SIZE) & ~ROUND_SIZE;
if( size_of_chunk < size ) return( 0 );
if( size_of_chunk < FRL_SIZE ) {
size_of_chunk = FRL_SIZE;
}
_AccessNHeap();
for( mhp = __nheapbeg; mhp != NULL; mhp = mhp->next ) {
pnext = mhp->freehead.next;
while( pnext != (frlptr) &mhp->freehead ) {
memsize = pnext->len;
count += memsize / size_of_chunk;
pnext = pnext->next;
}
}
_ReleaseNHeap();
return( count );
}
/programs/develop/open watcom/trunk/clib/heap/grownear.c
0,0 → 1,560
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Heap growing routines - allocate near heap memory from OS.
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include "heapacc.h"
#include "heap.h"
#include <errno.h>
#if defined(__DOS_EXT__)
// #include "extender.h"
// #include "tinyio.h"
#endif
#if defined(__CALL21__)
// #include "tinyio.h"
#endif
#if defined(__WINDOWS_286__) || defined(__NT__)
void* _stdcall UserAlloc(int size);
 
// #include "windows.h"
#endif
#if defined(__OS2__)
// #include <wos2.h>
#endif
#if defined(__WINDOWS_386__)
// extern void * pascal DPMIAlloc(unsigned long);
#endif
 
static frlptr __LinkUpNewMHeap( mheapptr );
 
#if defined(__DOS_EXT__)
 
extern int SegmentLimit();
#pragma aux SegmentLimit = \
"xor eax,eax" \
"mov ax,ds" \
"lsl eax,ax" \
"inc eax" \
value [eax] \
modify exact [eax];
 
static void __unlink( mheapptr miniheapptr )
{
mheapptr prev_link;
mheapptr next_link;
 
if( __nheapbeg == miniheapptr ) {
__nheapbeg = miniheapptr->next;
}
if( miniheapptr == __MiniHeapRover ) {
__MiniHeapRover = miniheapptr->prev;
if( __MiniHeapRover == NULL ) {
__MiniHeapRover = __nheapbeg;
__LargestSizeB4MiniHeapRover = 0;
}
}
if( miniheapptr == __MiniHeapFreeRover ) {
__MiniHeapFreeRover = 0;
}
prev_link = miniheapptr->prev;
next_link = miniheapptr->next;
if( prev_link != NULL ) prev_link->next = next_link;
if( next_link != NULL ) next_link->prev = prev_link;
}
 
void __FreeDPMIBlocks()
{
mheapptr mhp;
struct dpmi_hdr *dpmi;
 
mhp = __nheapbeg;
while( mhp != NULL ) {
// see if the last free entry has the full size of
// the DPMI block ( - overhead). If it is then we can give this
// DPMI block back to the DPMI host.
if( (mhp->freehead.prev)->len + sizeof(struct miniheapblkp) ==
mhp->len ) {
mheapptr pnext;
 
dpmi = ((struct dpmi_hdr *)mhp) - 1;
pnext = mhp->next;
__unlink( mhp );
mhp = pnext;
if( dpmi->dos_seg_value == 0 ) { // if DPMI block
TinyDPMIFree( dpmi->dpmi_handle );
} else { // else DOS block below 1MB
TinyFreeBlock( dpmi->dos_seg_value );
}
} else {
mhp = mhp->next;
}
}
}
 
void *__ReAllocDPMIBlock( frlptr p1, unsigned req_size )
{
mheapptr mhp;
struct dpmi_hdr *dpmi;
struct dpmi_hdr *prev_dpmi;
unsigned size;
frlptr flp, flp2;
 
if( !__heap_enabled ) return( 0 );
__FreeDPMIBlocks();
prev_dpmi = NULL;
for( mhp = __nheapbeg; mhp; mhp = mhp->next ) {
if( ((PTR)mhp + sizeof(struct miniheapblkp) == (PTR)p1)
&& (mhp->numalloc == 1) ) {
// The mini-heap contains only this memblk
__unlink( mhp );
dpmi = ((struct dpmi_hdr *)mhp) - 1;
if( dpmi->dos_seg_value != 0 ) return( NULL );
size = mhp->len + sizeof(struct dpmi_hdr) + TAG_SIZE;
size += ( req_size - (p1->len-TAG_SIZE) );
size += 0x0fff;
size &= ~0x0fff;
prev_dpmi = dpmi;
dpmi = TinyDPMIRealloc( dpmi, size );
if( dpmi == NULL ) {
dpmi = prev_dpmi;
return( NULL ); // indicate resize failed
}
dpmi->dos_seg_value = 0;
mhp = (mheapptr)( dpmi + 1 );
mhp->len = size - sizeof(struct dpmi_hdr) - TAG_SIZE;
flp = __LinkUpNewMHeap( mhp );
mhp->numalloc = 1;
 
// round up to even number
req_size = (req_size + 1) & ~1;
size = flp->len - req_size;
if( size >= FRL_SIZE ) { // Enough to spare a free block
flp->len = req_size | 1;// adjust size and set allocated bit
// Make up a free block at the end
flp2 = (frlptr)((PTR)flp + req_size);
flp2->len = size | 1;
++mhp->numalloc;
mhp->largest_blk = 0;
_nfree( (PTR)flp2 + TAG_SIZE );
} else {
flp->len |= 1; // set allocated bit
}
return( flp );
}
}
return( NULL );
}
#endif
 
static frlptr __LinkUpNewMHeap( mheapptr p1 ) // originally __AddNewHeap()
{
mheapptr p2;
mheapptr p2_prev;
tag *last_tag;
unsigned amount;
 
/* insert into ordered heap list (14-jun-91 AFS) */
/* logic wasn't inserting heaps in proper ascending order */
/* (09-nov-93 Fred) */
p2_prev = NULL;
for( p2 = __nheapbeg; p2 != NULL; p2 = p2->next ) {
if( p1 < p2 ) break;
p2_prev = p2;
}
/* ascending order should be: p2_prev < p1 < p2 */
/* except for special cases when p2_prev and/or p2 are NULL */
p1->prev = p2_prev;
p1->next = p2;
if( p2_prev != NULL ) {
p2_prev->next = p1;
} else { /* add p1 to beginning of heap */
__nheapbeg = p1;
}
if( p2 != NULL ) {
/* insert before 'p2' (list is non-empty) */
p2->prev = p1;
}
amount = p1->len - sizeof( struct miniheapblkp );
/* Fill out the new miniheap descriptor */
p1->freehead.len = 0;
p1->freehead.prev = &p1->freehead;
p1->freehead.next = &p1->freehead;
p1->rover = &p1->freehead;
p1->b4rover = 0;
p1->numalloc = 0;
p1->numfree = 0;
p1++;
((frlptr)p1)->len = amount;
/* fix up end of heap links */
last_tag = (tag *) ( (PTR)p1 + amount );
*last_tag = END_TAG;
return( (frlptr) p1 );
}
 
#if ! ( defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) \
)
size_t __LastFree( void ) /* used by nheapgrow to know about adjustment */
{
frlptr p1;
unsigned brk_value;
 
if( __nheapbeg == NULL ) { /* no heap? can't have free blocks */
return( 0 );
}
p1 = __nheapbeg->freehead.prev; /* point to last free block */
brk_value = (unsigned)((PTR)p1 + p1->len + TAG_SIZE );
#if defined(__DOS_EXT__)
if( _IsPharLap() && !__X32VM) _curbrk = SegmentLimit(); /*19-feb-94*/
#endif
if( brk_value == _curbrk ) { /* if last free block is at the end */
return( p1->len );
}
return( 0 );
}
#endif
 
#if ! defined(__CALL21__)
#if defined(__DOS_EXT__)
static void *RationalAlloc( size_t size )
{
struct dpmi_hdr *dpmi;
mheapptr mhp;
tiny_ret_t save_DOS_block;
tiny_ret_t DOS_block;
 
__FreeDPMIBlocks();
/* size is a multiple of 4k */
dpmi = TinyDPMIAlloc( size );
if( dpmi != NULL ) {
mhp = (mheapptr)( dpmi + 1 );
mhp->len = size - sizeof( struct dpmi_hdr );
dpmi->dos_seg_value = 0; // indicate DPMI block
return( (void *)mhp );
}
if( __minreal & 0xfff00000 ) {
/* checks for users that want >1M real memory saved */
__minreal = 0xfffff;
}
if( size > 0x00010000 ) {
/* cannot allocate more than 64k from DOS real memory */
return( NULL );
}
save_DOS_block = TinyAllocBlock(( __minreal >> 4 ) | 1 );
if( TINY_OK( save_DOS_block ) ) {
DOS_block = TinyAllocBlock( size >> 4 );
TinyFreeBlock( save_DOS_block );
if( TINY_OK( DOS_block ) ) {
dpmi = (struct dpmi_hdr *) TinyDPMIBase( DOS_block );
dpmi->dos_seg_value = DOS_block;
mhp = (mheapptr)( dpmi + 1 );
mhp->len = size - sizeof( struct dpmi_hdr );
return( (void *)mhp );
}
}
return( NULL );
}
#endif
#endif
 
static int __AdjustAmount( unsigned *amount )
{
unsigned old_amount = *amount;
unsigned amt;
#if ! ( defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) \
)
unsigned last_free_amt;
#endif
 
amt = old_amount;
amt = ( amt + TAG_SIZE + ROUND_SIZE) & ~ROUND_SIZE;
if( amt < old_amount ) {
return( 0 );
}
#if ! ( defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) \
)
#if defined(__DOS_EXT__)
if( _IsRationalZeroBase() || _IsCodeBuilder() ) {
// Allocating extra to identify the dpmi block
amt += sizeof(struct dpmi_hdr);
} else {
#else
{
#endif
last_free_amt = __LastFree(); /* adjust for last free block */
if( last_free_amt >= amt ) {
amt = 0;
} else {
amt -= last_free_amt;
}
}
#endif
/* amount is even here */
/*
extra amounts (22-feb-91 AFS)
 
(1) adding a new heap needs:
frl free block req'd for _nmalloc request
(frl is the MINIMUM because the block
may be freed)
tag end of miniheap descriptor
struct miniheapblkp start of miniheap descriptor
(2) extending heap needs:
tag free block req'd for _nmalloc request
*/
*amount = amt;
amt += ( (TAG_SIZE) + sizeof(frl) + sizeof(struct miniheapblkp) );
if( amt < *amount ) return( 0 );
if( amt < _amblksiz ) {
/*
_amblksiz may not be even so round down to an even number
nb. pathological case: where _amblksiz == 0xffff, we don't
want the usual round up to even
*/
amt = _amblksiz & ~1u;
}
#if defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) || \
defined(__CALL21__) || \
defined(__DOS_EXT__)
/* make sure amount is a multiple of 4k */
*amount = amt;
amt += 0x0fff;
if( amt < *amount ) return( 0 );
amt &= ~0x0fff;
#endif
*amount = amt;
return( *amount != 0 );
}
 
#if defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) || \
defined(__CALL21__) || \
defined(__DOS_EXT__)
static int __CreateNewNHeap( unsigned amount )
{
mheapptr p1;
frlptr flp;
unsigned brk_value;
 
if( !__heap_enabled ) return( 0 );
if( _curbrk == ~1u ) return( 0 );
if( __AdjustAmount( &amount ) == 0 ) return( 0 );
#if defined(__WINDOWS_286__)
brk_value = (unsigned) LocalAlloc( LMEM_FIXED, amount );
if( brk_value == 0 ) {
return( 0 );
}
#elif defined(__WINDOWS_386__)
brk_value = (unsigned) DPMIAlloc( amount );
if( brk_value == 0 ) {
return( 0 );
}
#elif defined(__WARP__)
{
PBYTE p;
 
if( DosAllocMem( &p, amount, PAG_COMMIT|PAG_READ|PAG_WRITE ) ) {
return( 0 );
}
brk_value = (unsigned)p;
}
#elif defined(__NT__)
// brk_value = (unsigned) VirtualAlloc( NULL, amount, MEM_COMMIT,
// PAGE_EXECUTE_READWRITE );
brk_value = (unsigned) UserAlloc (amount );
//brk_value = (unsigned) LocalAlloc( LMEM_FIXED, amount );
if( brk_value == 0 ) {
return( 0 );
}
#elif defined(__CALL21__)
{
tag _WCNEAR *tmp_tag;
 
tmp_tag = (tag _WCNEAR *)TinyMemAlloc( amount );
if( tmp_tag == NULL ) {
return( 0 );
}
/* make sure it will not look like the end of a heap */
tmp_tag[0] = ! END_TAG;
brk_value = (unsigned) &tmp_tag[2];
amount -= 2 * TAG_SIZE; // 11-jun-95, subtract extra tag
}
#elif defined(__DOS_EXT__)
// if( _IsRationalZeroBase() || _IsCodeBuilder() ) {
{
tag *tmp_tag;
 
if( _IsRational() ) {
tmp_tag = RationalAlloc( amount );
if( tmp_tag ) amount = *tmp_tag;
} else { /* CodeBuilder */
tmp_tag = TinyCBAlloc( amount );
amount -= TAG_SIZE;
}
if( tmp_tag == NULL ) {
return( 0 );
}
brk_value = (unsigned) tmp_tag;
}
// Pharlap, RSI/non-zero can never call this function
#endif
if( amount - TAG_SIZE > amount ) {
return( 0 );
} else {
amount -= TAG_SIZE;
}
if( amount < sizeof( struct miniheapblkp ) + sizeof( frl ) ) {
/* there isn't enough for a heap block (struct miniheapblkp) and
one free block (frl) */
return( 0 );
}
/* we've got a new heap block */
p1 = (mheapptr) brk_value;
p1->len = amount;
// Now link it up
flp = __LinkUpNewMHeap( p1 );
amount = flp->len;
/* build a block for _nfree() */
flp->len = amount | 1;
++p1->numalloc; /* 28-dec-90 */
p1->largest_blk = 0;
_nfree( (PTR)flp + TAG_SIZE );
return( 1 );
}
#endif
 
int __ExpandDGROUP( unsigned amount )
{
#if defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__WARP__) || \
defined(__NT__) || \
defined(__CALL21__)
// first try to free any available storage
_nheapshrink();
return( __CreateNewNHeap( amount ) );
#else
mheapptr p1;
frlptr flp;
unsigned brk_value;
tag *last_tag;
unsigned new_brk_value;
void _WCNEAR *brk_ret;
 
#if defined(__DOS_EXT__)
if( ( _IsRationalZeroBase() || _IsCodeBuilder() ) ) {
return( __CreateNewNHeap( amount ) ); // Won't slice either
}
// Rational non-zero based system should go through.
#endif
if( !__heap_enabled ) return( 0 );
if( _curbrk == ~1u ) return( 0 );
if( __AdjustAmount( &amount ) == 0 ) return( 0 );
#if defined(__DOS_EXT__)
if( _IsPharLap() && !__X32VM ) { /* 19-feb-94 */
_curbrk = SegmentLimit();
}
#endif
new_brk_value = amount + _curbrk;
if( new_brk_value < _curbrk ) {
new_brk_value = ~1u;
}
brk_ret = __brk( new_brk_value );
if( brk_ret == (void _WCNEAR *) -1 ) {
return( 0 );
}
brk_value = (unsigned) brk_ret;
if( brk_value > /*0xfff8*/ ~7u ) {
return( 0 );
}
if( new_brk_value <= brk_value ) {
return( 0 );
}
amount = new_brk_value - brk_value;
if( amount - TAG_SIZE > amount ) {
return( 0 );
} else {
amount -= TAG_SIZE;
}
for( p1 = __nheapbeg; p1 != NULL; p1 = p1->next ) {
if( p1->next == NULL ) break;
if( (unsigned)p1 <= brk_value &&
((unsigned)p1)+p1->len+TAG_SIZE >= brk_value ) break;
}
if( (p1 != NULL) &&
((brk_value - TAG_SIZE) == (unsigned)( (PTR)p1 + p1->len) ) ) {
/* we are extending the previous heap block (slicing) */
/* nb. account for the end-of-heap tag */
brk_value -= TAG_SIZE;
amount += TAG_SIZE;
flp = (frlptr) brk_value;
/* adjust current entry in heap list */
p1->len += amount;
/* fix up end of heap links */
last_tag = (tag *) ( (PTR)flp + amount );
last_tag[0] = END_TAG;
} else {
if( amount < sizeof( struct miniheapblkp ) + sizeof( frl ) ) {
/* there isn't enough for a heap block (struct miniheapblkp) and
one free block (frl) */
return( 0 );
}
// Initializing the near heap if __nheapbeg == NULL,
// otherwise, a new mini-heap is getting linked up
p1 = (mheapptr) brk_value;
p1->len = amount;
flp = __LinkUpNewMHeap( p1 );
amount = flp->len;
}
/* build a block for _nfree() */
flp->len = amount | 1;
++p1->numalloc; /* 28-dec-90 */
p1->largest_blk = ~0; /* set to largest value to be safe */
_nfree( (PTR)flp + TAG_SIZE );
return( 1 );
#endif
}
/programs/develop/open watcom/trunk/clib/heap/heap.h
0,0 → 1,207
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Heap library configuration for various platforms.
*
****************************************************************************/
 
 
#include "variety.h"
 
#if defined(_M_IX86)
#include <i86.h>
#endif
 
#if !defined(__DOS_EXT__)
#if defined(__386__) && \
!defined(__WINDOWS_386__) && \
!defined(__WINDOWS__) && \
!defined(__OS2__) && \
!defined(__NT__) && \
!defined(__OSI__) && \
!defined(__UNIX__)
#define __DOS_EXT__
#endif
#endif
 
typedef unsigned int tag;
typedef struct freelistp frl;
typedef struct freelistp _WCNEAR *frlptr;
typedef struct freelist _WCFAR *farfrlptr;
typedef unsigned char _WCNEAR *PTR;
typedef unsigned char _WCFAR *FARPTR;
typedef struct miniheapblkp _WCNEAR *mheapptr;
 
/*
** NOTE: the size of these data structures is critical to the alignemnt
** of the pointers returned by malloc().
*/
struct freelist {
tag len; /* length of block in free list */
unsigned int prev; /* offset of previous block in free list */
unsigned int next; /* offset of next block in free list */
};
struct heapblk {
tag heaplen; /* size of heap (0 = 64K) */
unsigned int prevseg; /* segment selector for previous heap */
unsigned int nextseg; /* segment selector for next heap */
unsigned int rover; /* roving pointer into free list */
unsigned int b4rover; /* largest block before rover */
unsigned int largest_blk; /* largest block in the heap */
unsigned int numalloc; /* number of allocated blocks in heap */
unsigned int numfree; /* number of free blocks in the heap */
struct freelist freehead; /* listhead of free blocks in heap */
};
 
struct freelistp {
tag len;
frlptr prev;
frlptr next;
};
struct heapblkp {
tag heaplen;
unsigned int prevseg;
unsigned int nextseg;
frlptr rover;
unsigned int b4rover;
unsigned int largest_blk;
unsigned int numalloc;
unsigned int numfree;
frl freehead;
};
 
struct miniheapblkp {
tag len;
mheapptr prev;
mheapptr next;
frlptr rover;
unsigned int b4rover;
unsigned int largest_blk;
unsigned int numalloc;
unsigned int numfree;
frl freehead;
};
 
struct heapstart {
struct heapblk h;
struct freelist first;
};
 
struct heapend {
tag last_tag;
struct freelist last;
};
 
#ifdef __DOS_EXT__
struct dpmi_hdr {
unsigned long dpmi_handle;
tag dos_seg_value; // 0 => DPMI block, else DOS segment
};
#endif
 
extern unsigned _curbrk;
extern mheapptr _WCNEAR __nheapbeg;
#if defined(_M_IX86)
extern __segment __fheap;
extern __segment __bheap;
extern __segment __fheapRover;
#endif
extern int __heap_enabled;
extern unsigned int __LargestSizeB4Rover;
extern struct miniheapblkp _WCNEAR *__MiniHeapRover;
extern unsigned int __LargestSizeB4MiniHeapRover;
extern struct miniheapblkp _WCNEAR *__MiniHeapFreeRover;
 
extern size_t __LastFree( void );
extern int __NHeapWalk( struct _heapinfo *entry, mheapptr heapbeg );
extern int __ExpandDGROUP( unsigned int __amt );
#if defined(_M_IX86)
extern unsigned __AllocSeg( unsigned int __amt );
extern unsigned __GrowSeg( __segment __seg, unsigned int __amt );
extern int __FreeSeg( __segment seg );
extern int __HeapWalk( struct _heapinfo *entry, __segment seg, unsigned all );
extern int __HeapMin( __segment seg, unsigned one_seg );
extern int __HeapSet( __segment seg, unsigned fill );
#endif
 
#if defined(__DOS_EXT__)
extern void __FreeDPMIBlocks( void );
extern void *__ReAllocDPMIBlock( frlptr p1, unsigned req_size );
extern void *__ExpandDPMIBlock( frlptr, unsigned );
#endif
 
extern int __HeapManager_expand( __segment seg, unsigned offset,
size_t req_size, size_t *growth_size );
 
extern void _WCFAR __HeapInit( void _WCNEAR *start, unsigned int amount );
 
_WCRTLINK extern void _WCNEAR *__brk( unsigned );
 
#if defined(_M_IX86)
#define _DGroup() FP_SEG((&__nheapbeg))
#else
#define _DGroup() 0
#endif
// __IsCtsNHeap() is used to determine whether the operating system provides
// a continuous near heap block. __ExpandDGroup should slice for more near
// heap under those operating systems with __IsCtsNHeap() == 1.
#if defined(__WARP__) || \
defined(__NT__) || \
defined(__WINDOWS_386__) || \
defined(__WINDOWS_286__)
#define __IsCtsNHeap() 0
#elif defined(__DOS_EXT__)
#define __IsCtsNHeap() ((_IsRationalZeroBase() || _IsCodeBuilder()) ? 0 : 1)
#else
#define __IsCtsNHeap() 1
#endif
 
extern unsigned __MemAllocator( unsigned __sz, unsigned __seg, unsigned __off );
extern void __MemFree( unsigned __ptr, unsigned __seg, unsigned __off );
#if defined(_M_IX86)
#if defined(__386__)
#pragma aux __MemAllocator "*" parm [eax] [edx] [ebx];
#pragma aux __MemFree "*" parm [eax] [edx] [ebx];
#else
#pragma aux __MemAllocator "*" parm [ax] [dx] [bx];
#pragma aux __MemFree "*" parm [ax] [dx] [bx];
#endif
#endif
 
#define PARAS_IN_64K (0x1000)
#define END_TAG (~0)
 
#define TAG_SIZE (sizeof(tag))
#if defined(M_I86)
#define ROUND_SIZE (TAG_SIZE-1)
#else
#define ROUND_SIZE (TAG_SIZE+TAG_SIZE-1)
#endif
#define FRL_SIZE ((sizeof(frl)+ROUND_SIZE)&~ROUND_SIZE)
 
#define __HM_SUCCESS 0
#define __HM_FAIL 1
#define __HM_TRYGROW 2
/programs/develop/open watcom/trunk/clib/heap/heapacc.h
0,0 → 1,59
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#ifndef _HEAPACC_H_INCLUDED
#define _HEAPACC_H_INCLUDED
/* macros for serialization of accesses to the heap */
#if defined(__SW_BM)
#if defined(__386__) || defined(__AXP__) || defined(__PPC__)
extern void (*_AccessFHeap)();
extern void (*_ReleaseFHeap)();
extern void (*_AccessNHeap)();
extern void (*_ReleaseNHeap)();
#else
extern void __AccessFHeap();
extern void __ReleaseFHeap();
extern void __AccessNHeap();
extern void __ReleaseNHeap();
#define _AccessFHeap() __AccessFHeap()
#define _ReleaseFHeap() __ReleaseFHeap()
#define _AccessNHeap() __AccessNHeap()
#define _ReleaseNHeap() __ReleaseNHeap()
#endif
#else
#define _AccessFHeap()
#define _ReleaseFHeap()
#define _AccessNHeap()
#define _ReleaseNHeap()
#endif
#endif
 
/programs/develop/open watcom/trunk/clib/heap/heapen.c
0,0 → 1,53
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
 
int __heap_enabled = 1;
 
_WCRTLINK int _heapenable( int new )
{
int old;
 
_AccessNHeap();
old = __heap_enabled;
__heap_enabled = new;
_ReleaseNHeap();
return( old );
}
/programs/develop/open watcom/trunk/clib/heap/heapgrow.c
0,0 → 1,126
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Routines to grow heap (allocate memory from OS).
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#if defined(__QNX__)
#elif defined(__LINUX__)
#elif defined(__OS2__)
#elif defined(_M_IX86)
// #include "tinyio.h"
#endif
#include "heap.h"
#include "heapacc.h"
 
#if defined(M_I86)
 
_WCRTLINK void _fheapgrow( void )
{
/* multiple heaps are used so growing the far heaps is not necessary */
}
 
#endif
 
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK void _heapgrow( void )
{
_nheapgrow();
}
 
#else
 
_WCRTLINK void _heapgrow( void )
{
_fheapgrow();
}
 
#endif
 
 
_WCRTLINK void _nheapgrow( void )
{
#if defined(__WINDOWS_286__) || defined(__386__) || defined(__AXP__) || defined(__PPC__) || defined(__MIPS__)
_nfree( _nmalloc( 1 ) ); /* get something into the heap */
#else
unsigned max_paras;
unsigned curr_paras;
unsigned diff_paras;
unsigned expand;
 
_AccessNHeap();
/* calculate # pages which always has extra slack space (ie. 0x10) */
curr_paras = (( _curbrk + 0x10 ) & ~0x0f ) >> 4;
if( curr_paras == 0 ) {
/* we're already at 64k */
_ReleaseNHeap();
return;
}
#if defined(__QNX__)
if( qnx_segment_realloc( _DGroup(), 65536L ) == -1 ) {
_ReleaseNHeap();
return;
}
max_paras = PARAS_IN_64K;
#elif defined(__OS2__)
if( DosReallocSeg( 0, _DGroup() ) ) {
_ReleaseNHeap();
return;
}
max_paras = PARAS_IN_64K;
#else
if( _osmode != DOS_MODE ) { /* 23-apr-91 */
max_paras = PARAS_IN_64K;
} else {
max_paras = TinyMaxSet( _psp );
/* subtract off code size */
max_paras -= _DGroup() - _psp;
if( max_paras > PARAS_IN_64K ) {
max_paras = PARAS_IN_64K;
}
}
#endif
if( max_paras <= curr_paras ) {
/* '<' -> something is wrong, '==' -> can't change size */
_ReleaseNHeap();
return;
}
diff_paras = max_paras - curr_paras;
expand = (( diff_paras + 1 ) << 4 ) - ( _curbrk & 0x0f );
expand += __LastFree(); /* compensate for _expand's adjustment */
_ReleaseNHeap();
_nfree( _nmalloc( expand - ( sizeof( size_t ) + sizeof(frl) ) ) );
#endif
}
/programs/develop/open watcom/trunk/clib/heap/mem.c
0,0 → 1,343
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Heart of the heap manager. Do not break
* unless you have a death wish.
*
****************************************************************************/
 
 
#include "variety.h"
#include <limits.h>
#include <malloc.h>
#include "heap.h"
 
 
#if defined(M_I86)
extern unsigned setup_ds( unsigned );
#pragma aux setup_ds = \
"push ax" \
"mov ax,ds" \
"pop ds" \
parm [ax] value [ax];
#define setup_segment( _x ) _x = setup_ds( _x );
#else
#define setup_segment( _x ) (void)(_x = _x);
#endif
 
//
// input:
// size - #bytes to allocate
// segment - 16bit Intel data selector containing heap
// offset - address of heap control block
// if 16bit Intel -> offset within segment
// else -> absolute pointer value
//
// output:
// result - address of allocated storage or zero on failure
// if 16bit Intel -> offset within segment
// else -> absolute pointer value
//
unsigned __MemAllocator( unsigned size, unsigned segment, unsigned offset )
{
frlptr result;
result = 0; // assume the worst
 
setup_segment( segment ); // setup DS for 16bit Intel
 
if( size != 0 ) { // quit if size is zero
unsigned new_size;
new_size = size + TAG_SIZE + ROUND_SIZE;// round up size
if( new_size >= size ) { // quit if overflowed
struct heapblkp _WCI86NEAR *heap;
unsigned largest;
heap = (struct heapblkp _WCI86NEAR *)offset;
size = new_size & ~ROUND_SIZE; // make size even
largest = heap->largest_blk;
if( size < FRL_SIZE ) {
size = FRL_SIZE;
}
if( size <= largest ) { // quit if size too big
frlptr pcur;
unsigned len;
pcur = heap->rover; // start at rover
largest = heap->b4rover;
if( size <= largest ) { // check size with rover
pcur = heap->freehead.next; // start at beginning
largest = 0; // reset largest block size
}
for(;;) { // search free list
len = pcur->len;
if( size <= len ) { // found one
break;
}
if( len > largest ) { // update largest block size
largest = len;
}
pcur = pcur->next; // advance to next entry
if( pcur == // if back at start
(frlptr)&(heap->freehead)) {
heap->largest_blk = largest; // update largest
setup_segment( segment ); // 16bit Intel restore
return( (unsigned)result ); // return 0
}
}
heap->b4rover = largest; // update rover size
heap->numalloc++; // udpate allocation count
len -= size; // compute leftover size
if( len >= FRL_SIZE ) { // if leftover big enough
// split into two chunks
frlptr pprev; // before current
frlptr pnext; // after current
frlptr pnew; // start of new piece
pnew = (frlptr)((PTR)pcur + size);
heap->rover = pnew; // update rover
pnew->len = len; // set new size
pcur->len = size; // reset current size
pprev = pcur->prev; // update next/prev links
pnew->prev = pprev;
pnext = pcur->next;
pnew->next = pnext;
pprev->next = pnew;
pnext->prev = pnew;
} else { // just use this chunk
frlptr pprev; // before current
frlptr pnext; // after current
heap->numfree--; // 1 fewer entries in free list
pprev = pcur->prev;
heap->rover = pprev; // update rover
pnext = pcur->next; // update next/prev links
pprev->next = pnext;
pnext->prev = pprev;
}
pcur->len |= 1; // mark as allocated
// get pointer to user area
result = (frlptr)((PTR)pcur + TAG_SIZE);
}
}
}
setup_segment( segment ); // 16bit Intel restore
return( (unsigned)result );
}
 
//
// input:
// pointer - address of block to free
// if 16bit Intel -> offset within segment
// else -> absolute pointer value
// segment - 16bit Intel data selector containing heap
// offset - address of heap control block
// if 16bit Intel -> offset within segment
// else -> absolute pointer value
//
// output:
// none
//
void __MemFree( unsigned pointer, unsigned segment, unsigned offset )
{
setup_segment( segment ); // setup DS for 16bit Intel
 
if( pointer != 0 ) { // quit if pointer is zero
frlptr pfree;
pfree = (frlptr)(pointer - TAG_SIZE);
if( pfree->len & 1 ) { // quit if storage is free
struct heapblkp _WCI86NEAR *heap;
frlptr pnext;
frlptr pprev;
frlptr ptr;
unsigned len;
heap = (struct heapblkp _WCI86NEAR *)offset;
do { // this allows break statement
unsigned average;
unsigned numfree;
 
// look at next block to try and coalesce
len = pfree->len & ~1; // get next block
pnext = (frlptr)((PTR)pfree + len);
if( (pnext->len & 1) == 0 ) { // if it is free
len += pnext->len; // include the length
pfree->len = len; // update pfree length
if( pnext == heap->rover ) { // check for rover
heap->rover = pfree; // update rover
}
pprev = pnext->prev; // fixup next/prev links
pnext = pnext->next;
pprev->next = pnext;
pnext->prev = pprev;
heap->numfree--; // reduce numfree
break; // proceed to coalesce code
}
 
// following block is not free
// we must now try to figure out where pfree
// is in relation to the entries in the free list
pfree->len = len; // remove allocated marker
 
// check a few special places
// see if pfree is:
// - just before or just after the rover
// - at the very beginning or very end of the heap
pnext = heap->rover; // get rover
if( pfree < pnext ) { // where is pfree?
// pfree is before rover
if( pfree > pnext->prev ) { // where is pfree?
// pfree is next to rover
break; // proceed to coalesce code
}
pnext = heap->freehead.next; // get start of free list
if( pfree < pnext ) { // where is pfree?
// pfree is at start of list
break; // proceed to coalesce code
}
} else { // pfree is after rover
pnext = pnext->next; // pnext is after rover
if( pfree < pnext ) { // where is pfree?
// pfree is just after rover
break; // proceed to coalesce code
}
// get end of free list
pnext = (frlptr)&(heap->freehead);
pprev = pnext->prev;
if( pfree > pprev ) { // where is pfree?
// pfree is at end of list
break; // proceed to coalesce code
}
}
 
// Calculate the average number of allocated blocks we may
// have to skip until we expect to find a free block. If
// this number is less than the total number of free blocks,
// chances are that we can find the correct position in the
// free list by scanning ahead for a free block and linking
// this free block before the found free block. We protect
// ourself against the degenerate case where there is an
// extremely long string of allocated blocks by limiting the
// number of blocks we will search to twice the calculated
// average.
 
numfree = heap->numfree;
average = heap->numalloc / (numfree+1);
if( average < numfree ) {
 
// There are lots of allocated blocks and lots of free
// blocks. On average we should find a free block
// quickly by following the allocated blocks, but the
// worst case can be very bad. So, we try scanning the
// allocated blocks and give up once we have looked at
// twice the average.
 
unsigned worst;
worst = heap->numalloc - numfree;
average *= 2; // give up after this many
if( worst <= numfree ) {
average = UINT_MAX; // we won't give up loop
}
// point at next allocated
pnext = (frlptr)((PTR)pfree + pfree->len);
for(;;) {
len = pnext->len;
if( len & 1 ) { // pnext is allocated
if( len != END_TAG ) { // check for end TAG
len &= ~1; // advance pnext
pnext = (frlptr)((PTR)pnext + len);
average--;
if( !average ) { // give up search
break;
}
} else {
break; // stop at end tag
}
} else {
// break twice!
goto found_it; // we have the spot
}
}
}
 
// when all else fails, search the free list
pnext = heap->rover; // begin at rover
if( pfree < pnext ) { // is pfree before rover?
// then begin at start
pnext = heap->freehead.next;
}
for(;;) {
if( pfree < pnext ) { // if pfree before pnext
break; // we found it
}
pnext = pnext->next; // advance pnext
 
if( pfree < pnext ) { // if pfree before pnext
break; // we found it
}
pnext = pnext->next; // advance pnext
 
if( pfree < pnext ) { // if pfree before pnext
break; // we found it
}
pnext = pnext->next; // advance pnext
}
} while( 0 ); // only do once
 
found_it:
// if we are here, then we found the spot
pprev = pnext->prev; // setup pprev
 
// pprev, pfree, pnext are all setup
len = pfree->len;
 
// check pprev and pfree
ptr = (frlptr)((PTR)pprev + pprev->len);
if( ptr == pfree ) { // are they adjacent?
// coalesce pprev and pfree
len += pprev->len; // udpate len
pprev->len = len;
if( heap->rover == pfree ) { // check rover impact
heap->rover = pprev; // update rover
}
pfree = pprev; // now work with coalesced blk
} else {
heap->numfree++; // one more free entry
pfree->next = pnext; // update next/prev entries
pfree->prev = pprev;
pprev->next = pfree;
pnext->prev = pfree;
}
heap->numalloc--; // one fewer allocated
 
if( pfree < heap->rover ) { // check rover impact
if( len > heap->b4rover ) { // is len bigger than b4rover
heap->b4rover = len; // then update b4rover
}
}
 
if( len > heap->largest_blk ) { // check largest block
heap->largest_blk = len;
}
}
}
 
setup_segment( segment ); // 16bit Intel restore
}
/programs/develop/open watcom/trunk/clib/heap/memavl.c
0,0 → 1,61
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
 
/* Return the amount of memory available in the near heap. */
/* Best done at start of program and after _nheapgrow() has been called. */
 
_WCRTLINK size_t _memavl( void )
{
size_t length;
frlptr pnext;
mheapptr mhp;
 
length = 0;
_AccessNHeap();
for( mhp = __nheapbeg; mhp != NULL; mhp = mhp->next ) {
pnext = mhp->freehead.next;
while( pnext != (frlptr) &mhp->freehead ) {
length += ( (pnext->len - TAG_SIZE) & ~ROUND_SIZE );
pnext = pnext->next;
}
}
_ReleaseNHeap();
return( length );
}
/programs/develop/open watcom/trunk/clib/heap/memmax.c
0,0 → 1,58
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
_WCRTLINK size_t _memmax( void ) /* return size of largest free piece from near heap */
{
size_t maxlen, size;
frlptr pnext;
mheapptr mhp;
 
maxlen = 0;
_AccessNHeap();
for( mhp = __nheapbeg; mhp != NULL; mhp = mhp->next ) {
pnext = mhp->freehead.next;
while( pnext != (frlptr) &mhp->freehead ) {
size = ((pnext->len - TAG_SIZE) & ~ROUND_SIZE);
if( size > maxlen ) maxlen = size;
pnext = pnext->next;
}
}
_ReleaseNHeap();
return( maxlen );
}
/programs/develop/open watcom/trunk/clib/heap/ncalloc.c
0,0 → 1,56
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <malloc.h>
#include <string.h>
#include "heap.h"
 
_WCRTLINK void _WCNEAR *_ncalloc( size_t n, size_t el_size )
{
void _WCI86NEAR *p;
unsigned long chk_size;
 
chk_size = (unsigned long) n * el_size;
el_size = chk_size;
#if defined(M_I86)
if( el_size != chk_size ) {
return( (void _WCNEAR *)NULL );
}
#endif
p = _nmalloc( el_size );
if( p != (void _WCNEAR *)NULL ) {
memset( p, 0, el_size );
}
return( p );
}
/programs/develop/open watcom/trunk/clib/heap/nexpand.c
0,0 → 1,205
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Near heap expansion routines.
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
#if defined(__DOS_EXT__)
#include "extender.h"
#endif
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK void *_expand( void *stg, size_t amount )
{
return( _nexpand( stg, amount ) );
}
 
#endif
 
#if defined(__AXP__) || defined(__PPC__)
#define _SEGMENT int
#else
#define _SEGMENT __segment
#endif
 
int __HeapManager_expand( _SEGMENT seg,
unsigned offset,
size_t req_size,
size_t *growth_size )
{
#if defined(M_I86)
typedef struct freelistp __based(seg) *fptr;
typedef char __based(void) *cptr;
 
struct miniheapblkp __based(seg) *hblk;
#else
typedef struct freelistp _WCNEAR *fptr;
typedef char _WCNEAR *cptr;
 
mheapptr hblk;
#endif
fptr p1;
fptr p2;
fptr pnext;
fptr pprev;
size_t new_size;
size_t old_size;
size_t free_size;
 
/* round (new_size + tag) to multiple of pointer size */
new_size = (req_size + TAG_SIZE + ROUND_SIZE) & ~ROUND_SIZE;
if( new_size < req_size ) new_size = ~0; //go for max
if( new_size < FRL_SIZE ) {
new_size = FRL_SIZE;
}
p1 = (fptr) ((cptr)offset - TAG_SIZE);
old_size = p1->len & ~1;
if( new_size > old_size ) {
/* enlarging the current allocation */
p2 = (fptr) ((cptr)p1 + old_size);
*growth_size = new_size - old_size;
for(;;) {
free_size = p2->len;
if( p2->len == END_TAG ) {
return( __HM_TRYGROW );
} else if( free_size & 1 ) { /* next piece is allocated */
break;
} else {
pnext = p2->next;
pprev = p2->prev;
 
if( seg == _DGroup() ) { // near heap
for( hblk = __nheapbeg; hblk->next; hblk = hblk->next ) {
if( (fptr)hblk <= (fptr)offset &&
(fptr)((PTR)hblk+hblk->len) > (fptr)offset ) break;
}
}
#if defined(M_I86)
else { // Based heap
hblk = 0;
}
#endif
 
if( hblk->rover == p2 ) { /* 09-feb-91 */
hblk->rover = p2->prev;
}
if( free_size < *growth_size ||
free_size - *growth_size < FRL_SIZE ) {
/* unlink small free block */
pprev->next = pnext;
pnext->prev = pprev;
p1->len += free_size;
hblk->numfree--;
if( free_size >= *growth_size ) {
return( __HM_SUCCESS );
}
*growth_size -= free_size;
p2 = (fptr) ((cptr)p2 + free_size);
} else {
p2 = (fptr) ((cptr)p2 + *growth_size);
p2->len = free_size - *growth_size;
p2->prev = pprev;
p2->next = pnext;
pprev->next = p2;
pnext->prev = p2;
p1->len += *growth_size;
return( __HM_SUCCESS );
}
}
}
/* no suitable free blocks behind, have to move block */
return( __HM_FAIL );
} else {
/* shrinking the current allocation */
if( old_size - new_size >= FRL_SIZE ) {
/* block big enough to split */
p1->len = new_size | 1;
p1 = (fptr) ((cptr)p1 + new_size);
p1->len = (old_size - new_size) | 1;
if( seg == _DGroup() ) { // near heap
for( hblk = __nheapbeg; hblk->next; hblk = hblk->next ) {
if( (fptr)hblk <= (fptr)offset &&
(fptr)((PTR)hblk+hblk->len) > (fptr)offset ) break;
}
}
#if defined(M_I86)
else // Based heap
hblk = 0;
#endif
/* _bfree will decrement 'numalloc' 08-jul-91 */
hblk->numalloc++;
#if defined(M_I86)
_bfree( seg, (cptr)p1 + TAG_SIZE );
/* free the top portion */
#else
_nfree( (cptr)p1 + TAG_SIZE );
#endif
}
}
return( __HM_SUCCESS );
}
 
 
_WCRTLINK void _WCNEAR *_nexpand( void _WCNEAR *stg, size_t req_size )
{
struct {
unsigned expanded : 1;
} flags;
int retval;
size_t growth_size;
 
flags.expanded = 0;
_AccessNHeap();
for( ;; ) {
retval = __HeapManager_expand( _DGroup(),
(unsigned) stg,
req_size,
&growth_size );
if( retval == __HM_SUCCESS ) {
_ReleaseNHeap();
return( stg );
}
if( retval == __HM_FAIL || !__IsCtsNHeap() ) break;
if( retval == __HM_TRYGROW ) {
if( flags.expanded ) break;
if( __ExpandDGROUP( growth_size ) == 0 ) {
break;
}
flags.expanded = 1;
}
}
_ReleaseNHeap();
return( NULL );
}
/programs/develop/open watcom/trunk/clib/heap/nfree.c
0,0 → 1,123
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of near free() and _nfree().
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK void free( void *stg )
{
_nfree( stg );
}
 
#endif
 
struct miniheapblkp _WCNEAR *__MiniHeapFreeRover;
 
_WCRTLINK void _nfree( void _WCNEAR *stg )
{
mheapptr p1,p2;
 
if( !stg )
return;
 
_AccessNHeap();
do {
// first try some likely locations
p1 = __MiniHeapFreeRover;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
p2 = p1;
p1 = p1->prev;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
}
p1 = p2->next;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
}
}
p1 = __MiniHeapRover;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
p2 = p1;
p1 = p1->prev;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
}
p1 = p2->next;
if( p1 ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
break;
}
}
}
 
// not found near rover, so search the list
for( p1 = __nheapbeg; p1; p1 = p1->next ) {
if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
// break twice!
goto found_it;
}
}
 
// this pointer is not in the heap
_ReleaseNHeap();
return;
} while( 0 );
 
found_it:
// we found the miniheap, free the storage
__MemFree( (unsigned)stg, _DGroup(), (unsigned) p1 );
__MiniHeapFreeRover = p1;
if( p1 < __MiniHeapRover ) {
if( p1->largest_blk > __LargestSizeB4MiniHeapRover ) {
__LargestSizeB4MiniHeapRover = p1->largest_blk;
}
}
_ReleaseNHeap();
}
/programs/develop/open watcom/trunk/clib/heap/nheapchk.c
0,0 → 1,162
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of near _heapchk() and _nheapchk().
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
frlptr __nheapchk_current;
 
static int checkFreeList( size_t *free_size )
{
frlptr p;
frlptr end;
size_t new_size;
size_t free_list_size = 0;
mheapptr mhp;
 
for( mhp = __nheapbeg; mhp != NULL; mhp = mhp ->next ) {
/* check that the free list is a doubly linked ring */
__nheapchk_current = p = mhp->freehead.next;
/* make sure we start off on the right track */
if( (p->prev == NULL) ||
(p->prev < &(mhp->freehead)) ||
(((PTR)p->prev) > (((PTR)mhp)+mhp->len)) ) {
return( _HEAPBADNODE );
}
if( p->prev->next != p ) {
return( _HEAPBADNODE );
}
end = p;
do {
/* loop invariant: p->prev->next == p */
/* are we still in a ring if we move to p->next? */
/* nb. this check is sufficient to ensure that we will
never cycle */
if( (p->next == NULL) ||
(p->next < &(mhp->freehead)) ||
(((PTR)p->next) > (((PTR)mhp)+mhp->len)) ) {
return( _HEAPBADNODE );
}
if( p->next->prev != p ) {
return( _HEAPBADNODE );
}
/* is entry allocated? */
if( p->len & 1 ) {
return( _HEAPBADNODE );
}
new_size = free_list_size + p->len;
if( new_size < free_list_size ) {
/* this is a case where we do not know where memory
is corrupted */
return( _HEAPBADNODE );
}
free_list_size = new_size;
__nheapchk_current = p = p->next;
} while( p != end );
}
*free_size = free_list_size;
return( _HEAPOK );
}
 
static int checkFree( frlptr p )
{
frlptr next;
frlptr prev;
frlptr next_next;
frlptr prev_prev;
 
__nheapchk_current = p;
if( p->len & 1 ) {
return( _HEAPBADNODE );
}
next = p->next;
prev = p->prev;
if( next->prev != p || prev->next != p ) {
return( _HEAPBADNODE );
}
next_next = next->next;
prev_prev = prev->prev;
if( next_next->prev != next || prev_prev->next != prev ) {
return( _HEAPBADNODE );
}
if( next_next->prev != next || prev_prev->next != prev ) {
return( _HEAPBADNODE );
}
return( _HEAPOK );
}
 
#if defined(__SMALL_DATA__)
_WCRTLINK int _heapchk( void )
{
return( _nheapchk() );
}
#endif
 
_WCRTLINK int _nheapchk( void )
{
struct _heapinfo hi;
int heap_status;
size_t free_size;
 
_AccessNHeap();
heap_status = checkFreeList( &free_size );
if( heap_status != _HEAPOK ) {
_ReleaseNHeap();
return( heap_status );
}
hi._pentry = NULL;
for(;;) {
heap_status = __NHeapWalk( &hi, __nheapbeg );
if( heap_status != _HEAPOK )
break;
if( hi._useflag == _FREEENTRY ) {
heap_status = checkFree( (frlptr) hi._pentry );
if( heap_status != _HEAPOK )
break;
free_size -= hi._size;
}
}
if( free_size != 0 ) {
heap_status = _HEAPBADNODE;
} else if( heap_status == _HEAPBADPTR ) {
heap_status = _HEAPBADNODE;
} else {
if( heap_status == _HEAPEND ) {
heap_status = _HEAPOK;
}
}
_ReleaseNHeap();
return( heap_status );
}
/programs/develop/open watcom/trunk/clib/heap/nheapmin.c
0,0 → 1,256
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of near _heapmin() and _nheapmin().
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
#if defined(__DOS_EXT__)
// #include "extender.h"
#endif
#if defined(__WINDOWS_286__) || defined(__NT__)
int _stdcall UserFree(void* p);
// #include "windows.h"
#endif
#if defined(__OS2__)
// #include <wos2.h>
#endif
#if defined(__WINDOWS_386__)
// extern int __pascal DPMIFree(unsigned long); // windows extender function
#endif
#if defined(__CALL21__)
// #include "tinyio.h"
#endif
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK int _heapshrink( void )
{
return( _nheapshrink() );
}
 
_WCRTLINK int _heapmin( void )
{
return( _nheapshrink() );
}
 
#endif
 
_WCRTLINK int _nheapmin( void )
{
return( _nheapshrink() );
}
 
#if defined(__WARP__) || \
defined(__WINDOWS_286__) || \
defined(__WINDOWS_386__) || \
defined(__NT__) || \
defined(__CALL21__)
static int __ReturnMemToSystem( mheapptr mhp )
{
mheapptr pnext;
 
pnext = mhp->next;
#if defined(__WARP__)
if( DosFreeMem( (PBYTE)mhp ) ) return( -1 );
#elif defined(__NT__)
//if( LocalFree( (HLOCAL)mhp ) != NULL ) return( -1 );
// if (!VirtualFree(mhp, 0, MEM_RELEASE))
// return -1;
if(!UserFree(mhp))
return -1;
#elif defined(__WINDOWS_386__)
if( DPMIFree( (unsigned long)mhp ) != 0 ) return( -1 );
#elif defined(__WINDOWS_286__)
if( LocalFree( (HLOCAL)mhp ) != NULL ) return( -1 );
#elif defined(__CALL21__)
// No way to free storage under OSI
if( mhp ) return( -1 );
#endif
if( __MiniHeapRover == mhp ) { // Update rovers
if( pnext ) {
__MiniHeapRover = pnext;
} else {
__MiniHeapRover = __nheapbeg;
__LargestSizeB4MiniHeapRover = 0;
}
}
if( __MiniHeapFreeRover == mhp ) {
__MiniHeapFreeRover = 0;
}
return( 0 ); // success
}
 
static void __ReleaseMiniHeap( mheapptr mhp )
{
mheapptr pprev;
mheapptr pnext;
 
pprev = mhp->prev;
pnext = mhp->next;
if( __ReturnMemToSystem( mhp ) == 0 ) {
if( pprev == NULL ) {
__nheapbeg = pnext;
} else {
pprev->next = pnext;
}
if( pnext != NULL ) pnext->prev = pprev;
} //else: do not unlink if the memory cannot be freed successfully
}
 
#endif
 
_WCRTLINK int _nheapshrink( void )
{
mheapptr mhp;
#if !defined(__WARP__) && \
!defined(__WINDOWS_286__) && \
!defined(__WINDOWS_386__) && \
!defined(__NT__) && \
!defined(__CALL21__)
// Shrink by adjusting _curbrk
 
frlptr last_free;
frlptr end_tag;
unsigned new_brk;
 
_AccessNHeap();
#if defined(__DOS_EXT__)
if( !_IsRationalZeroBase() && !_IsCodeBuilder() ) {
#endif
if( __nheapbeg == NULL ) {
_ReleaseNHeap();
return( 0 ); // No near heap, can't shrink
}
/* Goto the end of miniheaplist (if there's more than 1 blk) */
for( mhp = __nheapbeg; mhp->next; mhp = mhp->next );
/* check that last free block is at end of heap */
last_free = mhp->freehead.prev;
end_tag = (frlptr) ( (PTR)last_free + last_free->len );
if( end_tag->len != END_TAG ) {
_ReleaseNHeap();
return( 0 );
}
if( end_tag != (frlptr) ((PTR)mhp + mhp->len ) ) {
_ReleaseNHeap();
return( 0 );
}
#if defined(__DOS_EXT__)
// only shrink if we can shave off at least 4k
if( last_free->len < 0x1000 ) {
_ReleaseNHeap();
return( 0 );
}
#else
if( last_free->len <= sizeof( frl ) ) {
_ReleaseNHeap();
return( 0 );
}
#endif
/* make sure there hasn't been an external change in _curbrk */
if( sbrk( 0 ) != &(end_tag->prev) ) {
_ReleaseNHeap();
return( 0 );
}
/* calculate adjustment factor */
if( mhp->len-last_free->len > sizeof( struct miniheapblkp ) ) {
// this miniheapblk is still being used
#if defined(__DOS_EXT__)
frlptr new_last_free;
new_last_free = (frlptr)((((unsigned)last_free + 0xfff) & ~0xfff) - TAG_SIZE);
if( new_last_free == last_free ) {
#endif
// remove entire entry
mhp->len -= last_free->len;
--mhp->numfree;
// Relink the freelist entries, and update the rover
mhp->freehead.prev = last_free->prev;
last_free->prev->next = &mhp->freehead;
if( mhp->rover == last_free ) mhp->rover = last_free->prev;
#if defined(__DOS_EXT__)
} else {
// just shrink the last free entry
mhp->len -= last_free->len;
last_free->len = (PTR)new_last_free - (PTR)last_free;
mhp->len += last_free->len;
last_free = new_last_free;
}
#endif
last_free->len = END_TAG;
new_brk = (unsigned) ((PTR)last_free + TAG_SIZE );
} else {
// we can remove this miniheapblk
if( mhp->prev ) { // Not the first miniheapblk
mhp->prev->next = NULL;
new_brk = (unsigned)mhp;//->prev + (unsigned)mhp->prev->len;
} else { // Is the first miniheapblk
new_brk = (unsigned)__nheapbeg;
__nheapbeg = NULL;
}
// Update rover info
if( __MiniHeapRover == mhp ) {
__MiniHeapRover = __nheapbeg;
__LargestSizeB4MiniHeapRover = 0;
}
}
 
if( __brk( new_brk ) == (void _WCNEAR *) -1 ) {
_ReleaseNHeap();
return( -1 );
}
_ReleaseNHeap();
return( 0 );
#if defined(__DOS_EXT__)
}
__FreeDPMIBlocks(); // For RSI/zero-base and Intel CB
_ReleaseNHeap();
return( 0 );
#endif
#else
// Shrink by releasing mini-heaps
{
mheapptr pnext;
 
_AccessNHeap();
for( mhp = __nheapbeg; mhp; mhp = pnext ) {
pnext = mhp->next;
if( mhp->len - sizeof(struct miniheapblkp) ==
(mhp->freehead.prev)->len ) __ReleaseMiniHeap( mhp );
}
_ReleaseNHeap();
return( 0 );
}
#endif
}
/programs/develop/open watcom/trunk/clib/heap/nheapset.c
0,0 → 1,79
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Near heap set routines.
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include <string.h>
#include "heap.h"
#include "heapacc.h"
 
 
#if defined(__SMALL_DATA__)
_WCRTLINK int _heapset( unsigned int fill )
{
return( _nheapset( fill ) );
}
#endif
 
#if defined(_M_IX86)
#pragma intrinsic(_fmemset)
#endif
 
_WCRTLINK int _nheapset( unsigned int fill )
{
mheapptr mhp;
frlptr curr;
int test_heap;
 
test_heap = _heapchk();
if( test_heap != _HEAPOK ) {
return( test_heap );
}
fill |= fill << 8;
_AccessNHeap();
 
for( mhp = __nheapbeg; mhp != NULL; mhp = mhp->next ) {
curr = mhp->freehead.next;
for( ;; ) {
if( curr == (frlptr) &mhp->freehead ) break;
#if defined(_M_IX86)
_fmemset( (void _WCFAR *)(curr + 1), fill, curr->len - sizeof(frl) );
#else
memset( (void *)(curr + 1), fill, curr->len - sizeof(frl) );
#endif
curr = curr->next;
}
}
_ReleaseNHeap();
return( _HEAPOK );
}
/programs/develop/open watcom/trunk/clib/heap/nheapwal.c
0,0 → 1,103
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include "heap.h"
#include "heapacc.h"
 
#if defined(__SMALL_DATA__)
_WCRTLINK int _heapwalk( struct _heapinfo *entry )
{
return( _nheapwalk( entry ) );
}
#endif
 
int __NHeapWalk( struct _heapinfo *entry, mheapptr heapbeg )
{
frlptr p;
frlptr q;
 
if( heapbeg == NULL ) {
return( _HEAPEMPTY );
}
p = (frlptr)(entry->_pentry);
if( p == NULL ) {
p = (frlptr)(heapbeg + 1);
} else { /* advance to next entry */
for( heapbeg = __nheapbeg;; heapbeg = heapbeg->next ) {
if( heapbeg->next == NULL ) break;
if( (PTR)heapbeg <= (PTR)p &&
(PTR)heapbeg+heapbeg->len > (PTR)p ) break;
}
q = (frlptr)((PTR)p + (p->len & ~1));
if( q <= p ) {
return( _HEAPBADNODE );
}
p = q;
}
for( ;; ) {
if( p->len == END_TAG ) {
if( heapbeg->next == NULL ) {
entry->_useflag = _USEDENTRY;
entry->_size = 0;
entry->_pentry = NULL;
return( _HEAPEND );
} else { // We advance to next miniheapblk
heapbeg = heapbeg->next;
p = (frlptr)(heapbeg + 1);
}
} else {
break;
}
}
entry->_pentry = p;
entry->_useflag = _FREEENTRY;
entry->_size = p->len & ~1;
if( p->len & 1 ) {
entry->_useflag = _USEDENTRY;
}
return( _HEAPOK );
}
 
_WCRTLINK int _nheapwalk( struct _heapinfo *entry )
{
int heap_status;
 
_AccessNHeap();
heap_status = __NHeapWalk( entry, __nheapbeg );
_ReleaseNHeap();
return( heap_status );
}
 
/programs/develop/open watcom/trunk/clib/heap/nmalloc.c
0,0 → 1,124
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of near malloc() and _nmalloc().
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include "extfunc.h"
#include "heapacc.h"
#include "heap.h"
 
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) __nmemneed;
#endif
 
mheapptr _WCNEAR __nheapbeg = NULL;
 
struct miniheapblkp _WCNEAR *__MiniHeapRover = NULL;
unsigned int __LargestSizeB4MiniHeapRover = 0;
 
 
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK void *malloc( size_t amount )
{
return( _nmalloc( amount ) );
}
 
#endif
 
 
_WCRTLINK void _WCNEAR *_nmalloc( size_t amt )
{
unsigned largest;
unsigned size;
unsigned ptr;
unsigned char expanded;
mheapptr miniheap_ptr;
 
if( (amt == 0) || (amt > -sizeof(struct heapblk)) ) {
return( (void _WCNEAR *)NULL );
}
 
// Try to determine which miniheap to begin allocating from.
// first, round up the amount
size = (amt + TAG_SIZE + ROUND_SIZE) & ~ROUND_SIZE;
if( size < FRL_SIZE ) {
size = FRL_SIZE;
}
 
_AccessNHeap();
ptr = NULL;
expanded = 0;
for(;;) {
if( size > __LargestSizeB4MiniHeapRover ) {
miniheap_ptr = __MiniHeapRover;
if( miniheap_ptr == NULL ) {
__LargestSizeB4MiniHeapRover = 0;
miniheap_ptr = __nheapbeg;
}
} else {
__LargestSizeB4MiniHeapRover = 0; // force value to be updated
miniheap_ptr = __nheapbeg;
}
for(;;) {
if( miniheap_ptr == NULL ) {
break;
}
__MiniHeapRover = miniheap_ptr;
largest = miniheap_ptr->largest_blk;
if( largest >= amt ) {
ptr = __MemAllocator( amt, _DGroup(), (unsigned)miniheap_ptr );
if( ptr != NULL ) {
goto lbl_release_heap;
}
}
if( largest > __LargestSizeB4MiniHeapRover ) {
__LargestSizeB4MiniHeapRover = largest;
}
miniheap_ptr = miniheap_ptr->next;
}
if( expanded || !__ExpandDGROUP( amt ) ) {
if( !__nmemneed( amt ) ) {
break;
}
expanded = 0;
} else {
expanded = 1;
}
}
lbl_release_heap:
_ReleaseNHeap();
return( (void _WCNEAR *)ptr );
}
/programs/develop/open watcom/trunk/clib/heap/nmemneed.c
0,0 → 1,42
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
 
int __nmemneed( size_t size )
{
size = size;
return( 0 );
}
 
/programs/develop/open watcom/trunk/clib/heap/nmsize.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <malloc.h>
#include "heap.h"
 
 
#if defined(__SMALL_DATA__)
_WCRTLINK size_t _msize( void *p )
{
tag *q;
 
q = (tag *)(((unsigned char *)p) - TAG_SIZE);
return( ( *q & ~1 ) - TAG_SIZE );
}
#endif
 
_WCRTLINK size_t _nmsize( void _WCNEAR *p )
{
tag _WCNEAR *q;
 
q = (tag _WCNEAR *)(((unsigned char _WCNEAR *)p) - TAG_SIZE);
return( ( *q & ~1 ) - TAG_SIZE );
}
/programs/develop/open watcom/trunk/clib/heap/nrealloc.c
0,0 → 1,88
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Near heap realloc routines.
*
****************************************************************************/
 
 
//#include "dll.h" // needs to be first
#include "variety.h"
#include <stddef.h>
#include <malloc.h>
#include <string.h>
#include "heap.h"
#if defined(__DOS_EXT__)
#include "extender.h"
#endif
 
#if defined(__SMALL_DATA__)
 
_WCRTLINK void *realloc( void *stg, size_t amount )
{
return( _nrealloc( stg, amount ) );
}
 
#endif
 
#pragma intrinsic(memcpy)
 
_WCRTLINK void _WCNEAR *_nrealloc( void _WCI86NEAR *stg, size_t req_size )
{
void _WCNEAR *p;
size_t old_size;
 
if( stg == NULL ) {
return( _nmalloc( req_size ) );
}
if( req_size == 0 ) {
_nfree( stg );
return( (void _WCNEAR *) NULL );
}
old_size = _nmsize( stg );
p = _nexpand( stg, req_size ); /* try to expand it in place */
if( p == NULL ) { /* if couldn't be expanded in place */
#if defined(__DOS_EXT__)
if( _IsRational() ) {
frlptr flp, newflp;
 
flp = (frlptr) ((PTR)stg - TAG_SIZE);
newflp = __ReAllocDPMIBlock( flp, req_size + TAG_SIZE );
if( newflp ) {
return( (void _WCNEAR *)((PTR)newflp + TAG_SIZE) );
}
}
#endif
p = _nmalloc( req_size ); /* - allocate a new block */
if( p != NULL ) { /* - if we got one */
memcpy( p, stg, old_size ); /* copy it */
_nfree( stg ); /* and free old one */
} else {
_nexpand( stg, old_size ); /* reset back to old size */
}
}
return( p );
}
/programs/develop/open watcom/trunk/clib/heap/sbrkwnt.c
0,0 → 1,64
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <dos.h>
//#include <windows.h>
 
void* _stdcall UserAlloc(int size);
 
 
extern unsigned _curbrk;
extern unsigned _STACKTOP;
 
_WCRTLINK void _WCNEAR *sbrk( int increment )
{
if( increment > 0 )
{
void* p;
 
increment = ( increment + 0x0fff ) & ~0x0fff;
//p = LocalAlloc( LMEM_FIXED, increment );
//p = VirtualAlloc(NULL, increment, MEM_COMMIT,PAGE_EXECUTE_READWRITE);
p = UserAlloc(increment);
if( p != NULL ) return( p );
errno = ENOMEM;
}
else
{
errno = EINVAL;
}
return( (void *) -1 );
}
/programs/develop/open watcom/trunk/clib/memory/bcmp.c
0,0 → 1,45
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
 
_WCRTLINK int bcmp( const void *s1, const void *s2, size_t n )
/************************************************************/
{
if( memcmp( s1, s2, n ) == 0 ) {
return( 0 );
} else {
return( 1 );
}
}
/programs/develop/open watcom/trunk/clib/memory/bcopy.c
0,0 → 1,41
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
 
_WCRTLINK void bcopy( const void *s1, void *s2, size_t n )
/********************************************************/
{
memmove( s2, s1, n );
}
/programs/develop/open watcom/trunk/clib/memory/bzero.c
0,0 → 1,41
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
 
_WCRTLINK void bzero( void *s, size_t n )
/***************************************/
{
memset( s, 0, n );
}
/programs/develop/open watcom/trunk/clib/memory/fmemccpy.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
_WCRTLINK void _WCFAR *_fmemccpy( void _WCFAR *d, const void _WCFAR *s, int c, size_t cnt )
{
char _WCFAR *dst = d;
const char _WCFAR *src = s;
for(;;) {
if( cnt == 0 ) break;
*dst = *src;
++dst;
if( *src == c ) return( dst );
++src;
--cnt;
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/memory/fmemchr.c
0,0 → 1,56
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of fmemchr().
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include "xstring.h"
 
/* locate the first occurrence of c in the initial n characters of the
object pointed to by s.
If the character c is not found, NULL is returned.
*/
 
#undef _fmemchr
 
_WCRTLINK void _WCFAR *_fmemchr( const void _WCFAR *vs, int c, size_t n )
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fmemchr( vs, c, n ) );
#else
const char _WCFAR *s = vs;
while( n ) {
if( *s == c ) return( (void _WCFAR *)s );
++s;
--n;
}
return( NULL );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/fmemcmp.c
0,0 → 1,52
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "xstring.h"
#undef _fmemcmp
 
_WCRTLINK int _fmemcmp( const void _WCFAR *v1,
const void _WCFAR *v2, size_t len )
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fmemcmp( v1, v2, len ) );
#else
const unsigned char _WCFAR *s1 = v1;
const unsigned char _WCFAR *s2 = v2;
for( ; len; --len ) {
if( *s1 != *s2 ) return( *s1 - *s2 );
++s1;
++s2;
}
return( 0 ); /* both operands are equal */
#endif
}
/programs/develop/open watcom/trunk/clib/memory/fmemcpy.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "xstring.h"
#undef _fmemcpy
 
_WCRTLINK void _WCFAR *_fmemcpy( void _WCFAR *dst, const void _WCFAR *s, size_t len )
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fmemcpy( dst, s, len ) );
#else
const char _WCFAR *src = s;
char _WCFAR *p;
for( p = dst; len; --len ) {
*p++ = *src++;
}
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/fmemicmp.c
0,0 → 1,54
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
#include <ctype.h>
 
_WCRTLINK int _fmemicmp( const void _WCFAR *v1, const void _WCFAR *v2, size_t len )
{
unsigned char c1;
unsigned char c2;
const unsigned char _WCFAR *s1;
const unsigned char _WCFAR *s2;
 
for( s1 = v1, s2 = v2 ; len; --len ) {
c1 = *s1;
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
c2 = *s2;
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
if( c1 != c2 ) return( c1 - c2 );
++s1;
++s2;
}
return( 0 ); /* both operands are equal */
}
/programs/develop/open watcom/trunk/clib/memory/fmemmove.c
0,0 → 1,166
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <string.h>
 
#if defined(__386__)
 
#if defined(__FLAT__)
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movefwd = \
0x06 /* push es */\
0x8e 0xc2 /* mov es,dx */\
0x1e /* push ds */\
0x96 /* xchg esi,eax */\
0x8e 0xd8 /* mov ds,ax */\
0xd1 0xe9 /* shr cx,1 */\
0x66 0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
0x1f /* pop ds */\
0x07 /* pop es */\
parm [dx edi] [si eax] [ecx] \
modify exact [edi esi ecx eax];
#else
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movefwd = \
0x1e /* push ds */\
0x96 /* xchg esi,eax */\
0x8e 0xd8 /* mov ds,ax */\
0xd1 0xe9 /* shr cx,1 */\
0x66 0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
0x1f /* pop ds */\
parm [es edi] [si eax] [ecx] \
modify exact [edi esi ecx eax];
#endif
 
#elif defined(M_I86)
#if defined(__SMALL_DATA__)
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movebwd = \
0xfd /* std */\
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0x4e /* dec si */\
0x4f /* dec di */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0x46 /* inc si */\
0x47 /* inc di */\
0xf3 0xa4 /* rep movsb */\
0xfc /* cld */\
0x1f /* pop ds */\
parm [es di] [si ax] [cx] \
modify exact [di si cx ax];
 
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movefwd = \
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
0x1f /* pop ds */\
parm [es di] [si ax] [cx] \
modify exact [di si cx ax];
#else
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movebwd = \
0xfd /* std */\
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0x4e /* dec si */\
0x4f /* dec di */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0x46 /* inc si */\
0x47 /* inc di */\
0xf3 0xa4 /* rep movsb */\
0xfc /* cld */\
0x1f /* pop ds */\
parm [es di] [si ax] [cx] \
modify exact [di si cx ax];
 
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movefwd = \
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
0x1f /* pop ds */\
parm [es di] [si ax] [cx] \
modify exact [di si cx ax];
#endif
#else
#error platform not supported
#endif
 
 
_WCRTLINK void _WCFAR *_fmemmove( void _WCFAR *t, const void _WCFAR *f, size_t len )
{
char _WCFAR *to = t;
const char _WCFAR *from = f;
if( from == to ) {
return( to );
}
if( from < to && from + len > to ) { /* if buffers are overlapped*/
#if defined(__HUGE__) || defined(__386__)
to += len;
from += len;
while( len != 0 ) {
to--;
from--;
*to = *from;
len--;
}
#else
movebwd(( to + len ) - 1, ( from + len ) - 1, len );
#endif
} else {
movefwd( to, from, len );
}
return( to );
}
 
/programs/develop/open watcom/trunk/clib/memory/fmemset.c
0,0 → 1,51
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include "xstring.h"
 
#undef _fmemset
 
_WCRTLINK void _WCFAR *_fmemset( void _WCFAR *dst, int c, size_t len )
{
 
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fmemset( dst, c, len ) );
#else
char _WCFAR *p;
for( p = dst; len; --len ) {
*p++ = c;
}
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memccpy.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
_WCRTLINK void *memccpy( void *d, const void *s, int c, size_t cnt )
{
char *dst = d;
const char *src = s;
for(;;) {
if( cnt == 0 ) break;
*dst = *src;
++dst;
if( *src == c ) return( dst );
++src;
--cnt;
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/memory/memchr.c
0,0 → 1,59
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memchr() and wmemchr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
/* locate the first occurrence of c in the initial n characters of the
object pointed to by s.
If the character c is not found, NULL is returned.
*/
 
_WCRTLINK VOID_WC_TYPE *__F_NAME(memchr,wmemchr)( const VOID_WC_TYPE *s, INT_WC_TYPE c, size_t n )
{
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
return( _inline_memchr( s, c, n ) );
#else
const CHAR_TYPE *cs = s;
 
while( n ) {
if( *cs == c ) {
return( (VOID_WC_TYPE *)cs );
}
++cs;
--n;
}
return( NULL );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memcmp.c
0,0 → 1,56
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memcmp() and wmemcmp().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
 
_WCRTLINK int __F_NAME(memcmp,wmemcmp)( const VOID_WC_TYPE *in_s1, const VOID_WC_TYPE *in_s2, size_t len )
{
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
return( _inline_memcmp( in_s1, in_s2, len ) );
#else
const CHAR_TYPE *s1 = in_s1;
const CHAR_TYPE *s2 = in_s2;
 
for( ; len; --len ) {
if( *s1 != *s2 ) {
return( *s1 - *s2 );
}
++s1;
++s2;
}
return( 0 ); /* both operands are equal */
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memcpy.c
0,0 → 1,52
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memcpy() and wmemcpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
 
_WCRTLINK VOID_WC_TYPE *__F_NAME(memcpy,wmemcpy)( VOID_WC_TYPE *in_dst, const VOID_WC_TYPE *in_src, size_t len )
{
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
return( _inline_memcpy( in_dst, in_src, len ) );
#else
CHAR_TYPE *dst = in_dst;
const CHAR_TYPE *src = in_src;
 
for( ; len; --len ) {
*dst++ = *src++;
}
return( in_dst );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memcpy_s.c
0,0 → 1,75
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memcpy_s() - bounds-checking memcpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
_WCRTLINK errno_t __F_NAME(memcpy_s,wmemcpy_s)( VOID_WC_TYPE * __restrict s1,
rsize_t s1max,
const VOID_WC_TYPE * __restrict s2,
rsize_t n )
/*****************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// n <= RSIZE_MAX
// n <= s1max
// s1 and s2 no overlap
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_maxsize_msg( msg, n ) &&
__check_constraint_a_gt_b_msg( msg, n, s1max ) &&
__check_constraint_overlap_msg( msg, s1, s1max, s2, n ) ) {
 
// now it's safe to use memcpy
__F_NAME(memcpy,wmemcpy)( s1, s2, n );
rc = 0;
} else {
// Runtime-constraints violated, zero out destination array
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
__F_NAME(memset,wmemset)( s1, 0, s1max );
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
 
return( rc );
}
/programs/develop/open watcom/trunk/clib/memory/memicmp.c
0,0 → 1,54
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
#include <ctype.h>
 
_WCRTLINK int memicmp( const void *in_s1, const void *in_s2, size_t len )
{
const unsigned char * s1 = (const unsigned char *)in_s1;
const unsigned char * s2 = (const unsigned char *)in_s2;
unsigned char c1;
unsigned char c2;
 
for( ; len; --len ) {
c1 = *s1;
c2 = *s2;
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
if( c1 != c2 ) return( c1 - c2 );
++s1;
++s2;
}
return( 0 ); /* both operands are equal */
}
/programs/develop/open watcom/trunk/clib/memory/memmov_s.c
0,0 → 1,74
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memmove_s() - bounds-checking memmove().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
_WCRTLINK errno_t __F_NAME(memmove_s,wmemmove_s)( VOID_WC_TYPE * __restrict s1,
rsize_t s1max,
const VOID_WC_TYPE * __restrict s2,
rsize_t n )
/*******************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// n <= RSIZE_MAX
// n <= s1max
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_maxsize_msg( msg, n ) &&
__check_constraint_a_gt_b_msg( msg, n, s1max ) ) {
 
/* now it's safe to use memmove */
__F_NAME(memmove,wmemmove)( s1, s2, n );
rc = 0;
} else {
// Runtime-constraints violated, zero out destination array
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
__F_NAME(memset,wmemset)( s1, 0, s1max );
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
 
return( rc );
}
/programs/develop/open watcom/trunk/clib/memory/memmove.c
0,0 → 1,167
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memmove().
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <string.h>
 
#if defined(__386__)
extern void movefwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
#pragma aux movefwd = \
0x06 /* push es */\
0x8e 0xc2 /* mov es,dx */\
0x51 /* push ecx */\
0xc1 0xe9 0x02 /* shr ecx,2 */\
0xf3 0xa5 /* rep movsd */\
0x59 /* pop ecx */\
0x83 0xe1 0x03 /* and ecx,3 */\
0xf3 0xa4 /* rep movsb */\
0x07 /* pop es */\
parm [dx edi] [esi] [ecx] \
modify exact [edi esi ecx];
extern void movebwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
#pragma aux movebwd = \
0x06 /* push es */\
0x8e 0xc2 /* mov es,dx */\
0xfd /* std */\
0x4e /* dec esi */\
0x4f /* dec edi */\
0xd1 0xe9 /* shr ecx,1 */\
0x66 0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc ecx,ecx */\
0x46 /* inc esi */\
0x47 /* inc edi */\
0x66 0xf3 0xa4 /* rep movsb */\
0x07 /* pop es */\
0xfc /* cld */\
parm [dx edi] [esi] [ecx] \
modify exact [edi esi ecx];
#define HAVE_MOVEFWBW
 
#elif defined(M_I86) && defined(__SMALL_DATA__)
extern void movebwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
#pragma aux movebwd = \
0xfd /* std */\
0x4e /* dec si */\
0x4f /* dec di */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0x46 /* inc si */\
0x47 /* inc di */\
0xf3 0xa4 /* rep movsb */\
0xfc /* cld */\
parm [es di] [si] [cx] \
modify exact [di si cx];
 
extern void movefwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
#pragma aux movefwd = \
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
parm [es di] [si] [cx] \
modify exact [di si cx];
#define HAVE_MOVEFWBW
 
#elif defined(M_I86) && defined(__BIG_DATA__)
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movebwd = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xfd /* std */\
0x4e /* dec si */\
0x4f /* dec di */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0x46 /* inc si */\
0x47 /* inc di */\
0xf3 0xa4 /* rep movsb */\
0xfc /* cld */\
0x1f /* pop ds */ \
parm [es di] [dx si] [cx] \
modify exact [di si cx];
 
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
#pragma aux movefwd = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xa5 /* rep movsw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xa4 /* rep movsb */\
0x1f /* pop ds */ \
parm [es di] [dx si] [cx] \
modify exact [di si cx];
#define HAVE_MOVEFWBW
 
#else
// no pragma for non-x86
#endif
 
 
_WCRTLINK void *memmove( void *toStart, const void *fromStart, size_t len )
{
const char *from = fromStart;
char *to = toStart;
 
if( from == to ) {
return( to );
}
if( from < to && from + len > to ) { /* if buffers are overlapped*/
#if defined( __HUGE__ ) || !defined( HAVE_MOVEFWBW )
to += len;
from += len;
while( len != 0 ) {
*--to = *--from;
len--;
}
#else
movebwd(( to + len ) - 1, ( from + len ) - 1, len );
#endif
} else {
#if !defined( HAVE_MOVEFWBW )
while( len != 0 ) {
*to++ = *from++;
len--;
}
#else
movefwd( to, from, len );
#endif
}
 
#if defined(__HUGE__) || !defined( HAVE_MOVEFWBW )
return( toStart );
#else
return( to );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memset.c
0,0 → 1,73
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of memset() and wmemset().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "xstring.h"
 
 
#if defined(__386__)
extern void __STOSB( void *, int, unsigned );
#pragma aux __STOSB "*" parm [eax] [edx] [ecx];
 
extern void *__set386( void *, int, unsigned );
#pragma aux __set386 = \
"push EAX" /* save return value*/\
"mov DH,DL" /* duplicate byte value thru EDX */\
"shl EDX,8" /* ... */\
"mov DL,DH" /* ... */\
"shl EDX,8" /* ... */\
"mov DL,DH" /* ... */\
"call __STOSB" /* do store */\
"pop EAX" /* restore return value*/\
parm [eax] [edx] [ecx] \
value [eax];
#endif
 
_WCRTLINK VOID_WC_TYPE *__F_NAME(memset,wmemset)( VOID_WC_TYPE *dst, INT_WC_TYPE c, size_t len )
{
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
#if defined(__386__)
return( __set386( dst, c, len ) );
#else
return( _inline_memset( dst, c, len ) );
#endif
#else
CHAR_TYPE *p;
 
for( p = dst; len; --len ) {
*p++ = c;
}
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/memory/memtest.c
0,0 → 1,289
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
/*
* MEMTEST.C
* Non-exhaustive test of the C library memory manipulation functions.
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__386__) || defined(M_I86)
#include <i86.h>
#endif
#ifdef __SW_BW
#include <wdefwin.h>
#endif
 
 
#define VERIFY( exp ) if( !(exp) ) { \
printf( "%s: ***FAILURE*** at line %d of %s.\n",\
ProgramName, __LINE__, \
strlwr(__FILE__) ); \
NumErrors++; \
exit(-1); \
}
 
void TestCompare( void );
void TestCompareF( void );
void TestCopy( void );
void TestCopyF( void );
void TestOverlap( void );
void TestOverlapF( void );
void TestMisc( void );
 
 
char ProgramName[128]; /* executable filename */
int NumErrors = 0; /* number of errors */
 
 
 
/****
***** Program entry point.
****/
 
int main( int argc, char *argv[] )
{
#ifdef __SW_BW
FILE *my_stdout;
my_stdout = freopen( "tmp.log", "a", stdout );
if( my_stdout == NULL ) {
fprintf( stderr, "Unable to redirect stdout\n" );
exit( -1 );
}
#endif
 
/*** Initialize ***/
strcpy( ProgramName, strlwr(argv[0]) ); /* store filename */
 
/*** Test various functions ***/
TestCompare(); /* comparing stuff */
TestCopy(); /* copying stuff */
TestOverlap(); /* test overlapping copy */
TestMisc(); /* other stuff */
 
#if defined(__386__) || defined(M_I86)
TestCompareF();
TestCopyF();
TestOverlapF();
#endif
 
/*** Print a pass/fail message and quit ***/
if( NumErrors!=0 ) {
printf( "%s: SUCCESS.\n", ProgramName );
return( EXIT_SUCCESS );
}
printf( "Tests completed (%s).\n", strlwr( argv[0] ) );
#ifdef __SW_BW
{
fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) );
fclose( my_stdout );
_dwShutDown();
}
#endif
return( 0 );
}
 
 
 
/****
***** Test memcmp(), memicmp(), and memchr().
****/
 
void TestCompare( void )
{
char buf[80];
char * ptr;
int status;
 
strcpy( buf, "Foo !" ); /* initialize string */
 
status = memcmp( buf, "Foo", 3 ); /* compare */
VERIFY( status == 0 );
 
status = memcmp( buf, "Foo!", 4 ); /* compare */
VERIFY( status != 0 );
 
status = memicmp( buf, "FOO", 3 ); /* compare */
VERIFY( status == 0 );
 
status = memicmp( buf, "fOo!", 4 ); /* compare */
VERIFY( status != 0 );
 
ptr = memchr( buf, '~', 6 ); /* try to find a tilde */
VERIFY( ptr == NULL );
 
ptr = memchr( buf, '!', 6 ); /* find the '!' */
VERIFY( ptr == buf+4 );
}
 
 
#if defined(__386__) || defined(M_I86)
void TestCompareF( void )
{
char buf[80];
char __far * ptr;
int status;
 
strcpy( buf, "Foo !" ); /* initialize string */
 
status = _fmemcmp( buf, "Foo", 3 ); /* compare */
VERIFY( status == 0 );
 
status = _fmemcmp( buf, "Foo!", 4 ); /* compare */
VERIFY( status != 0 );
 
ptr = _fmemchr( buf, '~', 6 ); /* try to find a tilde */
VERIFY( ptr == NULL );
 
ptr = _fmemchr( buf, '!', 6 ); /* find the '!' */
VERIFY( ptr == buf+4 );
}
#endif
 
 
 
/****
***** Test memcpy(), memccpy(), and movedata().
****/
 
void TestCopy( void )
{
char bufA[80], bufB[80];
 
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
memccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
VERIFY( !memcmp(bufA, "Hello", 5) ); /* ensure copied ok */
 
memcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
VERIFY( !strcmp(bufA, bufB) ); /* ensure copied ok */
}
 
 
#if defined(__386__) || defined(M_I86)
void TestCopyF( void )
{
char __far bufA[80], bufB[80];
char __far testStr[] = "Foo Bar Goober Blah";
 
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
_fmemccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
VERIFY( !_fmemcmp(bufA, "Hello", 5) ); /* ensure copied ok */
 
_fmemcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
VERIFY( !_fstrcmp(bufA, bufB) ); /* ensure copied ok */
 
movedata( FP_SEG(bufA), FP_OFF(bufA), /* copy data */
FP_SEG(testStr), FP_OFF(testStr),
_fstrlen(testStr) );
VERIFY( !_fmemcmp(bufA, testStr, _fstrlen(testStr)) );
}
#endif
 
 
 
/****
***** Test memmove().
****/
 
void TestOverlap( void )
{
char bufA[80], bufB[80];
 
strcpy( bufA, " Hello, world!" ); /* initialize string */
 
memmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
VERIFY( !strcmp(bufB, bufA) );
 
memmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
VERIFY( !strcmp(bufA, "Hello, world!!") );
 
memmove( bufA+1, bufA, strlen(bufA+1) );
VERIFY( !strcmp(bufA, "HHello, world!") );
}
 
 
#if defined(__386__) || defined(M_I86)
void TestOverlapF( void )
{
char bufA[80], bufB[80];
 
strcpy( bufA, " Hello, world!" ); /* initialize string */
 
_fmemmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
VERIFY( !strcmp(bufB, bufA) );
 
_fmemmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
VERIFY( !strcmp(bufA, "Hello, world!!") );
 
_fmemmove( bufA+1, bufA, strlen(bufA+1) );
VERIFY( !strcmp(bufA, "HHello, world!") );
}
#endif
 
 
 
/****
***** Test memset(), _fmemset(), and swab().
****/
 
void TestMisc( void )
{
char bufA[80], bufB[80];
void * addr;
int count;
 
addr = memset( bufA, 0x00, 80 ); /* zero out memory */
VERIFY( addr == bufA );
 
for( count=0; count<80; count++ ) /* ensure all zero bytes */
VERIFY( bufA[count] == 0x00 );
 
#if defined(__386__) || defined(M_I86)
{
void __far * addrFar;
addrFar = _fmemset( bufB, 0x00, 80 ); /* zero out memory */
VERIFY( addrFar == bufB );
 
for( count=0; count<80; count++ ) { /* ensure all zero bytes */
VERIFY( bufB[count] == 0x00 );
}
}
#else
memset( bufB, 0x00, 80 ); /* zero out memory */
#endif
 
strcpy( bufA, "eHll,ow rodl" ); /* initialize string */
swab( bufA, bufB, strlen(bufA) ); /* swap pairs of characters */
VERIFY( !strcmp(bufB, "Hello, world") ); /* ensure swapped ok */
}
/programs/develop/open watcom/trunk/clib/memory/movedata.c
0,0 → 1,46
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of movedata().
*
****************************************************************************/
 
 
#include "variety.h"
/* Inline variant must always be used, no equivalent exists */
#ifndef __INLINE_FUNCTIONS__
#define __INLINE_FUNCTIONS__
#endif
#include "xstring.h"
 
#undef movedata
 
 
_WCRTLINK void movedata( unsigned fromseg, unsigned fromoff,
unsigned toseg, unsigned tooff, unsigned len )
{
_inline_movedata( fromseg, fromoff, toseg, tooff, len );
}
/programs/develop/open watcom/trunk/clib/memory/swab.c
0,0 → 1,47
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
 
_WCRTLINK void swab( char *src, char *dst, int n )
{
char c;
 
for( n = n >> 1; n; --n ) {
c = src[0]; /* 25-jun-90: just in case src and dst are the same */
dst[0] = src[1];
dst[1] = c;
dst += 2;
src += 2;
}
}
/programs/develop/open watcom/trunk/clib/search/bsearch.c
0,0 → 1,83
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#undef __INLINE_FUNCTIONS__
#include <stddef.h>
#include <stdlib.h>
#include "extfunc.h"
 
/*
The old bsearch could SIGSEGV if the compare is done on elements
which are not within the given segment. The error occurs if the search
key is larger than the 'high' element (or lower than the 'low' member)
and 'low','mid' and 'high' are all equal (either from the start or
after several iterations).
*/
 
typedef int bcomp();
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) bcomp;
#endif
 
_WCRTLINK void * bsearch( const void * key,
const void * base,
size_t nmemb,
size_t size,
int (*cmp)() )
{
char *low;
char *high;
char *mid;
int cond;
bcomp *compar = cmp;
 
if( nmemb == 0 ) {
return( NULL );
}
low = (char *) base;
high = low + (nmemb-1) * size;
// JBS while( low <= high ) {
while( low < high ) {
mid = low + ( (high-low)/size/2 ) * size;
cond = (*compar)( key, mid );
if( cond == 0 ) return( mid );
if( cond < 0 ) { /* key < mid */
// JBS high = mid - size;
high = mid;
} else { /* key > mid */
low = mid + size;
}
}
if (low == high) return( (*compar)(key, low) ? NULL : low );
return( NULL );
}
/programs/develop/open watcom/trunk/clib/search/bsrch_s.c
0,0 → 1,84
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of bsearch_s() - bounds-checking bsearch().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#undef __INLINE_FUNCTIONS__
#include <stddef.h>
#include <stdlib.h>
#include "extfunc.h"
 
typedef int bcomp();
#ifdef _M_IX86
#pragma aux (__outside_CLIB) bcomp;
#endif
 
_WCRTLINK void * bsearch_s( const void * key, const void * base,
rsize_t nmemb, rsize_t size,
int (*compar)( const void *k, const void *y, void *context ),
void *context )
/***********************************************************************/
{
char *low;
char *high;
char *mid;
int cond;
bcomp *comp = compar;
 
/* runtime-constraints */
// nmemb <= RSIZE_MAX
// size <= RSIZE_MAX
// if nmemb > 0 then key, base, compar not NULL
if( __check_constraint_maxsize( nmemb ) &&
__check_constraint_maxsize( size ) &&
( (nmemb == 0) || __check_constraint_nullptr( key ) &&
__check_constraint_nullptr( base ) &&
__check_constraint_nullptr( compar )) ) {
 
if( nmemb == 0 ) { /* empty array - nothing to do */
return( NULL );
}
low = (char *) base;
high = low + (nmemb - 1) * size;
while( low < high ) {
mid = low + ( (high - low) / size / 2 ) * size;
cond = (*comp)( key, mid, context );
if( cond == 0 ) return( mid );
if( cond < 0 ) { /* key < mid */
high = mid;
} else { /* key > mid */
low = mid + size;
}
}
if (low == high) return( (*comp)( key, low, context ) ? NULL : low );
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/search/lfind.c
0,0 → 1,65
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "extfunc.h"
#undef __INLINE_FUNCTIONS__
#include <stddef.h>
#include <search.h>
 
typedef int lcomp( const void *, const void * );
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) lcomp;
#endif
 
_WCRTLINK void *lfind(
const void *key,
const void *base,
unsigned *num,
unsigned width,
int (*compare)(
const void *,
const void *
)
)
{
lcomp *cmp = (lcomp *)compare;
unsigned n;
 
for( n = *num; n; --n )
{
if( cmp( key, base ) == 0 )
return( (void *)base );
base = ((const char *)base) + width;
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/search/lsearch.c
0,0 → 1,68
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "extfunc.h"
#undef __INLINE_FUNCTIONS__
#include <stddef.h>
#include <string.h>
#include <search.h>
 
typedef int lcomp( const void *, const void * );
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) lcomp;
#endif
 
_WCRTLINK void *lsearch(
const void *key,
void *base,
unsigned *num,
unsigned width,
int (*compare)(
const void *,
const void *
)
)
{
lcomp *cmp = (lcomp *)compare;
unsigned n;
 
for( n = *num; n; --n )
{
if( cmp( key, base ) == 0 )
return( base );
base = ((char *)base) + width;
}
memcpy( base, key, width );
++*num;
return( base );
}
/programs/develop/open watcom/trunk/clib/search/qsort.c
0,0 → 1,83
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#undef __INLINE_FUNCTIONS__
#include <stdio.h>
#include <stdlib.h>
#include "extfunc.h"
 
typedef int qcomp( const void *, const void * );
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) qcomp;
#endif
 
 
/* Function to find the median value */
static char *med3( char *a, char *b, char *c, qcomp cmp )
{
if( cmp( a, b ) > 0 ) {
if( cmp( a, c ) > 0 ) {
if( cmp( b, c ) > 0 ) {
return( b );
} else {
return( c );
}
} else {
return( a );
}
} else {
if( cmp( a, c ) >= 0 ) {
return( a );
} else {
if( cmp( b, c ) > 0 ) {
return( c );
} else {
return( b );
}
}
}
}
 
 
#ifdef __AXP__
 
#else
 
#define FUNCTION_LINKAGE _WCRTLINK
#define FUNCTION_NAME qsort
#define PTRATTR
#define MED3 med3
#define BYTESWAP byteswap
#include "qsortrtn.c"
 
#endif
/programs/develop/open watcom/trunk/clib/search/qsort_s.c
0,0 → 1,118
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of qsort_s() - bounds-checking qsort().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#undef __INLINE_FUNCTIONS__
#include <stdio.h>
#include <stdlib.h>
#include "extfunc.h"
 
typedef int qcomp( const void *, const void *, void * );
#if defined(_M_IX86)
#pragma aux (__outside_CLIB) qcomp;
#endif
 
 
/* Function to find the median value */
static char *med3( char *a, char *b, char *c, qcomp cmp, void *context )
{
if( cmp( a, b, context ) > 0 ) {
if( cmp( a, c, context ) > 0 ) {
if( cmp( b, c, context ) > 0 ) {
return( b );
} else {
return( c );
}
} else {
return( a );
}
} else {
if( cmp( a, c, context ) >= 0 ) {
return( a );
} else {
if( cmp( b, c, context ) > 0 ) {
return( c );
} else {
return( b );
}
}
}
}
 
 
#ifdef __AXP__
 
#define FUNCTION_LINKAGE static
#define FUNCTION_NAME aligned_qsort
#define PTRATTR
#define MED3 med3
#define BYTESWAP aligned_byteswap
#include "qsortr_s.c"
 
#undef FUNCTION_NAME
#undef PTRATTR
#undef MED3
#undef BYTESWAP
#define FUNCTION_NAME unaligned_qsort
#define PTRATTR __unaligned
#define BYTESWAP unaligned_byteswap
#define MED3(a,b,c,f,x) med3( (char*)(a), (char*)(b), (char*)(c), (f), (x) )
#include "qsortr_s.c"
 
_WCRTLINK errno_t qsort_s( void *in_base, rsize_t n, rsize_t size,
int (*compar)( const void *, const void *, void * ),
void *context )
/*****************************************************************/
{
/*
* If size%4 is 0 and the input base pointer is on a word boundary,
* call the aligned version of qsort. Otherwise, call the version
* that knows its pointers will be unaligned, so all the fixups can
* be done by qsort rather than by expensive OS exceptions.
*/
if( (size&3) == 0 && (((unsigned)in_base)&3) == 0 ) {
return( aligned_qsort( in_base, n, size, compar, context ) );
} else {
return( unaligned_qsort( (__unaligned void *)in_base, n, size, compar, context ) );
}
}
 
#else
 
#define FUNCTION_LINKAGE _WCRTLINK
#define FUNCTION_NAME qsort_s
#define PTRATTR
#define MED3 med3
#define BYTESWAP byteswap
#include "qsortr_s.c"
 
#endif
/programs/develop/open watcom/trunk/clib/search/qsortr_s.c
0,0 → 1,360
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of qsort_s() - bounds-checking qsort().
* Included by qsort_s.c.
*
****************************************************************************/
 
 
/* Support OS/2 16-bit protected mode - will never get stack overflow */
#define MAXDEPTH (sizeof( long ) * 8)
 
#define SHELL 3 /* Shell constant used in shell sort */
 
typedef int WORD;
#define W sizeof( WORD )
 
/*
swap() is a macro that chooses between an in_line function call and
an exchange macro.
*/
#define exch( a, b, t) ( t = a, a = b, b = t )
#define swap( a, b ) \
swaptype != 0 ? BYTESWAP( a, b, size ) : \
( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t )
 
/*
Note: The following assembly was timed against several other methods
of doing the same thing. The pragmas here were either fastest on all
machines tested, or fastest on most machines tested. (including an 8088,
386 16mhz, 386 33mhz, and 486 25mhz).
*/
 
#if defined( __386__ )
/* this is intended for 386 only... */
void inline_swap( char *p, char *q, size_t size );
#pragma aux inline_swap = \
0x06 /* push es */ \
0x1e /* push ds */ \
0x07 /* pop es */ \
0x0f 0xb6 0xd1 /* movzx edx,cl */ \
0xc1 0xe9 0x02 /* shr ecx,02H */ \
0x74 0x0b /* je L1 */ \
0x8b 0x07 /*L2 mov eax,[edi] */ \
0x87 0x06 /* xchg eax,[esi] */ \
0xab /* stosd */ \
0x83 0xc6 0x04 /* add esi,0004H */ \
0x49 /* dec ecx */ \
0x75 0xf5 /* jne L2 */ \
0x80 0xe2 0x03 /*L1 and dl,03H */ \
0x74 0x09 /* je L3 */ \
0x8a 0x07 /*L4 mov al,[edi] */ \
0x86 0x06 /* xchg al,[esi] */ \
0xaa /* stosb */ \
0x46 /* inc esi */ \
0x4a /* dec edx */ \
0x75 0xf7 /* jne L4 */ \
/*L3 */ \
0x07 /* pop es */ \
parm caller [esi] [edi] [ecx] \
value \
modify exact [esi edi ecx eax edx];
#pragma aux byteswap parm [esi] [edi] [ecx] \
modify exact [esi edi ecx eax edx];
static void _WCNEAR byteswap( char *p, char *q, size_t size ) {
inline_swap( p, q, size );
}
 
#elif defined( M_I86 ) && defined( __BIG_DATA__ )
void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size );
#pragma aux inline_swap = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xd1 0xe9 /* shr cx,1 */ \
0x74 0x0b /* je L1 */ \
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
0x87 0x04 /* xchg ax,[si] */ \
0xab /* stosw */ \
0x46 /* inc si */ \
0x46 /* inc si */ \
0x49 /* dec cx */ \
0x75 0xf5 /* jne L2 */ \
0x73 0x07 /*L1 jnc L3 */ \
0x8a 0x04 /* mov al,[si] */ \
0x26 0x86 0x05 /* xchg al,es:[di] */ \
0x88 0x04 /* mov [si],al */ \
0x1f /*L3 pop ds */ \
parm caller [dx si] [es di] [cx] \
value \
modify exact [si di cx ax];
#pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax];
static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) {
inline_swap( p, q, size );
}
 
#elif defined( M_I86 ) && defined( __SMALL_DATA__ )
/* we'll ask for char __far *q to save us writing code to load es */
void inline_swap( char *p, char _WCFAR *q, size_t size );
#pragma aux inline_swap = \
0xd1 0xe9 /* shr cx,1 */ \
0x74 0x0b /* je L1 */ \
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
0x87 0x04 /* xchg ax,[si] */ \
0xab /* stosw */ \
0x46 /* inc si */ \
0x46 /* inc si */ \
0x49 /* dec cx */ \
0x75 0xf5 /* jne L2 */ \
0x73 0x07 /*L1 jnc L3 */ \
0x8a 0x04 /* mov al,[si] */ \
0x26 0x86 0x05 /* xchg al,es:[di] */ \
0x88 0x04 /* mov [si],al */ \
/*L3 */ \
parm caller [si] [es di] [cx] \
value \
modify exact [si di cx ax];
#pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax];
static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) {
inline_swap( p, q, size );
}
 
#else
/* this is an optimized version of a simple byteswap */
#define inline_swap BYTESWAP
static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) {
long dword;
short word;
char byte;
 
#if 1 /* this is for 32 bit machines */
while( size > 3 ) {
dword = *(PTRATTR long *)p;
*(PTRATTR long *)p = *(PTRATTR long *)q;
*(PTRATTR long *)q = dword;
p += 4;
q += 4;
size -= 4;
}
if( size > 1 ) {
word = *(PTRATTR short *)p;
*(PTRATTR short *)p = *(PTRATTR short *)q;
*(PTRATTR short *)q = word;
p += 2;
q += 2;
size -= 2;
}
#else /* this is for 16 bit machines */
while( size > 1 ) {
word = *(PTRATTR short *)p;
*(PTRATTR short *)p = *(PTRATTR short *)q;
*(PTRATTR short *)q = word;
p += 2;
q += 2;
size -= 2;
}
#endif
if( size ) {
byte = *p;
*p = *q;
*q = byte;
}
}
#endif
 
 
FUNCTION_LINKAGE errno_t FUNCTION_NAME( PTRATTR void *in_base,
rsize_t n, rsize_t size,
int (*compar)( const void *, const void *, void * ),
void *context )
/*****************************************************************/
{
PTRATTR char *base = (PTRATTR char*) in_base;
PTRATTR char *p1;
PTRATTR char *p2;
PTRATTR char *pa;
PTRATTR char *pb;
PTRATTR char *pc;
PTRATTR char *pd;
PTRATTR char *pn;
PTRATTR char *pv;
PTRATTR char *mid;
WORD v; /* used in pivot initialization */
WORD t; /* used in exch() macro */
int comparison, swaptype, shell;
size_t count, r, s;
unsigned sp;
auto char *base_stack[MAXDEPTH];
unsigned n_stack[MAXDEPTH];
qcomp *cmp = (qcomp*)compar;
errno_t rc = -1;
 
/* runtime-constraints */
// n <= RSIZE_MAX
// size <= RSIZE_MAX
// if n > 0 then in_base, compar not NULL
if( __check_constraint_maxsize( n ) &&
__check_constraint_maxsize( size ) &&
((n == 0) || __check_constraint_nullptr( in_base ) &&
__check_constraint_nullptr( compar )) ) {
 
if( n == 0 ) { /* empty array - nothing to do */
return( 0 );
}
 
/*
Initialization of the swaptype variable, which determines which
type of swapping should be performed when swap() is called.
0 for single-word swaps, 1 for general swapping by words, and
2 for swapping by bytes. W (it's a macro) = sizeof(WORD).
*/
swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0;
sp = 0;
for( ;; ) {
while( n > 1 ) {
if( n < 16 ) { /* 2-shell sort on smallest arrays */
for( shell = (size * SHELL) ;
shell > 0 ;
shell -= ((SHELL-1) * size) ) {
p1 = base + shell;
for( ; p1 < base + n * size; p1 += shell ) {
for( p2 = p1;
p2 > base && cmp( p2 - shell, p2, context ) > 0;
p2 -= shell ) {
swap( p2, p2 - shell );
}
}
}
break;
} else { /* n >= 16 */
/* Small array (15 < n < 30), mid element */
mid = base + (n >> 1) * size;
if( n > 29 ) {
p1 = base;
p2 = base + ( n - 1 ) * size;
if( n > 42 ) { /* Big array, pseudomedian of 9 */
s = (n >> 3) * size;
p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp, context );
mid = MED3( mid - s, mid, mid + s, cmp, context );
p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp, context );
}
/* Mid-size (29 < n < 43), med of 3 */
mid = MED3( p1, mid, p2, cmp, context );
}
/*
The following sets up the pivot (pv) for partitioning.
It's better to store the pivot value out of line
instead of swapping it to base. However, it's
inconvenient in C unless the element size is fixed.
So, only the important special case of word-size
objects has utilized it.
*/
if( swaptype != 0 ) { /* Not word-size objects */
pv = base;
swap( pv, mid );
} else { /* Storing the pivot out of line (at v) */
pv = (char *)&v;
v = *(WORD *)mid;
}
 
pa = pb = base;
pc = pd = base + ( n - 1 ) * size;
count = n;
/*
count keeps track of how many entries we have
examined. Once we have looked at all the entries
then we know that the partitioning is complete.
We use count to terminate the looping, rather than
a pointer comparison, to handle 16bit pointer
limitations that may lead pb or pc to wrap.
i.e. pc = 0x0000;
pc -= 0x0004;
pc == 0xfffc;
pc is no longer less that 0x0000;
*/
for( ;; ) {
while( count && (comparison = cmp(pb, pv, context )) <= 0 ) {
if( comparison == 0 ) {
swap( pa, pb );
pa += size;
}
pb += size;
count--;
}
while( count && (comparison = cmp(pc, pv, context )) >= 0 ) {
if( comparison == 0 ) {
swap( pc, pd );
pd -= size;
}
pc -= size;
count--;
}
if( !count ) break;
swap( pb, pc );
pb += size;
count--;
if( !count ) break;
pc -= size;
count--;
}
pn = base + n * size;
s = min( pa - base, pb - pa );
if( s > 0 ) {
inline_swap( base, pb - s, s );
}
s = min( pd - pc, pn - pd - size);
if( s > 0 ) {
inline_swap( pb, pn - s, s );
}
/* Now, base to (pb-pa) needs to be sorted */
/* Also, pn-(pd-pc) needs to be sorted */
/* The middle 'chunk' contains all elements=pivot value */
r = pb - pa;
s = pd - pc;
if( s >= r ) { /* Stack up the larger chunk */
base_stack[sp] = pn - s; /* Stack up base */
n_stack[sp] = s / size; /* Stack up n */
n = r / size; /* Set up n for next 'call' */
/* next base is still base */
} else {
if( r <= size ) break;
base_stack[sp] = base; /* Stack up base */
n_stack[sp] = r / size; /* Stack up n */
base = pn - s; /* Set up base and n for */
n = s / size; /* next 'call' */
}
++sp;
}
}
if( sp == 0 ) break;
--sp;
base = base_stack[sp];
n = n_stack[sp];
}
rc = 0;
}
return( rc );
}
/programs/develop/open watcom/trunk/clib/search/qsortrtn.c
0,0 → 1,349
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
/*
* This file is #included by qsort.c.
*/
 
 
/* Support OS/2 16-bit protected mode - will never get stack overflow */
#define MAXDEPTH (sizeof(long) * 8)
 
#define SHELL 3 /* Shell constant used in shell sort */
 
typedef int WORD;
#define W sizeof( WORD )
 
/*
swap() is a macro that chooses between an in_line function call and
an exchange macro.
*/
#define exch( a, b, t) ( t = a, a = b, b = t )
#define swap( a, b ) \
swaptype != 0 ? BYTESWAP( a, b, size ) : \
( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t )
 
/*
Note: The following assembly was timed against several other methods
of doing the same thing. The pragmas here were either fastest on all
machines tested, or fastest on most machines tested. (including an 8088,
386 16mhz, 386 33mhz, and 486 25mhz).
*/
 
#if defined( __386__ )
/* this is intended for 386 only... */
void inline_swap( char *p, char *q, size_t size );
#pragma aux inline_swap = \
0x06 /* push es */ \
0x1e /* push ds */ \
0x07 /* pop es */ \
0x0f 0xb6 0xd1 /* movzx edx,cl */ \
0xc1 0xe9 0x02 /* shr ecx,02H */ \
0x74 0x0b /* je L1 */ \
0x8b 0x07 /*L2 mov eax,[edi] */ \
0x87 0x06 /* xchg eax,[esi] */ \
0xab /* stosd */ \
0x83 0xc6 0x04 /* add esi,0004H */ \
0x49 /* dec ecx */ \
0x75 0xf5 /* jne L2 */ \
0x80 0xe2 0x03 /*L1 and dl,03H */ \
0x74 0x09 /* je L3 */ \
0x8a 0x07 /*L4 mov al,[edi] */ \
0x86 0x06 /* xchg al,[esi] */ \
0xaa /* stosb */ \
0x46 /* inc esi */ \
0x4a /* dec edx */ \
0x75 0xf7 /* jne L4 */ \
/*L3 */ \
0x07 /* pop es */ \
parm caller [esi] [edi] [ecx] \
value \
modify exact [esi edi ecx eax edx];
#pragma aux byteswap parm [esi] [edi] [ecx] \
modify exact [esi edi ecx eax edx];
static void _WCNEAR byteswap( char *p, char *q, size_t size ) {
inline_swap( p, q, size );
}
 
#elif defined( M_I86 ) && defined( __BIG_DATA__ )
void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size );
#pragma aux inline_swap = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xd1 0xe9 /* shr cx,1 */ \
0x74 0x0b /* je L1 */ \
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
0x87 0x04 /* xchg ax,[si] */ \
0xab /* stosw */ \
0x46 /* inc si */ \
0x46 /* inc si */ \
0x49 /* dec cx */ \
0x75 0xf5 /* jne L2 */ \
0x73 0x07 /*L1 jnc L3 */ \
0x8a 0x04 /* mov al,[si] */ \
0x26 0x86 0x05 /* xchg al,es:[di] */ \
0x88 0x04 /* mov [si],al */ \
0x1f /*L3 pop ds */ \
parm caller [dx si] [es di] [cx] \
value \
modify exact [si di cx ax];
#pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax];
static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) {
inline_swap( p, q, size );
}
 
#elif defined( M_I86 ) && defined( __SMALL_DATA__ )
/* we'll ask for char __far *q to save us writing code to load es */
void inline_swap( char *p, char _WCFAR *q, size_t size );
#pragma aux inline_swap = \
0xd1 0xe9 /* shr cx,1 */ \
0x74 0x0b /* je L1 */ \
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
0x87 0x04 /* xchg ax,[si] */ \
0xab /* stosw */ \
0x46 /* inc si */ \
0x46 /* inc si */ \
0x49 /* dec cx */ \
0x75 0xf5 /* jne L2 */ \
0x73 0x07 /*L1 jnc L3 */ \
0x8a 0x04 /* mov al,[si] */ \
0x26 0x86 0x05 /* xchg al,es:[di] */ \
0x88 0x04 /* mov [si],al */ \
/*L3 */ \
parm caller [si] [es di] [cx] \
value \
modify exact [si di cx ax];
#pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax];
static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) {
inline_swap( p, q, size );
}
 
#else
/* this is an optimized version of a simple byteswap */
#define inline_swap BYTESWAP
static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) {
long dword;
short word;
char byte;
 
#if 1 /* this is for 32 bit machines */
while( size > 3 ) {
dword = *(PTRATTR long *)p;
*(PTRATTR long *)p = *(PTRATTR long *)q;
*(PTRATTR long *)q = dword;
p += 4;
q += 4;
size -= 4;
}
if( size > 1 ) {
word = *(PTRATTR short *)p;
*(PTRATTR short *)p = *(PTRATTR short *)q;
*(PTRATTR short *)q = word;
p += 2;
q += 2;
size -= 2;
}
#else /* this is for 16 bit machines */
while( size > 1 ) {
word = *(PTRATTR short *)p;
*(PTRATTR short *)p = *(PTRATTR short *)q;
*(PTRATTR short *)q = word;
p += 2;
q += 2;
size -= 2;
}
#endif
if( size ) {
byte = *p;
*p = *q;
*q = byte;
}
}
#endif
 
 
FUNCTION_LINKAGE void FUNCTION_NAME(
PTRATTR void *in_base, size_t n,
size_t size,
int (*compar)(const void *, const void *)
)
/**********************************************************************/
{
PTRATTR char * base = (PTRATTR char*) in_base;
PTRATTR char * p1;
PTRATTR char * p2;
PTRATTR char * pa;
PTRATTR char * pb;
PTRATTR char * pc;
PTRATTR char * pd;
PTRATTR char * pn;
PTRATTR char * pv;
PTRATTR char * mid;
WORD v; /* used in pivot initialization */
WORD t; /* used in exch() macro */
int comparison, swaptype, shell;
size_t count, r, s;
unsigned int sp;
auto char * base_stack[MAXDEPTH];
auto unsigned int n_stack[MAXDEPTH];
qcomp * cmp = (qcomp*) compar;
 
/*
Initialization of the swaptype variable, which determines which
type of swapping should be performed when swap() is called.
0 for single-word swaps, 1 for general swapping by words, and
2 for swapping by bytes. W (it's a macro) = sizeof(WORD).
*/
swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0;
sp = 0;
for(;;) {
while( n > 1 ) {
if( n < 16 ) { /* 2-shell sort on smallest arrays */
for( shell = (size * SHELL) ;
shell > 0 ;
shell -= ((SHELL-1) * size) ) {
p1 = base + shell;
for( ; p1 < base + n * size; p1 += shell ) {
for( p2 = p1;
p2 > base && cmp( p2 - shell, p2 ) > 0;
p2 -= shell ) {
swap( p2, p2 - shell );
}
}
}
break;
} else { /* n >= 16 */
/* Small array (15 < n < 30), mid element */
mid = base + (n >> 1) * size;
if( n > 29 ) {
p1 = base;
p2 = base + ( n - 1 ) * size;
if( n > 42 ) { /* Big array, pseudomedian of 9 */
s = (n >> 3) * size;
p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp );
mid = MED3( mid - s, mid, mid + s, cmp );
p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp );
}
/* Mid-size (29 < n < 43), med of 3 */
mid = MED3( p1, mid, p2, cmp );
}
/*
The following sets up the pivot (pv) for partitioning.
It's better to store the pivot value out of line
instead of swapping it to base. However, it's
inconvenient in C unless the element size is fixed.
So, only the important special case of word-size
objects has utilized it.
*/
if( swaptype != 0 ) { /* Not word-size objects */
pv = base;
swap( pv, mid );
} else { /* Storing the pivot out of line (at v) */
pv = ( char* )&v;
v = *( WORD* )mid;
}
 
pa = pb = base;
pc = pd = base + ( n - 1 ) * size;
count = n;
/*
count keeps track of how many entries we have
examined. Once we have looked at all the entries
then we know that the partitioning is complete.
We use count to terminate the looping, rather than
a pointer comparison, to handle 16bit pointer
limitations that may lead pb or pc to wrap.
i.e. pc = 0x0000;
pc -= 0x0004;
pc == 0xfffc;
pc is no longer less that 0x0000;
*/
for(;;) {
while(count && (comparison = cmp(pb, pv)) <= 0) {
if( comparison == 0 ) {
swap( pa, pb );
pa += size;
}
pb += size;
count--;
}
while(count && (comparison = cmp(pc, pv)) >= 0) {
if( comparison == 0 ) {
swap( pc, pd );
pd -= size;
}
pc -= size;
count--;
}
if( !count ) break;
swap( pb, pc );
pb += size;
count--;
if( !count ) break;
pc -= size;
count--;
}
pn = base + n * size;
s = min( pa - base, pb - pa );
if( s > 0 ) {
inline_swap( base, pb - s, s );
}
s = min( pd - pc, pn - pd - size);
if( s > 0 ) {
inline_swap( pb, pn - s, s );
}
/* Now, base to (pb-pa) needs to be sorted */
/* Also, pn-(pd-pc) needs to be sorted */
/* The middle 'chunk' contains all elements=pivot value*/
r = pb - pa;
s = pd - pc;
if( s >= r ) { /* Stack up the larger chunk */
base_stack[sp] = pn - s;/* Stack up base */
n_stack[sp] = s / size; /* Stack up n */
n = r / size; /* Set up n for next 'call'*/
/* next base is still base */
} else {
if( r <= size ) break;
base_stack[sp] = base; /* Stack up base */
n_stack[sp] = r / size; /* Stack up n */
base = pn - s; /* Set up base and n for */
n = s / size; /* next 'call' */
}
++sp;
}
}
if( sp == 0 ) break;
--sp;
base = base_stack[sp];
n = n_stack[sp];
}
}
/programs/develop/open watcom/trunk/clib/src/grownear.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strncpy.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nmemneed.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nheapwal.c
File deleted
/programs/develop/open watcom/trunk/clib/src/freect.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nheapmin.c
File deleted
/programs/develop/open watcom/trunk/clib/src/calloc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strcat.c
File deleted
/programs/develop/open watcom/trunk/clib/src/memmove.c
File deleted
/programs/develop/open watcom/trunk/clib/src/sscanf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strchr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/i8m386.asm
File deleted
/programs/develop/open watcom/trunk/clib/src/strcpy.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strupr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nexpand.c
File deleted
/programs/develop/open watcom/trunk/clib/src/i8rs386.asm
File deleted
/programs/develop/open watcom/trunk/clib/src/nrealloc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strnicmp.c
File deleted
/programs/develop/open watcom/trunk/clib/src/mem.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ambsptr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/heapgrow.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strncmp.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nheapset.c
File deleted
/programs/develop/open watcom/trunk/clib/src/heapen.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nheapchk.c
File deleted
/programs/develop/open watcom/trunk/clib/src/memmax.c
File deleted
/programs/develop/open watcom/trunk/clib/src/memset.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strlen.c
File deleted
/programs/develop/open watcom/trunk/clib/src/memcpy.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strrchr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/memavl.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nmsize.c
File deleted
/programs/develop/open watcom/trunk/clib/src/nfree.c
File deleted
/programs/develop/open watcom/trunk/clib/src/amblksiz.c
File deleted
/programs/develop/open watcom/trunk/clib/src/sprintf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/heapacc.h
File deleted
/programs/develop/open watcom/trunk/clib/src/sbrkwnt.c
File deleted
/programs/develop/open watcom/trunk/clib/src/heap.h
File deleted
/programs/develop/open watcom/trunk/clib/src/bufld386.asm
File deleted
/programs/develop/open watcom/trunk/clib/src/nmalloc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ncalloc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/fstatus.inc
0,0 → 1,47
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
 
 
FPE_OK equ 0
FPE_INVALID equ 81h
FPE_DENORMAL equ 82h
FPE_ZERODIVIDE equ 83h
FPE_OVERFLOW equ 84h
FPE_UNDERFLOW equ 85h
FPE_INEXACT equ 86h
FPE_UNEMULATED equ 87h
FPE_SQRTNEG equ 88h
FPE_STACKOVERFLOW equ 8ah
FPE_STACKUNDERFLOW equ 8bh
FPE_EXPLICITGEN equ 8ch
FPE_IOVERFLOW equ 8dh
FPE_LOGERR equ 8eh
FPE_MODERR equ 8fh
/programs/develop/open watcom/trunk/clib/src/saferlib.h
0,0 → 1,103
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Internal data and routines for "Safer C", or bounds-checking
* library extension.
*
****************************************************************************/
 
 
#ifndef _SAFERLIB_H_INCLUDED
#define _SAFERLIB_H_INCLUDED
 
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
#include <stdint.h>
 
// Maximum length of runtime-constraint error message
#define RTCT_MSG_MAX 128
 
#define _RWD_rtcthandler __runtime_constraint_handler
 
extern constraint_handler_t __runtime_constraint_handler;
 
extern void __rtct_fail( const char *fn, const char *reason, void *reserved );
 
// Runtime-constraint validation macros. Call the handler and return zero if check
// failed, return non-zero value if check succeeded.
 
#define __check_constraint_nullptr( arg ) \
((arg == NULL) ? __rtct_fail( __func__, #arg " == NULL", NULL ), 0 : 1)
 
#define __check_constraint_maxsize( arg ) \
((arg > RSIZE_MAX) ? __rtct_fail( __func__, #arg " > RSIZE_MAX", NULL ), 0 : 1)
 
#define __check_constraint_zero( arg ) \
((arg == 0) ? __rtct_fail( __func__, #arg " == 0", NULL ), 0 : 1)
 
#define __check_constraint_toosmall( name, left ) \
((left == 0) ? __rtct_fail( __func__, #name " is too small to hold data", NULL ), 0 : 1)
 
 
// Runtime-constraint validation macros. Construct the message and return
// zero if check failed, return non-zero value if check succeeded.
// __rtct_fail has to be explicitly called later.
 
#define __check_constraint_nullptr_msg( msg, arg ) \
((arg == NULL) ? ( msg = #arg " == NULL" ), 0 : 1)
 
#define __check_constraint_maxsize_msg( msg, arg ) \
((arg > RSIZE_MAX) ? ( msg = #arg " > RSIZE_MAX" ), 0 : 1)
 
#define __check_constraint_zero_msg( msg, arg ) \
((arg == 0) ? ( msg = #arg " == 0" ), 0 : 1)
 
#define __check_constraint_toosmall_msg( msg, name, left ) \
((left == 0) ? ( msg = #name " is too small to hold data" ), 0 : 1)
 
#define __check_constraint_a_gt_b_msg( msg, a, b ) \
((a > b) ? ( msg = #a " > " #b ), 0 : 1)
 
#define __check_constraint_overlap_msg( msg, p1, len1, p2, len2 ) \
(((p1 == p2) || ( (p1 > p2) && ( p1 < (CHAR_TYPE *)p2 + len2 * sizeof( CHAR_TYPE ))) \
|| ( (p2 > p1) && ( p2 < (CHAR_TYPE *)p1 + len1 * sizeof( CHAR_TYPE )))) \
? ( msg = #p1 " overlap " #p2 ), 0 : 1)
 
 
// For 16-bit targets, the RSIZE_MAX check is effectively no-op. Object sizes
// up to SIZE_MAX are legal and not uncommon.
#if RSIZE_MAX == SIZE_MAX
#undef __check_constraint_maxsize
#define __check_constraint_maxsize( arg ) 1
#undef __check_constraint_maxsize_msg
#define __check_constraint_maxsize_msg( msg, arg ) 1
 
#define __lte_rsizmax( arg ) 1
#else
#define __lte_rsizmax( arg ) (arg <= RSIZE_MAX)
#endif
 
#endif // _SAFERLIB_H_INCLUDED
/programs/develop/open watcom/trunk/clib/src/strdup.h
0,0 → 1,41
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#ifndef __STRDUP_H_INCLUDED
#define __STRDUP_H_INCLUDED
 
#include "variety.h"
#include "widechar.h"
 
_WCRTLINK extern char *__clib_strdup( const char *str );
_WCRTLINK extern wchar_t *__clib_wcsdup( const wchar_t *str );
#endif
/programs/develop/open watcom/trunk/clib/string/bits.c
0,0 → 1,48
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
#include "setbits.h"
 
const unsigned char _HUGEDATA _Bits[] =
{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
 
void __setbits( unsigned char vector[32], const char *charset )
{
unsigned char c;
 
memset( vector, 0, 32 );
for( ; c = *charset; ++charset ) {
vector[ c >> 3 ] |= _Bits[ c & 0x07 ];
}
}
/programs/develop/open watcom/trunk/clib/string/bprintf.c
0,0 → 1,139
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: This module supports formatted output to a character buffer.
* Both character and wide character formatting are included.
* For added library granularity, this module could be split
* into two, with "bprintf" functions in one file and the
* "snprintf" functions in another.
*
* C library functions:
* _bprintf, _vbprintf
* _bwprintf, _vbwprintf
* _snprintf, _snwprintf
* _vsnprintf, _vsnwprintf
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include "printf.h"
 
struct buf_limit {
CHAR_TYPE *bufptr;
size_t bufsize;
int bufover;
};
 
/*
* buf_putc -- append a character to a string in memory
*/
static slib_callback_t buf_putc; // setup calling convention
static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char )
{
struct buf_limit *bufinfo;
bufinfo = (struct buf_limit *)specs->_dest;
if( specs->_output_count < bufinfo->bufsize ) {
*( bufinfo->bufptr++ ) = op_char;
specs->_output_count++;
} else {
bufinfo->bufover = -1;
}
}
 
_WCRTLINK int __F_NAME(_vbprintf,_vbwprintf) ( CHAR_TYPE *s, size_t bufsize,
const CHAR_TYPE *format, va_list arg)
{
register int len;
auto struct buf_limit bufinfo;
slib_callback_t *tmp;
 
bufinfo.bufptr = s;
bufinfo.bufsize = bufsize - 1;
bufinfo.bufover = 0;
#if defined( __386__ ) && defined( __QNX__ )
/* avoid some segment relocations for 32-bit QNX */
tmp = (void (*)())buf_putc;
#else
tmp = buf_putc;
#endif
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp );
s[len] = '\0';
return( len );
}
 
_WCRTLINK int __F_NAME(_bprintf,_bwprintf) ( CHAR_TYPE *dest, size_t bufsize,
const CHAR_TYPE *format, ... )
{
auto va_list args;
 
va_start( args, format );
return( __F_NAME(_vbprintf,_vbwprintf)( dest, bufsize, format, args ) );
}
 
// Notes:
// _vsnprintf, _vsnwprintf must return an error (-1) when buffer too small
// If a NULL character can fit, append it. If not, no error.
 
_WCRTLINK int __F_NAME(_vsnprintf,_vsnwprintf) ( CHAR_TYPE *s, size_t bufsize,
const CHAR_TYPE *format, va_list arg)
{
register int len;
auto struct buf_limit bufinfo;
slib_callback_t *tmp;
 
bufinfo.bufptr = s;
bufinfo.bufsize = bufsize;
bufinfo.bufover = 0;
#if defined( __386__ ) && defined( __QNX__ )
/* avoid some segment relocations for 32-bit QNX */
tmp = (void (*)())buf_putc;
#else
tmp = buf_putc;
#endif
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp );
if( len < bufsize ) {
s[len] = '\0';
}
if( bufinfo.bufover == 0 ) {
return( len );
} else {
return( -1 );
}
}
 
_WCRTLINK int __F_NAME(_snprintf,_snwprintf) ( CHAR_TYPE *dest, size_t bufsize,
const CHAR_TYPE *format, ... )
{
auto va_list args;
 
va_start( args, format );
return( __F_NAME(_vsnprintf,_vsnwprintf)( dest, bufsize, format, args ) );
}
/programs/develop/open watcom/trunk/clib/string/cmp386.asm
0,0 → 1,213
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: Intel 386 implementation strcmp().
;*
;*****************************************************************************
 
 
include mdef.inc
include struct.inc
 
ifdef _PROFILE
include p5prof.inc
endif
 
modstart _strcmp,para
 
cmp4 macro off
mov ebx,off[eax] ; get dword from op1
mov ecx,off[edx] ; get dword from op2
cmp ecx,ebx ; compare them
jne unequal ; quit if not equal
ife off-12
add eax,off+4 ; point to next group of dwords
add edx,off+4 ; ...
endif
not ecx ; ...
add ebx,0FEFEFEFFh ; determine if '\0' is one of bytes
and ebx,ecx ; ...
and ebx,80808080h ; ebx will be non-zero if '\0' found
endm
 
defpe strcmp
xdefp "C",strcmp
ifdef _PROFILE
P5Prolog
endif
ifdef __STACK__
mov eax,4[esp] ; get p1
mov edx,8[esp] ; get p2
endif
cmp eax,edx ; pointers equal ?
je equalnorst ; yes, return 0
ifndef __STACK__
push ecx ; save register
endif
test al,3 ; p1 aligned ?
jne realign ; no, go and realign
test dl,3 ; p2 aligned ?
jne slowcpy ; no, do the slow copy (impossible to align both)
 
fastcpy:
push ebx ; save register
 
align 4
_loop ; - loop
cmp4 0 ; - - compare first dword
_quif ne ; - - quit if end of string
cmp4 4 ; - - compare second dword
_quif ne ; - - quit if end of string
cmp4 8 ; - - compare third dword
_quif ne ; - - quit if end of string
cmp4 12 ; - - compare fourth dword
_until ne ; - until end of string
equalrst: ; strings equal, restore registers
pop ebx ; restore register
ifndef __STACK__
pop ecx ; ...
endif
equalnorst: ; strings equal, skip register restore
sub eax,eax ; indicate strings equal
ifdef _PROFILE
P5Epilog
endif
ret ; return
 
unequal: ; dword was not equal
_guess ; guess strings are equal
cmp bl,cl ; - check low bytes
_quif ne ; - quit if not equal
cmp bl,0 ; - stop if end of string
je equalrst ; - ...
cmp bh,ch ; - check next bytes
_quif ne ; - quit if not equal
cmp bh,0 ; - stop if end of string
je equalrst ; - ...
shr ebx,16 ; - shift top 2 bytes to bottom
shr ecx,16 ; - ...
cmp bl,cl ; - check third byte
_quif ne ; - quit if not equal
cmp bl,0 ; - stop if end of string
je equalrst ; - ...
cmp bh,ch ; - check high order byte
;; we know at this point that bh != ch, just have to do the compare
;; _quif ne ; - quit if not equal
;; cmp bh,0 ; - stop if end of string
;; je equalrst ; - ...
_endguess ; endguess
sbb eax,eax ; eax = 0 if op1>op2, -1 if op1<op2
or al,1 ; eax = 1 if op1>op2, -1 if op1<op2
pop ebx ; restore registers
ifndef __STACK__
pop ecx ; ...
endif
ifdef _PROFILE
P5Epilog
endif
ret ; return
 
align 4
realign:
_loop ; - loop
mov cl,[eax] ; get byte from p1
inc eax ; point to next byte
mov ch,[edx] ; get byte from p2
inc edx ; point to next byte
cmp cl,ch ; bytes equal?
jne unequal2 ; unequal, quit
or cl,cl ; end of string ?
je equal2 ; yes, quit
test al,3 ; check alignment
_until e ; until aligned
test dl,3 ; p2 aligned ?
je fastcpy ; yes
 
align 4
slowcpy:
_loop
mov ecx,[eax] ; get aligned 4 bytes
cmp cl,[edx] ; check 1st byte
jne unequal2 ; bytes not equal
or cl,cl ; end of string?
je equal2 ; yes, quit
cmp ch,[edx+1] ; check 2nd byte
jne unequal2 ; bytes not equal
or ch,ch ; end of string?
je equal2 ; yes, quit
shr ecx,16 ; move next pair of bytes to be tested
cmp cl,[edx+2] ; check 3rd byte
jne unequal2 ; bytes not equal
or cl,cl ; end of string?
je equal2 ; yes, quit
cmp ch,[edx+3] ; check 4th byte
jne unequal2 ; bytes not equal
or ch,ch ; end of string?
je equal2 ; yes, quit
mov ecx,[eax+4] ; get next aligned 4 bytes
cmp cl,[edx+4] ; check 5th byte
jne unequal2 ; bytes not equal
or cl,cl ; end of string?
je equal2 ; yes, quit
cmp ch,[edx+5] ; check 6th byte
jne unequal2 ; bytes not equal
or ch,ch ; end of string?
je equal2 ; yes, quit
shr ecx,16 ; move next pair of bytes to be tested
cmp cl,[edx+6] ; check 7th byte
jne unequal2 ; bytes not equal
or cl,cl ; end of string?
je equal2 ; yes, quit
cmp ch,[edx+7] ; check 8th byte
jne unequal2 ; bytes not equal
add eax,8 ; next 8 bytes
add edx,8 ; next 8 bytes
or ch,ch ; end of string?
_until e ; until equal
equal2:
xor eax,eax ; return 0
ifndef __STACK__
pop ecx ; restore registers
endif
ifdef _PROFILE
P5Epilog
endif
ret ; return
 
unequal2:
sbb eax,eax ; eax = 0 if op1>op2, -1 if op1<op2
or al,1 ; eax = 1 if op1>op2, -1 if op1<op2
ifndef __STACK__
pop ecx ; restore registers
endif
ifdef _PROFILE
P5Epilog
endif
ret ; return
endproc strcmp
 
endmod
end
/programs/develop/open watcom/trunk/clib/string/errstr.h
0,0 → 1,46
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Internal definitions for strerror() and friends.
*
****************************************************************************/
 
 
#if defined(__NETWARE__) || defined(__WIDECHAR__)
 
extern int _WCNEAR sys_nerr;
extern char *sys_errlist[];
#define _sys_nerr sys_nerr
#define _sys_errlist sys_errlist
 
#else
 
extern char *_sys_errlist[];
extern int _WCNEAR _sys_nerr;
 
#endif
 
#define UNKNOWN_ERROR "unknown error"
/programs/develop/open watcom/trunk/clib/string/fsetbits.c
0,0 → 1,45
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
#include "setbits.h"
 
void __fsetbits( unsigned char _WCFAR *vector, const char _WCFAR *charset )
{
unsigned char c;
 
_fmemset( vector, 0, 32 );
for( ; c = *charset; ++charset ) {
vector[ c >> 3 ] |= _Bits[ c & 0x07 ];
}
}
/programs/develop/open watcom/trunk/clib/string/fstrcat.c
0,0 → 1,51
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdio.h>
#include "xstring.h"
 
#undef _fstrcat
/* concatenate t to the end of dst */
 
_WCRTLINK char _WCFAR *_fstrcat( char _WCFAR *dst, const char _WCFAR *t )
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fstrcat( dst, t ) );
#else
char _WCFAR *s;
s = dst;
while( *s != '\0' ) ++s;
while( *s++ = *t++ ) ;
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrchr.c
0,0 → 1,91
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern char _WCFAR * _scan1( char _WCFAR *s, int c );
 
/* use scan1 to find the char we are looking for */
 
#pragma aux _scan1 = 0x1e /* push ds */\
0x8e 0xda /* mov ds,dx */\
0xad /* L1:lodsw */\
0x38 0xd8 /* cmp al,bl */\
0x74 0x22 /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x19 /* je L2 */\
0x38 0xdc /* cmp ah,bl */\
0x74 0x1b /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x74 0x11 /* je L2 */\
0xad /* lodsw */\
0x38 0xd8 /* cmp al,bl */\
0x74 0x11 /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x08 /* je L2 */\
0x38 0xdc /* cmp ah,bl */\
0x74 0x0a /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x75 0xde /* jne L1 */\
0x31 0xf6 /* L2:xor si,si*/\
0x89 0xf2 /* mov dx,si */\
0xa9 /* test ax,... */\
0x4e /* L3:dec si */\
0x4e /* L4:dec si */\
0x1f /* pop ds */\
parm caller [dx si] [bl]\
value [dx si]\
modify [ax dx si];
#endif
 
 
/* locate the first occurrence of c in the initial n characters of the
string pointed to by s. The terminating null character is considered
to be part of the string.
If the character c is not found, NULL is returned.
*/
#undef _fstrchr
 
_WCRTLINK char _WCFAR *_fstrchr( const char _WCFAR *s, int c )
{
//#if defined(M_I86)
//return( _scan1( (char _WCFAR *)s, c ) );
//#else
do {
if( *s == c ) return( (char _WCFAR *)s );
} while( *s++ != '\0' );
return( NULL );
//#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrcmp.c
0,0 → 1,50
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "xstring.h"
 
#undef _fstrcmp
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
_WCRTLINK int _fstrcmp( const char _WCFAR *s, const char _WCFAR *t )
{
#if /*defined(M_I86) &&*/ defined(__INLINE_FUNCTIONS__)
return( _inline__fstrcmp( s, t ) );
#else
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return( 0 );
return( *s - *t );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrcpy.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "xstring.h"
 
#undef _fstrcpy
/* copy string t to string s */
 
_WCRTLINK char _WCFAR *_fstrcpy( char _WCFAR *s, const char _WCFAR *t )
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fstrcpy( s, t ) );
#else
char _WCFAR *dst;
dst = s;
while( *dst++ = *t++ );
return( s );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrcspn.c
0,0 → 1,57
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <string.h>
#include "setbits.h"
 
/* The strcspn function computes the length of the initial segment of the
string pointed to by str which consists entirely of characters not from
the string pointed to by charset. The terminating NULL character is not
considered part of charset.
*/
 
_WCRTLINK size_t _fstrcspn( const char _WCFAR *str, const char _WCFAR *charset )
{
unsigned /*char*/ tc;
unsigned char vector[32];
size_t len;
 
__fsetbits( vector, charset );
len = 0;
for( ; tc = (unsigned char) *str; ++len, ++str ) {
/* quit if we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) break;
}
return( len );
}
/programs/develop/open watcom/trunk/clib/string/fstrdup.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
#include "liballoc.h"
 
_WCRTLINK char _WCFAR *_fstrdup( const char _WCFAR *str )
{
char _WCFAR *mem;
int len;
 
len = _fstrlen( str ) + 1;
mem = lib_malloc( len );
if( mem ) {
(_fmemcpy)( mem, str, len );
}
return( mem );
}
/programs/develop/open watcom/trunk/clib/string/fstricmp.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
_WCRTLINK int _fstricmp( const char _WCFAR *s, const char _WCFAR *t )
{
unsigned char c1;
unsigned char c2;
 
for(;;) {
c1 = *s;
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
c2 = *t;
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
if( c1 != c2 ) break;
if( c1 == '\0' ) break;
++s;
++t;
}
return( c1 - c2 );
}
/programs/develop/open watcom/trunk/clib/string/fstrlen.c
0,0 → 1,49
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of _fstrlen().
*
****************************************************************************/
 
 
#include "variety.h"
#include "xstring.h"
 
#undef _fstrlen
 
_WCRTLINK size_t _fstrlen( const char _WCFAR *s ) /* return length of string s */
{
#if defined(__INLINE_FUNCTIONS__)
return( _inline__fstrlen( s ) );
#else
const char _WCFAR *p;
 
p = s;
while( *p != '\0' )
++p;
return( p - s );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrlwr.c
0,0 → 1,52
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
 
_WCRTLINK char _WCFAR *_fstrlwr( char _WCFAR *str )
{
char _WCFAR *p;
unsigned char c;
 
p = str;
while( c = *p ) {
c -= 'A';
if( c <= 'Z' - 'A' ) {
c += 'a';
*p = c;
}
++p;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/fstrncat.c
0,0 → 1,86
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern char _WCFAR *_fast_strncat( char _WCFAR *, const char _WCFAR *, size_t );
 
#pragma aux _fast_strncat = \
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0x57 /* push di */\
0xb9 0xff 0xff /* mov cx,ffffh */\
0x31 0xc0 /* xor ax,ax */\
0xf2 0xae /* repne scasb */\
0x4f /* dec di */\
0x89 0xd1 /* mov cx,dx */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x74 0x03 /* je L2 */\
0x26 0x88 0x25 /* mov es:[di],ah */\
0x58 /* L2: pop ax */\
0x1f /* pop ds */\
parm caller [es di] [si ax] [dx]\
value [es ax] \
modify exact [ax cx si di];
#endif
 
/* concatenate t to the end of dst */
 
_WCRTLINK char _WCFAR *_fstrncat( char _WCFAR *dst, const char _WCFAR *t, size_t n )
{
#ifdef M_I86
if( n ) {
return( _fast_strncat( dst, t, n ) );
}
return( dst );
#else
char _WCFAR *s;
 
s = _fmemchr( dst, '\0', ~0 );
while( n != 0 ) {
*s = *t;
if( *s == '\0' ) break;
++s;
++t;
--n;
}
*s = '\0';
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrncmp.c
0,0 → 1,80
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern int _fast_strncmp( const char _WCFAR *, const char _WCFAR *, size_t );
 
#pragma aux _fast_strncmp = \
0x1e /* push ds */ \
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0x89 0xfa /* mov dx,di */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0x89 0xf9 /* mov cx,di */ \
0x89 0xd7 /* mov di,dx */ \
0x29 0xf9 /* sub cx,di */ \
0xf3 0xa6 /* repe cmpsb */ \
0x74 0x05 /* je L1 */ \
0x19 0xc9 /* sbb cx,cx */ \
0x83 0xd9 0xff /* sbb cx,ffffh */ \
/* L1: */ \
0x1f /* pop ds */\
parm caller [si ax] [es di] [cx] \
value [cx] \
modify exact [dx ax di cx si];
#endif
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
_WCRTLINK int _fstrncmp( const char _WCFAR *s, const char _WCFAR *t, size_t n )
{
#if defined(M_I86)
if( n ) {
return( _fast_strncmp( s, t, n ) );
}
return( 0 );
#else
for(;;) {
if( n == 0 ) return( 0 ); /* equal */
if( *s != *t ) return( *s - *t ); /* less than or greater than */
if( *s == '\0' ) return( 0 ); /* equal */
++s;
++t;
--n;
}
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrncpy.c
0,0 → 1,82
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern char _WCFAR *fast_strncpy( char _WCFAR *, const char _WCFAR *, size_t );
 
#pragma aux fast_strncpy = \
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0x57 /* push di */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x31 0xc0 /* xor ax,ax */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xab /* rep stosw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xaa /* rep stosb */\
0x58 /* pop ax */\
0x1f /* pop ds */\
parm caller [es di] [si ax] [cx]\
value [es ax] \
modify exact [ax cx si di];
#endif
 
_WCRTLINK char _WCFAR *_fstrncpy( char _WCFAR *dst, const char _WCFAR *src, size_t len )
{
#ifdef M_I86
if( len ) {
return( fast_strncpy( dst, src, len ) );
}
return( dst );
#else
char _WCFAR *ret;
 
ret = dst;
for(;len; --len ) {
if( *src == '\0' ) break;
*dst++ = *src++;
}
while( len != 0 ) {
*dst++ = '\0'; /* pad destination string with null chars */
--len;
}
return( ret );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrnicm.c
0,0 → 1,56
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
_WCRTLINK int _fstrnicmp( const char _WCFAR *s, const char _WCFAR *t, size_t n )
{
unsigned char c1;
unsigned char c2;
 
for(;;) {
if( n == 0 ) return( 0 ); /* equal */
c1 = *s;
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
c2 = *t;
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
if( c1 != c2 ) return( c1 - c2 ); /* less than or greater than */
if( c1 == '\0' ) return( 0 ); /* equal */
++s;
++t;
--n;
}
}
/programs/develop/open watcom/trunk/clib/string/fstrnset.c
0,0 → 1,45
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
_WCRTLINK char _WCFAR *_fstrnset( char _WCFAR *str, int c, size_t len )
{
char _WCFAR *p;
 
for( p = str; len; --len ) {
if( *p == '\0' ) break;
*p++ = c;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/fstrpbrk.c
0,0 → 1,54
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <string.h>
#include "setbits.h"
 
/* The strpbrk function locates the first occurrence in the string pointed
to by str of any character from the string pointed to by charset.
*/
 
_WCRTLINK char _WCFAR *_fstrpbrk( const char _WCFAR *str, const char _WCFAR *charset )
{
unsigned char tc;
unsigned char vector[32];
 
__fsetbits( vector, charset );
for( ; tc = *str; ++str ) {
/* quit when we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 )
return( (char _WCFAR *)str );
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/string/fstrrchr.c
0,0 → 1,78
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern char _WCFAR *_fast_strrchr( const char _WCFAR *, char );
 
#pragma aux _fast_strrchr = \
0xb9 0xff 0xff /* mov cx,ffffh */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0xf7 0xd1 /* not cx */ \
0x4f /* dec di */ \
0x88 0xd8 /* mov al,bl */ \
0xfd /* std */ \
0xf2 0xae /* repne scasb */ \
0xfc /* cld */ \
0x75 0x04 /* jne L1 */ \
0x89 0xf9 /* mov cx,di */ \
0x41 /* inc cx */ \
0xa9 /* hide 2 bytes */ \
0x8e 0xc1 /* L1: mov es,cx */ \
parm caller [es di] [bl] \
value [es cx] \
modify exact [es cx ax di];
#endif
 
/* Locate the last occurrence of c in the string pointed to by s.
The terminating null character is considered to be part of the string.
If the character c is not found, NULL is returned.
*/
 
_WCRTLINK char _WCFAR *_fstrrchr( const char _WCFAR *s, int c )
{
#if defined(M_I86)
return( _fast_strrchr( s, c ) );
#else
char _WCFAR *p;
 
p = NULL; /* assume c will not be found */
do {
if( *s == c ) p = (char _WCFAR *)s;
} while( *s++ != '\0' );
return( p );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrrev.c
0,0 → 1,121
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
 
#ifdef M_I86
 
/*
explanation of algorithm:
 
(1) reverse as much of the string as possible as words
 
(2) after main loop: reverse residual inner string (0-3 bytes)
 
the string falls into one of these forms:
 
{ prefix_word }* { suffix_word }*
{ prefix_word }* middle_byte { suffix_word }*
{ prefix_word }* pre_middle_byte post_middle_byte { suffix_word }*
{ prefix_word }* pre_middle_byte middle_byte post_middle_byte { suffix_word }*
 
we only have to swap two bytes when:
 
len & 2 != 0 is true (ie. the carry is set after second shr cx,1)
 
*****************************************************************************
WARNING: the code in the L1: ... reverse loop cannot modify the carry flag
*****************************************************************************
*/
 
extern void fast_rev( char _WCFAR * );
 
#pragma aux fast_rev = \
0x1e /* push ds */\
0x8e 0xc1 /* mov es,cx */\
0x8e 0xd9 /* mov ds,cx */\
0x89 0xfe /* mov si,di */\
0xb9 0xff 0xff /* mov cx,ffff */\
0x30 0xc0 /* xor al,al */\
0xf2 0xae /* repne scasb */\
0xf7 0xd1 /* not cx */\
0x49 /* dec cx */\
0xfd /* std */\
0x83 0xef 0x03 /* sub di,3 */\
0xd1 0xe9 /* shr cx,1 */\
0xd1 0xe9 /* shr cx,1 */\
0xe3 0x0d /* jcxz L2 */\
0x8b 0x05 /* L1:mov ax,[di] */\
0x86 0xe0 /* xchg ah,al */\
0x87 0x04 /* xchg ax,[si] */\
0x86 0xe0 /* xchg ah,al */\
0xab /* stosw */\
0x46 /* inc si */\
0x46 /* inc si */\
0xe2 0xf3 /* loop L1 */\
0x73 0x07 /* L2:jnc L3 */\
0x47 /* inc di */\
0x8a 0x05 /* mov al,[di] */\
0x86 0x04 /* xchg al,[si] */\
0x88 0x05 /* mov [di],al */\
0xfc /* L3:cld */\
0x1f /* pop ds */\
parm caller [cx di] \
modify [si cx ax di es];
#endif
 
_WCRTLINK char _WCFAR *_fstrrev( char _WCFAR *str ) /* reverse characters in string */
{
#if defined(M_I86)
fast_rev( str );
return( str );
#else
char _WCFAR *p1;
char _WCFAR *p2;
char c1;
char c2;
 
p1 = str;
p2 = p1 + _fstrlen( p1 ) - 1;
while( p1 < p2 ) {
c1 = *p1;
c2 = *p2;
*p1 = c2;
*p2 = c1;
++p1;
--p2;
}
return( str );
#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrset.c
0,0 → 1,75
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
#ifdef M_I86
 
extern char _WCFAR *fast_strset( char _WCFAR *, char );
 
#pragma aux fast_strset = \
0x1e /* push ds */\
0x56 /* push si */\
0x50 /* push ax */\
0x8e 0xda /* mov ds,dx */\
0x89 0xc6 /* mov si,ax */\
0x88 0xdf /* mov bh,bl */\
0xad /* L1:lodsw */\
0x84 0xc0 /* test al,al */\
0x74 0x0c /* je L3 */\
0x84 0xe4 /* test ah,ah */\
0x74 0x05 /* je L2 */\
0x89 0x5c 0xfe /* mov -2[si],bx */\
0xeb 0xf2 /* jmp L1 */\
0x88 0x5c 0xfe /* L2:mov -2[si],bl */\
0x58 /* L3:pop ax */\
0x5e /* pop si */\
0x1f /* pop ds */\
parm caller [dx ax] [bl] \
value [dx ax] \
modify exact [bh];
#endif
 
_WCRTLINK char _WCFAR *_fstrset( char _WCFAR *s, int c )
{
//#ifdef M_I86
//return( fast_strset( s, c ) );
//#else
char _WCFAR *p;
 
for( p = s; *p; ++p ) {
*p = c;
}
return( s );
//#endif
}
/programs/develop/open watcom/trunk/clib/string/fstrspn.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
#include "setbits.h"
 
/* The strspn function computes the length of the initial segment of the
string pointed to by str which consists entirely of characters from
the string pointed to by charset.
*/
 
_WCRTLINK size_t _fstrspn( const char _WCFAR *str, const char _WCFAR *charset )
{
unsigned /*char*/ tc;
unsigned char vector[32];
size_t len;
 
__fsetbits( vector, charset );
len = 0;
for( ; tc = (unsigned char) *str; ++str, ++len ) {
/* quit if we find any char not in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break;
}
return( len );
}
/programs/develop/open watcom/trunk/clib/string/fstrspnp.c
0,0 → 1,47
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <string.h>
 
 
_WCRTLINK char _WCFAR *_fstrspnp( const char _WCFAR *p1, const char _WCFAR *p2 )
{
size_t index;
 
index = _fstrspn( p1, p2 );
if( *(p1+index) != '\0' ) {
return( (char _WCFAR*)(p1+index) );
} else {
return( NULL );
}
}
/programs/develop/open watcom/trunk/clib/string/fstrstr.c
0,0 → 1,93
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: _fstrstr() implementation.
*
****************************************************************************/
 
 
#include "variety.h"
#include <stddef.h>
#include <string.h>
 
#ifdef M_I86
#if defined(__QNX__)
#include <i86.h>
#else
#include <dos.h>
#endif
 
extern int i86_memeq( const char _WCFAR *, const char _WCFAR *, int );
 
#define _ZFLAG (INTR_ZF<<8)
 
#pragma aux i86_memeq = \
0x1e /* push ds */\
0x96 /* xchg si,ax */\
0x8e 0xd8 /* mov ds,ax */\
0xf3 0xa6 /* rep cmpsb */\
0x9f /* lahf */\
0x1f /* pop ds */\
parm caller [si ax] [es di] [cx]\
value [ax] \
modify exact [si di cx ax];
 
#define memeq( p1, p2, len ) ( i86_memeq((p1),(p2),(len)) & _ZFLAG )
 
#else
 
#define memeq( p1, p2, len ) ( _fmemcmp((p1),(p2),(len)) == 0 )
 
#endif
 
/* Locate the first occurrence of the string pointed to by s2 in the
string pointed to by s1.
The strstr function returns a pointer to the located string, or a
null pointer if the string is not found.
*/
 
_WCRTLINK char _WCFAR *_fstrstr( const char _WCFAR *s1, const char _WCFAR *s2 )
{
char _WCFAR *end_of_s1;
size_t s1len, s2len;
 
if( s2[0] == '\0' ) {
return( (char _WCFAR *)s1 );
} else if( s2[1] == '\0' ) {
return( _fstrchr( s1, s2[0] ) );
}
end_of_s1 = _fmemchr( s1, '\0', ~0u );
s2len = _fstrlen( s2 );
for(;;) {
s1len = end_of_s1 - s1;
if( s1len < s2len ) break;
s1 = _fmemchr( s1, *s2, s1len ); /* find start of possible match */
if( s1 == NULL ) break;
if( memeq( s1, s2, s2len ) ) return( (char _WCFAR *)s1 );
++s1;
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/string/fstrtok.c
0,0 → 1,70
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdio.h>
#include <string.h>
#include "rtdata.h"
#include "nextftok.h"
#include "setbits.h"
 
 
_WCRTLINK char _WCFAR *_fstrtok( char _WCFAR *str, const char _WCFAR *charset )
{
unsigned /*char*/ tc;
unsigned char vector[32];
unsigned char _WCFAR *p1;
 
_INITNEXTFTOK
if( str == NULL ) {
str = _RWD_nextftok; /* use previous value */
if( str == NULL ) return( NULL );
}
__fsetbits( vector, charset );
for( ; tc = (unsigned char) *str; ++str ) {
/* quit if we find any char not in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break;
}
if( tc == '\0' ) return( NULL );
p1 = str;
for( ; tc = *p1; ++p1 ) {
/* quit when we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) {
*p1 = '\0'; /* terminate the token */
p1++; /* start of next token */
_RWD_nextftok = p1;
return( str );
}
}
_RWD_nextftok = NULL;
return( str );
}
/programs/develop/open watcom/trunk/clib/string/fstrupr.c
0,0 → 1,52
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <ctype.h>
#include <string.h>
 
_WCRTLINK char _WCFAR *_fstrupr( char _WCFAR *str )
{
char _WCFAR *p;
unsigned char c;
 
p = str;
while( c = *p ) {
c -= 'a';
if( c <= 'z' - 'a' ) {
c += 'A';
*p = c;
}
++p;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/nextftok.h
0,0 → 1,54
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#if defined(__OS2__) || defined(__NT__) || defined(__NETWARE__)
#if defined(__SW_BM)
 
#include "thread.h"
 
#define _INITNEXTFTOK
#define _NEXTFTOK (__THREADDATAPTR->__nextftokP)
 
#else
 
static char _WCFAR *nextftok = NULL;
 
#define _INITNEXTFTOK
#define _NEXTFTOK nextftok
 
#endif
#else
#define _INITNEXTFTOK
static char _WCFAR *nextftok = NULL;
#define _NEXTFTOK nextftok
#endif
/programs/develop/open watcom/trunk/clib/string/nexttok.h
0,0 → 1,48
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#define _INITNEXTTOK
#if defined(__OS2__) || defined(__NT__) || defined(__NETWARE__)
// the OS/2, NT and NETWARE files are identical
// note that NETWARE is always multi-thread
#if defined(__SW_BM)
#include "thread.h"
#define _NEXTTOK (__THREADDATAPTR->__nexttokP)
#else
static char *nexttok = NULL;
#define _NEXTTOK nexttok
#endif
#else
static char *nexttok = NULL;
#define _NEXTTOK nexttok
#endif
/programs/develop/open watcom/trunk/clib/string/selptr.c
0,0 → 1,44
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include "rtdata.h"
 
#ifdef __NETWARE__
_WCRTLINKD extern char *sys_errlist[];/* strerror error message table */
#define _sys_errlist sys_errlist
#endif
 
_WCRTLINK char * (*__get_sys_errlist_ptr())[] {
return &_sys_errlist;
}
/programs/develop/open watcom/trunk/clib/string/setbits.h
0,0 → 1,36
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: declaration for character set bit array routines
*
****************************************************************************/
 
 
extern void __setbits( unsigned char *vector, const char *charset );
extern void __fsetbits( unsigned char _WCFAR *vector, const char _WCFAR *charset );
 
extern const unsigned char _HUGEDATA _Bits[8];
 
/programs/develop/open watcom/trunk/clib/string/sneptr.c
0,0 → 1,44
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include "rtdata.h"
 
#ifdef __NETWARE__
_WCRTLINKD extern int _WCNEAR sys_nerr; /* # of entries in sys_errlist array */
#define _sys_nerr sys_nerr
#endif
 
_WCRTLINK int (*__get_sys_nerr_ptr()) {
return &_sys_nerr;
}
/programs/develop/open watcom/trunk/clib/string/snprintf.c
0,0 → 1,93
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of snprintf().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include "printf.h"
 
struct buf_limit {
CHAR_TYPE *bufptr;
size_t bufsize;
};
 
/*
* buf_putc -- append a character to a string in memory
*/
static slib_callback_t buf_putc; // setup calling convention
static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char )
{
struct buf_limit *bufinfo;
 
bufinfo = (struct buf_limit *)specs->_dest;
if( specs->_output_count < bufinfo->bufsize ) {
*( bufinfo->bufptr++ ) = op_char;
}
specs->_output_count++;
}
 
/*
* buf_count_putc -- only count characters to be output
*/
static slib_callback_t buf_count_putc; // setup calling convention
static void __SLIB_CALLBACK buf_count_putc( SPECS __SLIB *specs, int op_char )
{
specs->_output_count++;
}
 
 
_WCRTLINK int __F_NAME(vsnprintf,vsnwprintf) ( CHAR_TYPE *s, size_t bufsize,
const CHAR_TYPE *format, va_list arg)
{
register int len;
auto struct buf_limit bufinfo;
 
bufinfo.bufptr = s;
bufinfo.bufsize = bufsize - 1;
if( bufsize == 0 )
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_count_putc );
else {
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_putc );
s[(( len >= 0 ) && ( len < bufsize )) ? len : bufsize - 1] = '\0';
}
return( len );
}
 
 
_WCRTLINK int __F_NAME(snprintf,snwprintf) ( CHAR_TYPE *dest, size_t bufsize,
const CHAR_TYPE *format, ... )
{
auto va_list args;
 
va_start( args, format );
return( __F_NAME(vsnprintf,vsnwprintf)( dest, bufsize, format, args ) );
}
/programs/develop/open watcom/trunk/clib/string/snprtf_s.c
0,0 → 1,100
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of snprintf_s() - safe string fmt'd output.
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
#include "printf.h"
 
 
struct buf_limit {
CHAR_TYPE *bufptr;
rsize_t chars_output;
rsize_t max_chars;
};
 
/*
* buf_putc -- append a character to a string in memory
*/
static slib_callback_t buf_putc; // setup calling convention
static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char )
{
struct buf_limit *info;
 
info = (struct buf_limit *)specs->_dest;
if( specs->_output_count < info->max_chars ) {
*( info->bufptr++ ) = op_char;
info->chars_output++;
}
specs->_output_count++;
}
 
 
_WCRTLINK int __F_NAME(snprintf_s,snwprintf_s)( CHAR_TYPE * __restrict s, rsize_t n,
const CHAR_TYPE * __restrict format, ... )
{
va_list arg;
struct buf_limit info;
const char *msg;
 
/* First check the critical conditions; if any of those
* is violated, return immediately and don't touch anything.
*/
if( __check_constraint_nullptr_msg( msg, s )
&& __check_constraint_maxsize_msg( msg, n )
&& __check_constraint_zero_msg( msg, n ) ) {
 
/* The buffer looks okay, try doing something useful */
if( __check_constraint_nullptr_msg( msg, format ) ) {
int len;
 
info.bufptr = s;
info.chars_output = 0;
info.max_chars = n - 1;
msg = NULL;
va_start( arg, format );
len = __F_NAME(__prtf_s,__wprtf_s)( &info, format, arg, &msg, buf_putc );
va_end( arg );
if( msg == NULL ) {
/* No rt-constraint violation while formatting */
s[info.chars_output] = NULLCHAR;
return( len );
}
}
/* Something went wrong, output buffer will contain empty string */
*s = NULLCHAR;
}
__rtct_fail( __func__, msg, NULL );
return( -1 );
}
/programs/develop/open watcom/trunk/clib/string/sprintf.c
0,0 → 1,72
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include "printf.h"
 
 
//#ifdef __WIDECHAR__
//_WCRTLINK int _usprintf( wchar_t *dest, const wchar_t *format, ... )
//{
// va_list args;
//
// va_start( args, format );
// return( vswprintf( dest, INT_MAX, format, args ) );
//}
//#endif
 
 
#ifdef __WIDECHAR__
_WCRTLINK int swprintf( CHAR_TYPE *dest, size_t n, const CHAR_TYPE *format, ... )
{
auto va_list args;
 
va_start( args, format );
return( vswprintf( dest, n, format, args ) );
}
#endif
 
_WCRTLINK int __F_NAME(sprintf,_swprintf) ( CHAR_TYPE *dest, const CHAR_TYPE *format, ... )
{
auto va_list args;
 
va_start( args, format );
#ifdef __WIDECHAR__
return( _vswprintf( dest, format, args ) );
#else
return( vsprintf( dest, format, args ) );
#endif
}
/programs/develop/open watcom/trunk/clib/string/sprntf_s.c
0,0 → 1,107
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of sprintf_s() - safe formatted string output.
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
#include "printf.h"
 
 
/*
* mem_putc -- append a character to a string in memory, with overflow check
*/
 
struct vsprtf_s_buf {
CHAR_TYPE *bufptr;
rsize_t chars_output;
rsize_t max_chars;
};
 
static slib_callback_t mem_putc; // set up calling convention
static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char )
{
struct vsprtf_s_buf *info;
 
info = (struct vsprtf_s_buf *)specs->_dest;
if( info->chars_output <= info->max_chars ) {
*( info->bufptr++ ) = op_char;
specs->_output_count++;
info->chars_output++;
}
}
 
_WCRTLINK int __F_NAME(sprintf_s,swprintf_s)( CHAR_TYPE * __restrict s, rsize_t n,
const CHAR_TYPE * __restrict format, ... )
{
va_list arg;
struct vsprtf_s_buf info;
const char *msg;
int rc = 0;
 
/* First check the critical conditions; if any of those
* is violated, return immediately and don't touch anything.
*/
if( __check_constraint_nullptr_msg( msg, s )
&& __check_constraint_maxsize_msg( msg, n )
&& __check_constraint_zero_msg( msg, n ) ) {
 
/* The buffer looks okay, try doing something useful */
if( __check_constraint_nullptr_msg( msg, format ) ) {
info.bufptr = s;
info.chars_output = 0;
info.max_chars = n - 1;
msg = NULL;
 
va_start( arg, format );
__F_NAME(__prtf_s,__wprtf_s)( &info, format, arg, &msg, mem_putc );
va_end( arg );
 
if( msg == NULL ) {
if( info.chars_output <= info.max_chars ) {
s[info.chars_output] = NULLCHAR;
return( info.chars_output );
}
/* If we got here, the output buffer was too small */
msg = "n < chars_output";
#ifdef __WIDECHAR__
rc = -1; /* Return value for swprintf_s is different! */
#endif
}
}
/* Something went wrong, output buffer will contain empty string */
*s = NULLCHAR;
}
__rtct_fail( __func__, msg, NULL );
return( rc );
}
/programs/develop/open watcom/trunk/clib/string/sscanf.c
0,0 → 1,77
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include "scanf.h"
 
 
static int cget_string( PTR_SCNF_SPECS specs )
{
int c;
 
if( (c = *(specs->ptr)) != NULLCHAR ) {
++(specs->ptr);
} else {
c = EOF;
specs->eoinp = 1;
}
return( c );
}
 
 
static void uncget_string( int c, PTR_SCNF_SPECS specs )
{
--specs->ptr;
}
 
 
_WCRTLINK int __F_NAME(vsscanf,vswscanf) ( const CHAR_TYPE *dest, const CHAR_TYPE *format, va_list args )
{
auto SCNF_SPECS specs;
 
specs.ptr = (CHAR_TYPE *)dest;
specs.cget_rtn = cget_string;
specs.uncget_rtn = uncget_string;
return( __F_NAME(__scnf,__wscnf)( (PTR_SCNF_SPECS)&specs, format, args ) );
}
 
 
_WCRTLINK int __F_NAME(sscanf,swscanf) ( const CHAR_TYPE *dest, const CHAR_TYPE *format, ... )
{
va_list args;
 
va_start( args, format );
return( __F_NAME(vsscanf,vswscanf)( dest, format, args ) );
}
/programs/develop/open watcom/trunk/clib/string/sscanf_s.c
0,0 → 1,87
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of sscanf_s() - safe formatted string input.
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
#include "scanf.h"
 
 
static int cget_string( PTR_SCNF_SPECS specs )
{
int c;
 
if( (c = *(specs->ptr)) != NULLCHAR ) {
++(specs->ptr);
} else {
c = EOF;
specs->eoinp = 1;
}
return( c );
}
 
 
static void uncget_string( int c, PTR_SCNF_SPECS specs )
{
--specs->ptr;
}
 
 
 
_WCRTLINK int __F_NAME(sscanf_s,swscanf_s)( const CHAR_TYPE *s, const CHAR_TYPE *format, ... )
{
SCNF_SPECS specs;
const char *msg;
int rc;
va_list args;
 
/* Basic check for null pointers to see if we can continue */
if( __check_constraint_nullptr_msg( msg, s )
&& __check_constraint_nullptr_msg( msg, format ) ) {
 
specs.ptr = (CHAR_TYPE *)s;
specs.cget_rtn = cget_string;
specs.uncget_rtn = uncget_string;
msg = NULL;
va_start( args, format );
rc = __F_NAME(__scnf_s,__wscnf_s)( (PTR_SCNF_SPECS)&specs, format, &msg, args );
va_end( args );
if( msg == NULL ) {
/* no rt-constraint violation inside worker routine */
return( rc );
}
}
__rtct_fail( __func__, msg, NULL );
return( __F_NAME(EOF,WEOF) );
}
/programs/develop/open watcom/trunk/clib/string/stncat_s.c
0,0 → 1,90
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strncat_s() - bounds-checking strncat().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
 
 
_WCRTLINK errno_t __F_NAME(strncat_s,wcsncat_s)( CHAR_TYPE * __restrict s1,
rsize_t s1max, const CHAR_TYPE * __restrict s2,
rsize_t n )
/*************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
// strnlen_s is safe to use as it has no rt constraints
rsize_t m = s1max - __F_NAME(strnlen_s,wcsnlen_s)( s1, s1max );
 
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// n <= RSIZE_MAX
// s1max != 0
// m = s1max - strnlen_s( s1, s1max ) != 0
// if n >= m then m > strnlen_s( s2, m )
// s1 and s2 no overlap
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_maxsize_msg( msg, m ) &&
__check_constraint_zero_msg( msg, s1max ) &&
__check_constraint_zero_msg( msg, m ) &&
((n < m) || __check_constraint_a_gt_b_msg( msg, __F_NAME(strnlen_s,wcsnlen_s)( s2, m ), m - 1 )) &&
__check_constraint_overlap_msg( msg, s1, s1max, s2, __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ))) {
 
while( *s1 != NULLCHAR ) ++s1; //find end of field
 
while( n != 0 ) {
*s1 = *s2;
if( *s2 == NULLCHAR ) break;
++s1;
++s2;
--n;
}
*s1 = NULLCHAR;
 
rc = 0;
} else {
// Runtime-constraints found, store zero in receiving field
if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) {
s1[0] = NULLCHAR;
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
return( rc );
}
/programs/develop/open watcom/trunk/clib/string/stncpy_s.c
0,0 → 1,81
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strncpy_s() - bounds-checking strncpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
 
 
_WCRTLINK errno_t __F_NAME(strncpy_s,wcsncpy_s)( CHAR_TYPE * __restrict s1,
rsize_t s1max, const CHAR_TYPE * __restrict s2,
rsize_t n )
/*************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
// strnlen_s is safe to use as it has no rt constraints
rsize_t s2len = __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max );
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// n <= RSIZE_MAX
// s1max != 0
// if n >= s1max then s1max > strnlen_s( s2, s1max )
// s1 s2 no overlap
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_maxsize_msg( msg, n ) &&
__check_constraint_zero_msg( msg, s1max ) &&
((n < s1max) || __check_constraint_a_gt_b_msg( msg, s2len, s1max - 1 )) &&
__check_constraint_overlap_msg( msg, s1, s1max, s2, s2len )) {
 
for( ; n; --n) {
if( *s2 == '\0' ) break;
*s1++ = *s2++;
}
*s1 = '\0';
rc = 0;
} else {
// Runtime-constraints found, store zero in receiving field
if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) {
s1[0] = '\0';
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
return( rc );
}
/programs/develop/open watcom/trunk/clib/string/strcat.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include "xstring.h"
#undef strcat
 
 
/* concatenate t to the end of s */
 
_WCRTLINK CHAR_TYPE *__F_NAME(strcat,wcscat) ( CHAR_TYPE *dst, const CHAR_TYPE *t )
{
 
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
return( _inline_strcat( dst, t ) );
#else
CHAR_TYPE *s;
 
s = dst;
while( *s != NULLCHAR ) ++s;
while( *s++ = *t++ ) ;
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strcat_s.c
0,0 → 1,81
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strcat_s() - bounds-checking strcat().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
 
 
_WCRTLINK errno_t __F_NAME(strcat_s,wcscat_s)( CHAR_TYPE * __restrict s1,
rsize_t s1max, const CHAR_TYPE * __restrict s2 )
/************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
// strnlen_s is safe to use as it has no rt constraints
rsize_t m = s1max - __F_NAME(strnlen_s,wcsnlen_s)( s1, s1max );
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// s1max != 0
// m != 0
// m > strnlen_s( s2, m )
// s1 and s2 no overlap
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_zero_msg( msg, s1max ) &&
__check_constraint_zero_msg( msg, m ) &&
__check_constraint_a_gt_b_msg( msg,
__F_NAME(strnlen_s,wcsnlen_s)( s2, m ), m - 1 ) &&
__check_constraint_overlap_msg( msg, s1, s1max, s2,
__F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ) ) ) {
 
while( *s1 != NULLCHAR ) ++s1; // find end of field
while( *s1++ = *s2++ ); // append source field
 
rc = 0;
} else {
// Runtime-constraints found, store zero in receiving field
if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) {
s1[0] = NULLCHAR;
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
return( rc );
}
 
/programs/develop/open watcom/trunk/clib/string/strchr.c
0,0 → 1,125
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strchr() and wcschr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#include "riscstr.h"
 
#if defined(M_I86) && !defined(__WIDECHAR__)
 
extern char * _scan1();
 
/* use scan1 to find the char we are looking for */
 
#if defined(__SMALL_DATA__)
#pragma aux _scan1 = 0xad /* L1:lodsw */\
0x38 0xd0 /* cmp al,dl */\
0x74 0x20 /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x19 /* je L2 */\
0x38 0xd4 /* cmp ah,dl */\
0x74 0x19 /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x74 0x11 /* je L2 */\
0xad /* lodsw */\
0x38 0xd0 /* cmp al,dl */\
0x74 0x0f /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x08 /* je L2 */\
0x38 0xd4 /* cmp ah,dl */\
0x74 0x08 /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x75 0xde /* jne L1 */\
0x31 0xf6 /* L2:xor si,si */\
0xa9 /* test ax,... */\
0x4e /* L3:dec si */\
0x4e /* L4:dec si */\
parm caller [si] [dl]\
value [si]\
modify [ax si];
#else
#pragma aux _scan1 = \
0x1e /* push ds */ \
0x8e 0xd9 /* mov ds,cx */ \
0x8c 0xda /* mov dx,ds */\
0xad /* L1:lodsw */\
0x38 0xd8 /* cmp al,bl */\
0x74 0x22 /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x19 /* je L2 */\
0x38 0xdc /* cmp ah,bl */\
0x74 0x1b /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x74 0x11 /* je L2 */\
0xad /* lodsw */\
0x38 0xd8 /* cmp al,bl */\
0x74 0x11 /* je L3 */\
0x84 0xc0 /* test al,al*/\
0x74 0x08 /* je L2 */\
0x38 0xdc /* cmp ah,bl */\
0x74 0x0a /* je L4 */\
0x84 0xe4 /* test ah,ah*/\
0x75 0xde /* jne L1 */\
0x31 0xf6 /* L2:xor si,si*/\
0x89 0xf2 /* mov dx,si */\
0xa9 /* test ax,... */\
0x4e /* L3:dec si */\
0x4e /* L4:dec si */\
0x1f /* pop ds */ \
parm caller [cx si] [bl]\
value [dx si]\
modify [ax dx si];
#endif
#endif
 
 
/* locate the first occurrence of c in the initial n characters of the
string pointed to by s. The terminating null character is considered
to be part of the string.
If the character c is not found, NULL is returned.
*/
#undef strchr
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple_wcschr( const CHAR_TYPE *s, INTCHAR_TYPE c )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strchr,wcschr)( const CHAR_TYPE *s, INTCHAR_TYPE c )
#endif
{
CHAR_TYPE cc = c;
do {
if( *s == cc ) return( (CHAR_TYPE *)s );
} while( *s++ != NULLCHAR );
return( NULL );
}
/programs/develop/open watcom/trunk/clib/string/strcoll.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include "xstring.h"
 
#undef strcoll
 
 
 
/* This function is identical to strcmp, except it is suppose to use
the current locale. We only support the "C" locale, so this code
is identical to strcmp.
*/
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
 
_WCRTLINK int __F_NAME(strcoll,wcscoll) ( const CHAR_TYPE *s, const CHAR_TYPE *t )
{
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return( 0 );
return( *s - *t );
}
/programs/develop/open watcom/trunk/clib/string/strcpy.c
0,0 → 1,140
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strcpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <string.h>
#include "riscstr.h"
 
#undef strcpy
 
extern CHAR_TYPE *__strcpy( CHAR_TYPE *dst, const CHAR_TYPE *src );
#if defined(__386__)
#pragma aux __strcpy = \
" push eax" \
"L1: mov cl,[edx]" \
" mov [eax],cl" \
" cmp cl,0" \
" je L2" \
" mov cl,1[edx]"\
" add edx,2" \
" mov 1[eax],cl"\
" add eax,2" \
" cmp cl,0" \
" jne L1" \
"L2: pop eax" \
parm [eax] [edx] value [eax] modify exact [eax edx ecx];
#elif defined(M_I86)
#if defined(__SMALL_DATA__)
#pragma aux __strcpy = \
" push di" \
" test si,1" \
" je L1" \
" lodsb" \
" mov [di],al" \
" inc di" \
" cmp al,0" \
" je L3" \
"L1: mov ax,[si]" \
" test al,al" \
" je L2" \
" mov [di],ax" \
" add di,2" \
" test ah,ah" \
" je L3" \
" mov ax,2[si]" \
" test al,al" \
" je L2" \
" mov [di],ax" \
" add si,4" \
" add di,2" \
" test ah,ah" \
" jne L1" \
" je L3" \
"L2: mov [di],al" \
"L3: pop ax" \
parm [di] [si] value [ax] modify exact [si di];
#else // compact, large, or huge
#pragma aux __strcpy = \
" push ds" \
" push di" \
" mov ds,dx" \
" test si,1" \
" je L1" \
" lodsb" \
" stosb" \
" cmp al,0" \
" je L3" \
"L1: mov ax,[si]" \
" test al,al" \
" je L2" \
" stosw" \
" test ah,ah" \
" je L3" \
" mov ax,2[si]" \
" test al,al" \
" je L2" \
" stosw" \
" add si,4" \
" test ah,ah" \
" jne L1" \
" je L3" \
"L2: stosb" \
"L3: pop ax" \
" mov dx,es" \
" pop ds" \
parm [es di] [dx si] value [dx ax] modify exact [si di];
#endif
#else
/* currently no pragma for non-x86 */
#endif
 
 
/* copy string t to string s */
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple_wcscpy( CHAR_TYPE *s, const CHAR_TYPE *t )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strcpy,wcscpy)( CHAR_TYPE *s, const CHAR_TYPE *t )
#endif
{
#if !defined(__WIDECHAR__) && defined(_M_IX86)
return( __strcpy( s, t ) );
#else
CHAR_TYPE *dst;
 
dst = s;
while( *dst++ = *t++ )
;
return( s );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strcpy_s.c
0,0 → 1,76
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strcpy_s() - bounds-checking strcpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
 
 
_WCRTLINK errno_t __F_NAME(strcpy_s,wcscpy_s)( CHAR_TYPE * __restrict s1,
rsize_t s1max, const CHAR_TYPE * __restrict s2 )
/************************************************************************/
{
errno_t rc = -1;
const char *msg;
 
// strnlen_s is safe to use as it has no rt constraints
rsize_t s2len = __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max );
 
// Verify runtime-constraints
// s1 not NULL
// s2 not NULL
// s1max <= RSIZE_MAX
// s1max != 0
// s1max > strnlen_s( s2, s1max )
// s1 s2 no overlap
if( __check_constraint_nullptr_msg( msg, s1 ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_maxsize_msg( msg, s1max ) &&
__check_constraint_zero_msg( msg, s1max ) &&
__check_constraint_a_gt_b_msg( msg, s2len, s1max - 1 ) &&
__check_constraint_overlap_msg( msg, s1, s1max, s2, s2len ) ) {
 
while( *s1++ = *s2++)
;
 
rc = 0;
} else {
// Runtime-constraints violated, make destination string empty
if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) {
s1[0] = NULLCHAR;
}
// Now call the handler
__rtct_fail( __func__, msg, NULL );
}
return( rc );
}
/programs/develop/open watcom/trunk/clib/string/strcspn.c
0,0 → 1,78
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#include "setbits.h"
 
/* The strcspn function computes the length of the initial segment of the
string pointed to by str which consists entirely of characters not from
the string pointed to by charset. The terminating NULL character is not
considered part of charset.
*/
 
 
_WCRTLINK size_t __F_NAME(strcspn,wcscspn) ( const CHAR_TYPE *str, const CHAR_TYPE *charset )
{
#if defined(__WIDECHAR__)
 
const CHAR_TYPE *p1;
const CHAR_TYPE *p2;
CHAR_TYPE tc1;
CHAR_TYPE tc2;
size_t len;
 
len = 0;
for( p1 = str; tc1 = *p1; p1++, len++ ) {
for( p2 = charset; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 != NULLCHAR ) break;
}
return( len );
 
#else
unsigned /*char*/ tc;
unsigned char vector[32];
size_t len;
 
__setbits( vector, charset );
len = 0;
for( ; tc = (unsigned char) *str; ++len, ++str ) {
/* quit if we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) break;
}
return( len );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strdup.c
0,0 → 1,57
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include "strdup.h"
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "liballoc.h"
 
#ifdef __WIDECHAR__
extern size_t wcslen( const CHAR_TYPE * );
#endif
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(__clib_strdup,__clib_wcsdup) ( const CHAR_TYPE *str )
{
CHAR_TYPE *mem;
int len;
 
len = __F_NAME(strlen,wcslen)( str ) + 1;
mem = lib_malloc( len * CHARSIZE );
if( mem ) {
(memcpy)( mem, str, len * CHARSIZE );
}
return( mem );
}
/programs/develop/open watcom/trunk/clib/string/streln_s.c
0,0 → 1,57
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strerrorlen_s().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "errstr.h"
 
 
_WCRTLINK size_t __F_NAME(strerrorlen_s,wcserrorlen_s)( errno_t errnum )
/************************************************************************/
{
size_t m = 0;
char *msg;
 
if( errnum < 0 || errnum >= _sys_nerr ) {
msg = UNKNOWN_ERROR;
} else {
msg = _sys_errlist[ errnum ];
}
 
// count chars up to '\0' assuming _sys_errlist is singlebyte
while( *msg++ != '\0' ) {
++m;
}
return( m );
}
/programs/develop/open watcom/trunk/clib/string/strerr_s.c
0,0 → 1,99
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strerror_s() - bounds checking strerror().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include <errno.h>
#include "errstr.h"
 
 
_WCRTLINK errno_t __F_NAME(strerror_s,wcserror_s)( CHAR_TYPE *s,
rsize_t maxsize,
errno_t errnum )
/*****************************************************************/
{
errno_t rc = -1;
 
#ifdef __WIDECHAR__
wchar_t Wide_Error_String[ 128 ];
#endif
char *msg;
CHAR_TYPE *p;
CHAR_TYPE *p2;
size_t msglen;
int k;
 
/* runtime-constraints */
// s not NULL
// maxsize <= RSIZE_MAX
// maxsize != 0
if( __check_constraint_nullptr( s ) &&
__check_constraint_maxsize( maxsize ) &&
__check_constraint_zero( maxsize ) ) {
 
if( errnum < 0 || errnum >= _sys_nerr ) {
msg = UNKNOWN_ERROR;
} else {
msg = _sys_errlist[ errnum ];
}
 
msglen = strlen( msg );
 
#ifdef __WIDECHAR__
_AToUni( Wide_Error_String, msg );
p2 = Wide_Error_String;
#else
p2 = msg;
#endif
p = s;
k = 0;
// copy string up to end of string or end of receiving field
while ( (k < maxsize - 1) && (*p2 != NULLCHAR) ) {
*p++ = *p2++;
++k;
};
 
if( (maxsize > 3) && (msglen > maxsize - 4) ) {
/* msg does not fit, indicate it's incomplete */
/* and terminate string */
__F_NAME(strcpy,wcscpy)( p - 3, STRING( "..." ) );
} else {
*p = NULLCHAR; // terminate string
}
if( msglen < maxsize) {
rc = 0; // msg not truncated
}
}
return( rc );
}
/programs/develop/open watcom/trunk/clib/string/strerror.c
0,0 → 1,344
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strerror() function.
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include <errno.h>
#include "rtdata.h"
#if defined(__NT__)
#include <windows.h>
#endif
#include "errstr.h"
 
 
#ifndef __WIDECHAR__
 
#ifdef __LINUX__
char *_sys_errlist[] = {
/* 0 EOK */ "No error",
/* 1 EPERM */ "Operation not permitted",
/* 2 ENOENT */ "No such file or directory",
/* 3 ESRCH */ "No such process",
/* 4 EINTR */ "Interrupted system call",
/* 5 EIO */ "I/O error",
/* 6 ENXIO */ "No such device or address",
/* 7 E2BIG */ "Arg list too long",
/* 8 ENOEXEC */ "Exec format error",
/* 9 EBADF */ "Bad file number",
/* 10 ECHILD */ "No child processes",
/* 11 EAGAIN */ "Try again",
/* 12 ENOMEM */ "Out of memory",
/* 13 EACCES */ "Permission denied",
/* 14 EFAULT */ "Bad address",
/* 15 ENOTBLK */ "Block device required",
/* 16 EBUSY */ "Device or resource busy",
/* 17 EEXIST */ "File exists",
/* 18 EXDEV */ "Cross-device link",
/* 19 ENODEV */ "No such device",
/* 20 ENOTDIR */ "Not a directory",
/* 21 EISDIR */ "Is a directory",
/* 22 EINVAL */ "Invalid argument",
/* 23 ENFILE */ "File table overflow",
/* 24 EMFILE */ "Too many open files",
/* 25 ENOTTY */ "Not a typewriter",
/* 26 ETXTBSY */ "Text file busy",
/* 27 EFBIG */ "File too large",
/* 28 ENOSPC */ "No space left on device",
/* 29 ESPIPE */ "Illegal seek",
/* 30 EROFS */ "Read-only file system",
/* 31 EMLINK */ "Too many links",
/* 32 EPIPE */ "Broken pipe",
/* 33 EDOM */ "Math argument out of domain of func",
/* 34 ERANGE */ "Math result not representable",
/* 35 EDEADLK */ "Resource deadlock would occur",
/* 36 ENAMETOOLONG */ "File name too long",
/* 37 ENOLCK */ "No record locks available",
/* 38 ENOSYS */ "Function not implemented",
/* 39 ENOTEMPTY */ "Directory not empty",
/* 40 ELOOP */ "Too many symbolic links encountered",
/* 41 */ "",
/* 42 ENOMSG */ "No message of desired type",
/* 43 EIDRM */ "Identifier removed",
/* 44 ECHRNG */ "Channel number out of range",
/* 45 EL2NSYNC */ "Level 2 not synchronized",
/* 46 EL3HLT */ "Level 3 halted",
/* 47 EL3RST */ "Level 3 reset",
/* 48 ELNRNG */ "Link number out of range",
/* 49 EUNATCH */ "Protocol driver not attached",
/* 50 ENOCSI */ "No CSI structure available",
/* 51 EL2HLT */ "Level 2 halted",
/* 52 EBADE */ "Invalid exchange",
/* 53 EBADR */ "Invalid request descriptor",
/* 54 EXFULL */ "Exchange full",
/* 55 ENOANO */ "No anode",
/* 56 EBADRQC */ "Invalid request code",
/* 57 EBADSLT */ "Invalid slot",
/* 58 */ "",
/* 59 EBFONT */ "Bad font file format",
/* 60 ENOSTR */ "Device not a stream",
/* 61 ENODATA */ "No data available",
/* 62 ETIME */ "Timer expired",
/* 63 ENOSR */ "Out of streams resources",
/* 64 ENONET */ "Machine is not on the network",
/* 65 ENOPKG */ "Package not installed",
/* 66 EREMOTE */ "Object is remote",
/* 67 ENOLINK */ "Link has been severed",
/* 68 EADV */ "Advertise error",
/* 69 ESRMNT */ "Srmount error",
/* 70 ECOMM */ "Communication error on send",
/* 71 EPROTO */ "Protocol error",
/* 72 EMULTIHOP */ "Multihop attempted",
/* 73 EDOTDOT */ "RFS specific error",
/* 74 EBADMSG */ "Not a data message",
/* 75 EOVERFLOW */ "Value too large for defined data type",
/* 76 ENOTUNIQ */ "Name not unique on network",
/* 77 EBADFD */ "File descriptor in bad state",
/* 78 EREMCHG */ "Remote address changed",
/* 79 ELIBACC */ "Can not access a needed shared library",
/* 80 ELIBBAD */ "Accessing a corrupted shared library",
/* 81 ELIBSCN */ ".lib section in a.out corrupted",
/* 82 ELIBMAX */ "Attempting to link in too many shared libraries",
/* 83 ELIBEXEC */ "Cannot exec a shared library directly",
/* 84 EILSEQ */ "Illegal byte sequence",
/* 85 ERESTART */ "Interrupted system call should be restarted",
/* 86 ESTRPIPE */ "Streams pipe error",
/* 87 EUSERS */ "Too many users",
/* 88 ENOTSOCK */ "Socket operation on non-socket",
/* 89 EDESTADDRREQ */ "Destination address required",
/* 90 EMSGSIZE */ "Message too long",
/* 91 EPROTOTYPE */ "Protocol wrong type for socket",
/* 92 ENOPROTOOPT */ "Protocol not available",
/* 93 EPROTONOSUPPORT */ "Protocol not supported",
/* 94 ESOCKTNOSUPPORT */ "Socket type not supported",
/* 95 EOPNOTSUPP */ "Operation not supported on transport endpoint",
/* 96 EPFNOSUPPORT */ "Protocol family not supported",
/* 97 EAFNOSUPPORT */ "Address family not supported by protocol",
/* 98 EADDRINUSE */ "Address already in use",
/* 99 EADDRNOTAVAIL */ "Cannot assign requested address",
/* 100 ENETDOWN */ "Network is down",
/* 101 ENETUNREACH */ "Network is unreachable",
/* 102 ENETRESET */ "Network dropped connection because of reset",
/* 103 ECONNABORTED */ "Software caused connection abort",
/* 104 ECONNRESET */ "Connection reset by peer",
/* 105 ENOBUFS */ "No buffer space available",
/* 106 EISCONN */ "Transport endpoint is already connected",
/* 107 ENOTCONN */ "Transport endpoint is not connected",
/* 108 ESHUTDOWN */ "Cannot send after transport endpoint shutdown",
/* 109 ETOOMANYREFS */ "Too many references: cannot splice",
/* 110 ETIMEDOUT */ "Connection timed out",
/* 111 ECONNREFUSED */ "Connection refused",
/* 112 EHOSTDOWN */ "Host is down",
/* 113 EHOSTUNREACH */ "No route to host",
/* 114 EALREADY */ "Operation already in progress",
/* 115 EINPROGRESS */ "Operation now in progress",
/* 116 ESTALE */ "Stale NFS file handle",
/* 117 EUCLEAN */ "Structure needs cleaning",
/* 118 ENOTNAM */ "Not a XENIX named type file",
/* 119 ENAVAIL */ "No XENIX semaphores available",
/* 120 EISNAM */ "Is a named type file",
/* 121 EREMOTEIO */ "Remote I/O error",
/* 122 EDQUOT */ "Quota exceeded",
/* 121 */ "",
/* 123 ENOMEDIUM */ "No medium found",
/* 124 EMEDIUMTYPE */ "Wrong medium type"
/* if more are added, be sure to update _sys_nerr accordingly */
};
#else
char *_sys_errlist[] = {
/* 0 EZERO */ "No error",
/* 1 ENOENT */ "No such file or directory",
/* 2 E2BIG */ "Arg list too big",
/* 3 ENOEXEC */ "Exec format error",
/* 4 EBADF */ "Bad file number",
/* 5 ENOMEM */ "Not enough memory",
/* 6 EACCES */ "Permission denied",
/* 7 EEXIST */ "File exists",
/* 8 EXDEV */ "Cross-device link",
/* 9 EINVAL */ "Invalid argument",
/* 10 ENFILE */ "File table overflow",
/* 11 EMFILE */ "Too many open files",
/* 12 ENOSPC */ "No space left on device",
/* 13 EDOM */ "Argument too large",
/* 14 ERANGE */ "Result too large",
/* 15 EDEADLK */ "Resource deadlock would occur",
/* 16 EINTR */ "System call interrupted",
/* 17 ECHILD */ "Child does not exist",
/* 18 EAGAIN */ "Resource unavailable, try again",
/* 19 EBUSY */ "Device or resource busy",
/* 20 EFBIG */ "File too large",
/* 21 EIO */ "I/O error",
/* 22 EISDIR */ "Is a directory",
/* 23 ENOTDIR */ "Not a directory",
/* 24 EMLINK */ "Too many links",
/* 25 ENOTBLK */ "Block device required",
/* 26 ENOTTY */ "Not a character device",
/* 27 ENXIO */ "No such device or address",
/* 28 EPERM */ "Not owner",
/* 29 EPIPE */ "Broken pipe",
/* 30 EROFS */ "Read-only file system",
/* 31 ESPIPE */ "Illegal seek",
/* 32 ESRCH */ "No such process",
/* 33 ETXTBSY */ "Text file busy",
/* 34 EFAULT */ "Bad address",
/* 35 ENAMETOOLONG */ "Filename too long",
/* 36 ENODEV */ "No such device",
/* 37 ENOLCK */ "No locks available in system",
/* 38 ENOSYS */ "Unknown system call",
/* 39 ENOTEMPTY */ "Directory not empty",
/* 40 EILSEQ */ "Illegal multibyte sequence"
/* if more are added, be sure to update _sys_nerr accordingly */
};
#endif
 
int _WCNEAR _sys_nerr = ( sizeof( _sys_errlist ) / sizeof( *_sys_errlist ) );
 
#endif
 
_WCRTLINK CHAR_TYPE *__F_NAME(strerror,wcserror)( int errnum )
{
#ifdef __WIDECHAR__
static wchar_t Wide_Error_String[40];
#endif
char *msg;
 
if( errnum < 0 || errnum >= _sys_nerr ) {
msg = UNKNOWN_ERROR;
} else {
msg = _sys_errlist[ errnum ];
}
return( _AToUni( Wide_Error_String, msg ) );
}
 
// Note: Windows FORMAT_MESSAGE_MAX_WIDTH_MASK is 255
 
#if !defined(FORMAT_MESSAGE_MAX_WIDTH_MASK)
#define FORMAT_MESSAGE_MAX_WIDTH_MASK 255
#endif
 
#ifdef __WIDECHAR__
static wchar_t Wide_Error_String[FORMAT_MESSAGE_MAX_WIDTH_MASK+1];
#else
static char Error_String[FORMAT_MESSAGE_MAX_WIDTH_MASK+1];
#endif
 
 
/*
char *_strerror( const char *strErrMsg );
 
Description from the MSDN:
 
If strErrMsg is passed as NULL, _strerror returns a pointer to a
string containing the system error message for the last library call
that produced an error. The error-message string is terminated by
the newline character ('\n'). If strErrMsg is not equal to NULL,
then _strerror returns a pointer to a string containing (in order)
your string message, a colon, a space, the system error message for
the last library call producing an error, and a newline character.
Your string message can be, at most, 94 bytes long.
 
The actual error number for _strerror is stored in the variable
errno. The system error messages are accessed through the variable
_sys_errlist, which is an array of messages ordered by error number.
_strerror accesses the appropriate error message by using the errno
value as an index to the variable _sys_errlist. The value of the
variable _sys_nerr is defined as the maximum number of elements in
the _sys_errlist array. To produce accurate results, call _strerror
immediately after a library routine returns with an error.
Otherwise, subsequent calls to strerror or _strerror can overwrite
the errno value.
 
_strerror is not part of the ANSI definition but is instead a
Microsoft extension to it. Do not use it where portability is
desired; for ANSI compatibility, use strerror instead.
 
*/
 
_WCRTLINK CHAR_TYPE *__F_NAME(_strerror,_wcserror)( const CHAR_TYPE *strErrMsg )
{
int errnum;
 
errnum = _RWD_errno;
#ifdef __WIDECHAR__
Wide_Error_String[0] = L'\0';
if( strErrMsg != NULL ) {
wcsncpy( Wide_Error_String, strErrMsg, 94 );
Wide_Error_String[94] = L'\0'; // just in case more than 94
wcscat( Wide_Error_String, L": " );
}
wcscat( Wide_Error_String, wcserror( errnum ) );
wcscat( Wide_Error_String, L"\n" );
return( Wide_Error_String );
#else
Error_String[0] = '\0';
if( strErrMsg != NULL ) {
strncpy( Error_String, strErrMsg, 94 );
Error_String[94] = '\0'; // just in case more than 94
strcat( Error_String, ": " );
}
strcat( Error_String, strerror( errnum ) );
strcat( Error_String, "\n" );
return( Error_String );
#endif
}
 
#if defined(__NT__)
 
_WCRTLINK CHAR_TYPE *__F_NAME(_doserror,_wdoserror)( int errnum )
{
#ifdef __WIDECHAR__
Wide_Error_String[0] = L'\0';
FormatMessageW( FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
errnum,
0,
Wide_Error_String,
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL );
return( Wide_Error_String );
#else
Error_String[0] = '\0';
FormatMessageA( FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
errnum,
0,
Error_String,
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL );
return( Error_String );
#endif
}
 
#endif
/programs/develop/open watcom/trunk/clib/string/stricmp.c
0,0 → 1,62
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <ctype.h>
#include <string.h>
#include "riscstr.h"
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK int __simple__wcsicmp( const CHAR_TYPE *s, const CHAR_TYPE *t ) {
#else
_WCRTLINK int __F_NAME(stricmp,_wcsicmp)( const CHAR_TYPE *s, const CHAR_TYPE *t ) {
#endif
UCHAR_TYPE c1;
UCHAR_TYPE c2;
 
for(;;) {
c1 = *s;
c2 = *t;
if( IS_ASCII( c1 ) && IS_ASCII( c2 ) ) {
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
}
if( c1 != c2 ) break;
if( c1 == NULLCHAR ) break;
++s;
++t;
}
return( c1 - c2 );
}
/programs/develop/open watcom/trunk/clib/string/strlcat.c
0,0 → 1,68
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of BSD style strlcat() and wcslcat().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
 
 
_WCRTLINK size_t __F_NAME(strlcat,wcslcat)( CHAR_TYPE *dst, const CHAR_TYPE *t, size_t n )
{
CHAR_TYPE *s;
size_t len;
 
s = dst;
// Find end of string in destination buffer but don't overrun
for( len = n; len; --len ) {
if( *s == NULLCHAR ) break;
++s;
}
// If no null char was found in dst, the buffer is messed up; don't
// touch it
if( *s == NULLCHAR ) {
--len; // Decrement len to leave space for terminating null
while( len != 0 ) {
*s = *t;
if( *s == NULLCHAR ) {
return( n - len - 1 );
}
++s;
++t;
--len;
}
// Buffer not large enough. Terminate and figure out desired length
*s = NULLCHAR;
while( *t++ != NULLCHAR )
++n;
--n;
}
return( n );
}
/programs/develop/open watcom/trunk/clib/string/strlcpy.c
0,0 → 1,64
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of BSD style strlcpy() and wcslcpy().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
 
 
_WCRTLINK size_t __F_NAME(strlcpy,wcslcpy)( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t len )
{
const CHAR_TYPE *s;
size_t count;
 
count = len;
if( len ) {
--len; // leave space for terminating null
for( ; len; --len ) {
if( *src == NULLCHAR ) {
break;
}
*dst++ = *src++;
}
*dst = NULLCHAR; // terminate 'dst'
} else {
++count; // account for not decrementing 'len'
}
 
if( !len ) { // source string was truncated
s = src;
while( *s != NULLCHAR ) {
++s;
}
count += s - src; // find out how long 'src' really is
}
return( count - len - 1 ); // final null doesn't count
}
/programs/develop/open watcom/trunk/clib/string/strlen.c
0,0 → 1,58
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include "xstring.h"
#include "riscstr.h"
#undef strlen
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK size_t __simple_wcslen( const CHAR_TYPE *s ) /* return length of s */
#else
_WCRTLINK size_t __F_NAME(strlen,wcslen)( const CHAR_TYPE *s ) /* return length of s */
#endif
{
 
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
return( _inline_strlen( s ) );
#else
const CHAR_TYPE *p;
 
p = s;
while( *p != NULLCHAR )
++p;
return( p - s );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strlwr.c
0,0 → 1,59
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strlwr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <ctype.h>
#include <string.h>
#include "riscstr.h"
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple__wcslwr( CHAR_TYPE *str ) {
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strlwr,_wcslwr)( CHAR_TYPE *str ) {
#endif
CHAR_TYPE *p;
UCHAR_TYPE c;
 
p = str;
while( (c = *p) ) {
if( IS_ASCII( c ) ) {
c -= 'A';
if( c <= 'Z' - 'A' ) {
c += 'a';
*p = c;
}
}
++p;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/strncat.c
0,0 → 1,116
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <string.h>
 
#if defined(M_I86) && !defined(__WIDECHAR__)
 
extern char *_fast_strncat( char _WCFAR *, const char *, size_t );
 
#if defined(__SMALL_DATA__)
 
#pragma aux _fast_strncat = \
0x57 /* push di */\
0xb9 0xff 0xff /* mov cx,ffffh */\
0x31 0xc0 /* xor ax,ax */\
0xf2 0xae /* repne scasb */\
0x4f /* dec di */\
0x89 0xd1 /* mov cx,dx */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x74 0x03 /* je L2 */\
0x26 0x88 0x25 /* mov es:[di],ah */\
0x58 /* L2: pop ax */\
parm caller [es di] [si] [dx]\
value [ax] \
modify exact [ax cx si di];
 
#else
 
#pragma aux _fast_strncat = \
0x1e /* push ds */ \
0x8e 0xd9 /* mov ds,cx */ \
0x57 /* push di */\
0xb9 0xff 0xff /* mov cx,ffffh */\
0x31 0xc0 /* xor ax,ax */\
0xf2 0xae /* repne scasb */\
0x4f /* dec di */\
0x89 0xd1 /* mov cx,dx */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x74 0x03 /* je L2 */\
0x26 0x88 0x25 /* mov es:[di],ah */\
0x58 /* L2: pop ax */\
0x1f /* pop ds */ \
parm caller [es di] [cx si] [dx]\
value [es ax] \
modify exact [ax cx si di];
#endif
 
#endif
 
 
/* concatenate t to the end of dst */
 
_WCRTLINK CHAR_TYPE *__F_NAME(strncat,wcsncat) ( CHAR_TYPE *dst, const CHAR_TYPE *t, size_t n )
{
#if defined(M_I86) && !defined(__WIDECHAR__)
if( n ) {
return( _fast_strncat( dst, t, n ) );
}
return( dst );
#else
CHAR_TYPE *s;
 
#ifdef __WIDECHAR__
s = dst + wcslen( dst );
#else
s = memchr( dst, NULLCHAR, ~0u );
#endif
while( n != 0 ) {
*s = *t;
if( *s == NULLCHAR ) break;
++s;
++t;
--n;
}
*s = NULLCHAR;
return( dst );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strncmp.c
0,0 → 1,104
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <string.h>
#include "riscstr.h"
 
#if defined(M_I86) && !defined(__WIDECHAR__)
 
extern int _fast_strncmp( const char *, const char _WCFAR *, size_t );
 
#if defined(__SMALL_DATA__)
#pragma aux _fast_strncmp = \
0x89 0xfa /* mov dx,di */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0x89 0xf9 /* mov cx,di */ \
0x89 0xd7 /* mov di,dx */ \
0x29 0xf9 /* sub cx,di */ \
0xf3 0xa6 /* repe cmpsb */ \
0x74 0x05 /* je L1 */ \
0x19 0xc9 /* sbb cx,cx */ \
0x83 0xd9 0xff /* sbb cx,ffffh */ \
/* L1: */ \
parm caller [si] [es di] [cx] \
value [cx] \
modify exact [dx ax di cx si];
#else
#pragma aux _fast_strncmp = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0x89 0xfa /* mov dx,di */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0x89 0xf9 /* mov cx,di */ \
0x89 0xd7 /* mov di,dx */ \
0x29 0xf9 /* sub cx,di */ \
0xf3 0xa6 /* repe cmpsb */ \
0x74 0x05 /* je L1 */ \
0x19 0xc9 /* sbb cx,cx */ \
0x83 0xd9 0xff /* sbb cx,ffffh */ \
/* L1: */ \
0x1f /* pop ds */ \
parm caller [dx si] [es di] [cx] \
value [cx] \
modify exact [dx ax di cx si];
#endif
#endif
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK int __simple_wcsncmp( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
#else
_WCRTLINK int __F_NAME(strncmp,wcsncmp)( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
#endif
{
#if defined(M_I86) && !defined(__WIDECHAR__)
if( n ) {
return( _fast_strncmp( s, t, n ) );
}
return( 0 );
#else
for(;;) {
if( n == 0 ) return( 0 ); /* equal */
if( *s != *t ) return( *s - *t ); /* less than or greater than */
if( *s == NULLCHAR ) return( 0 ); /* equal */
++s;
++t;
--n;
}
#endif
}
/programs/develop/open watcom/trunk/clib/string/strncpy.c
0,0 → 1,111
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include "riscstr.h"
 
#if defined(M_I86) & !defined(__WIDECHAR__)
 
extern char *fast_strncpy( char _WCFAR *, const char *, size_t );
 
#if defined(__SMALL_DATA__)
 
#pragma aux fast_strncpy = \
0x57 /* push di */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x31 0xc0 /* xor ax,ax */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xab /* rep stosw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xaa /* rep stosb */\
0x58 /* pop ax */\
parm caller [es di] [si] [cx]\
value [ax] \
modify exact [ax cx si di];
 
#else
 
#pragma aux fast_strncpy = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0x57 /* push di */\
0xac /* L1: lodsb */\
0xaa /* stosb */\
0x84 0xc0 /* test al,al */\
0xe0 0xfa /* loopne L1 */\
0x31 0xc0 /* xor ax,ax */\
0xd1 0xe9 /* shr cx,1 */\
0xf3 0xab /* rep stosw */\
0x11 0xc9 /* adc cx,cx */\
0xf3 0xaa /* rep stosb */\
0x58 /* pop ax */\
0x1f /* pop ds */ \
parm caller [es di] [dx si] [cx]\
value [es ax] \
modify exact [ax cx si di];
 
#endif
 
#endif
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple_wcsncpy( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t len )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strncpy,wcsncpy)( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t len )
#endif
{
#if defined(M_I86) && !defined(__WIDECHAR__)
if( len ) {
return( fast_strncpy( dst, src, len ) );
}
return( dst );
#else
CHAR_TYPE *ret;
 
ret = dst;
for(;len; --len ) {
if( *src == NULLCHAR ) break;
*dst++ = *src++;
}
while( len != 0 ) {
*dst++ = NULLCHAR; /* pad destination string with null chars */
--len;
}
return( ret );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strnicmp.c
0,0 → 1,65
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <ctype.h>
#include <string.h>
#include "riscstr.h"
 
/* return <0 if s<t, 0 if s==t, >0 if s>t */
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK int __simple__wcsnicmp( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
#else
_WCRTLINK int __F_NAME(strnicmp,_wcsnicmp)( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
#endif
{
UCHAR_TYPE c1;
UCHAR_TYPE c2;
 
for(;;) {
if( n == 0 ) return( 0 ); /* equal */
c1 = *s;
c2 = *t;
if( IS_ASCII( c1 ) && IS_ASCII( c2 ) ) {
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
}
if( c1 != c2 ) return( c1 - c2 ); /* less than or greater than */
if( c1 == NULLCHAR ) return( 0 ); /* equal */
++s;
++t;
--n;
}
}
/programs/develop/open watcom/trunk/clib/string/strnln_s.c
0,0 → 1,51
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strnlen_s() - "safe" strnlen().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
 
 
_WCRTLINK size_t __F_NAME(strnlen_s,wcsnlen_s)( const CHAR_TYPE *s, size_t maxsize )
/**********************************************************************************/
{
size_t m = 0;
 
// ensure the pointer is not NULL
if( s != NULL ) {
// count chars up to '\0' or maxsize
while( *(s + m) != NULLCHAR && m < maxsize )
++m;
}
return( m );
}
/programs/develop/open watcom/trunk/clib/string/strnset.c
0,0 → 1,52
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include "riscstr.h"
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple__wcsnset( CHAR_TYPE *str, int c, size_t len )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strnset,_wcsnset)( CHAR_TYPE *str, int c, size_t len )
#endif
{
CHAR_TYPE *p;
 
for( p = str; len; --len ) {
if( *p == NULLCHAR ) break;
*p++ = c;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/strpbrk.c
0,0 → 1,75
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#include "setbits.h"
 
/* The strpbrk function locates the first occurrence in the string pointed
to by str of any character from the string pointed to by charset.
*/
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(strpbrk,wcspbrk) ( const CHAR_TYPE *str, const CHAR_TYPE *charset )
{
#if defined(__WIDECHAR__)
 
const CHAR_TYPE *p1;
const CHAR_TYPE *p2;
CHAR_TYPE tc1;
CHAR_TYPE tc2;
size_t len;
 
len = 0;
for( p1 = str; tc1 = *p1; p1++, len++ ) {
for( p2 = charset; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 != NULLCHAR ) return( (CHAR_TYPE *)p1 );
}
return( NULL );
 
#else
unsigned char tc;
unsigned char vector[32];
 
__setbits( vector, charset );
for( ; tc = *str; ++str ) {
/* quit when we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 )
return( (char *)str );
}
return( NULL );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strrchr.c
0,0 → 1,106
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strchr() and wcsrchr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#include "riscstr.h"
 
#if defined(M_I86) && !defined(__WIDECHAR__)
 
extern char *_fast_strrchr( const char _WCFAR *, char );
 
#if defined(__SMALL_DATA__)
#pragma aux _fast_strrchr = \
0xb9 0xff 0xff /* mov cx,ffffh */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0xf7 0xd1 /* not cx */ \
0x4f /* dec di */ \
0x88 0xd0 /* mov al,dl */ \
0xfd /* std */ \
0xf2 0xae /* repne scasb */ \
0xfc /* cld */ \
0x75 0x03 /* jne L1 */ \
0x89 0xf9 /* mov cx,di */ \
0x41 /* inc cx */ \
/* L1: */ \
parm caller [es di] [dl] \
value [cx] \
modify exact [cx ax di];
#else
#pragma aux _fast_strrchr = \
0xb9 0xff 0xff /* mov cx,ffffh */ \
0x30 0xc0 /* xor al,al */ \
0xf2 0xae /* repne scasb */ \
0xf7 0xd1 /* not cx */ \
0x4f /* dec di */ \
0x88 0xd8 /* mov al,bl */ \
0xfd /* std */ \
0xf2 0xae /* repne scasb */ \
0xfc /* cld */ \
0x75 0x04 /* jne L1 */ \
0x89 0xf9 /* mov cx,di */ \
0x41 /* inc cx */ \
0xa9 /* hide 2 bytes */ \
0x8e 0xc1 /* L1: mov es,cx */ \
parm caller [es di] [bl] \
value [es cx] \
modify exact [es cx ax di];
#endif
#endif
 
/* Locate the last occurrence of c in the string pointed to by s.
The terminating null character is considered to be part of the string.
If the character c is not found, NULL is returned.
*/
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple_wcsrchr( const CHAR_TYPE *s, INTCHAR_TYPE c )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strrchr,wcsrchr)( const CHAR_TYPE *s, INTCHAR_TYPE c )
#endif
{
#if defined(M_I86) && !defined(__WIDECHAR__)
return( _fast_strrchr( s, c ) );
#else
CHAR_TYPE *p;
CHAR_TYPE cc = c;
 
p = NULL; /* assume c will not be found */
do {
if( *s == cc ) p = (CHAR_TYPE *)s;
} while( *s++ != NULLCHAR );
return( p );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strrev.c
0,0 → 1,157
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <ctype.h>
#include <string.h>
 
#if defined(__WIDECHAR__)
extern size_t wcslen( const CHAR_TYPE * );
#endif
 
#if defined(M_I86) && !defined(__WIDECHAR__)
 
/*
explanation of algorithm:
 
(1) reverse as much of the string as possible as words
 
(2) after main loop: reverse residual inner string (0-3 bytes)
 
the string falls into one of these forms:
 
{ prefix_word }* { suffix_word }*
{ prefix_word }* middle_byte { suffix_word }*
{ prefix_word }* pre_middle_byte post_middle_byte { suffix_word }*
{ prefix_word }* pre_middle_byte middle_byte post_middle_byte { suffix_word }*
 
we only have to swap two bytes when:
 
len & 2 != 0 is true (ie. the carry is set after second shr cx,1)
 
*****************************************************************************
WARNING: the code in the L1: ... reverse loop cannot modify the carry flag
*****************************************************************************
*/
 
extern void fast_rev( char *, char _WCFAR * );
 
#if defined(__SMALL_DATA__)
#pragma aux fast_rev = \
0xb9 0xff 0xff /* mov cx,ffff */\
0x30 0xc0 /* xor al,al */\
0xf2 0xae /* repne scasb */\
0xf7 0xd1 /* not cx */\
0x49 /* dec cx */\
0xfd /* std */\
0x83 0xef 0x03 /* sub di,3 */\
0xd1 0xe9 /* shr cx,1 */\
0xd1 0xe9 /* shr cx,1 */\
0xe3 0x0d /* jcxz L2 */\
0x8b 0x05 /* L1:mov ax,[di] */\
0x86 0xe0 /* xchg ah,al */\
0x87 0x04 /* xchg ax,[si] */\
0x86 0xe0 /* xchg ah,al */\
0xab /* stosw */\
0x46 /* inc si */\
0x46 /* inc si */\
0xe2 0xf3 /* loop L1 */\
0x73 0x07 /* L2:jnc L3 */\
0x47 /* inc di */\
0x8a 0x05 /* mov al,[di] */\
0x86 0x04 /* xchg al,[si] */\
0x88 0x05 /* mov [di],al */\
0xfc /* L3:cld */\
parm caller [si] [es di] \
value [ax] \
modify [si cx ax di];
#else
#pragma aux fast_rev = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xb9 0xff 0xff /* mov cx,ffff */\
0x30 0xc0 /* xor al,al */\
0xf2 0xae /* repne scasb */\
0xf7 0xd1 /* not cx */\
0x49 /* dec cx */\
0xfd /* std */\
0x83 0xef 0x03 /* sub di,3 */\
0xd1 0xe9 /* shr cx,1 */\
0xd1 0xe9 /* shr cx,1 */\
0xe3 0x0d /* jcxz L2 */\
0x8b 0x05 /* L1:mov ax,[di] */\
0x86 0xe0 /* xchg ah,al */\
0x87 0x04 /* xchg ax,[si] */\
0x86 0xe0 /* xchg ah,al */\
0xab /* stosw */\
0x46 /* inc si */\
0x46 /* inc si */\
0xe2 0xf3 /* loop L1 */\
0x73 0x07 /* L2:jnc L3 */\
0x47 /* inc di */\
0x8a 0x05 /* mov al,[di] */\
0x86 0x04 /* xchg al,[si] */\
0x88 0x05 /* mov [di],al */\
0xfc /* L3:cld */\
0x1f /* pop ds */ \
parm caller [dx si] [es di] \
value [ax] \
modify [si cx ax di];
#endif
 
#endif
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(strrev,_wcsrev) ( CHAR_TYPE *str ) { /* reverse characters in string */
#if defined(M_I86) && !defined(__WIDECHAR__)
fast_rev( str, (char _WCFAR *) str );
return( str );
#else
CHAR_TYPE *p1;
CHAR_TYPE *p2;
CHAR_TYPE c1;
CHAR_TYPE c2;
 
p1 = str;
p2 = p1 + __F_NAME(strlen,wcslen)( p1 ) - 1;
while( p1 < p2 ) {
c1 = *p1;
c2 = *p2;
*p1 = c2;
*p2 = c1;
++p1;
--p2;
}
return( str );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strset.c
0,0 → 1,50
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strset() and _wcsset()
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
#include "riscstr.h"
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple__wcsset( CHAR_TYPE *s, INTCHAR_TYPE c )
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strset,_wcsset)( CHAR_TYPE *s, INTCHAR_TYPE c )
#endif
{
CHAR_TYPE *p;
 
for( p = s; *p; ++p ) {
*p = c;
}
return( s );
}
/programs/develop/open watcom/trunk/clib/string/strspn.c
0,0 → 1,78
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#include "setbits.h"
 
/* The strspn function computes the length of the initial segment of the
string pointed to by str which consists entirely of characters from
the string pointed to by charset.
*/
 
 
_WCRTLINK size_t __F_NAME(strspn,wcsspn) ( const CHAR_TYPE *str, const CHAR_TYPE *charset )
{
#if defined(__WIDECHAR__)
 
const CHAR_TYPE *p1;
const CHAR_TYPE *p2;
CHAR_TYPE tc1;
CHAR_TYPE tc2;
size_t len;
 
len = 0;
for( p1 = str; tc1 = *p1; p1++, len++ ) {
for( p2 = charset; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 == NULLCHAR ) break;
}
return( len );
 
 
#else
unsigned /*char*/ tc;
unsigned char vector[32];
size_t len;
 
__setbits( vector, charset );
len = 0;
for( ; tc = (unsigned char) *str; ++str, ++len ) {
/* quit if we find any char not in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break;
}
return( len );
#endif
}
/programs/develop/open watcom/trunk/clib/string/strspnp.c
0,0 → 1,48
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(strspnp,_wcsspnp)( const CHAR_TYPE *p1, const CHAR_TYPE *p2 )
{
size_t index;
 
index = __F_NAME(strspn,wcsspn)( p1, p2 );
if( *(p1+index) != __F_NAME('\0',L'\0') ) {
return( (CHAR_TYPE*)(p1+index) );
} else {
return( NULL );
}
}
/programs/develop/open watcom/trunk/clib/string/strstr.c
0,0 → 1,113
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strstr() and wcsstr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stddef.h>
#include <string.h>
#if defined(_M_IX86)
#include <i86.h>
#endif
 
#if defined(M_I86) && !defined( __WIDECHAR__ )
 
extern int i86_memeq( const char *, const char _WCFAR *, int );
 
#define _ZFLAG (INTR_ZF<<8)
 
#if defined(__SMALL_DATA__)
 
#pragma aux i86_memeq = \
0xf3 0xa6 /* rep cmpsb */\
0x9f /* lahf */\
parm caller [si] [es di] [cx]\
value [ax] \
modify exact [si di cx ax];
 
#else
 
#pragma aux i86_memeq = \
0x1e /* push ds */ \
0x8e 0xda /* mov ds,dx */ \
0xf3 0xa6 /* rep cmpsb */\
0x9f /* lahf */\
0x1f /* pop ds */ \
parm caller [dx si] [es di] [cx]\
value [ax] \
modify exact [si di cx ax];
 
#endif
 
#define memeq( p1, p2, len ) ( i86_memeq((p1),(p2),(len)) & _ZFLAG )
 
#else
 
#define memeq( p1, p2, len ) ( memcmp((p1),(p2),(len)*CHARSIZE) == 0 )
 
#endif
 
/* Locate the first occurrence of the string pointed to by s2 in the
string pointed to by s1.
The strstr function returns a pointer to the located string, or a
null pointer if the string is not found.
*/
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(strstr,wcsstr) ( const CHAR_TYPE *s1, const CHAR_TYPE *s2 )
{
CHAR_TYPE *end_of_s1;
size_t s1len, s2len;
 
if( s2[0] == NULLCHAR ) {
return( (CHAR_TYPE *)s1 );
} else if( s2[1] == NULLCHAR ) {
return( __F_NAME(strchr,wcschr)( s1, s2[0] ) );
}
#ifdef __WIDECHAR__
end_of_s1 = (CHAR_TYPE*)s1 + wcslen( s1 );
#else
end_of_s1 = memchr( s1, NULLCHAR, ~0u );
#endif
s2len = __F_NAME(strlen,wcslen)( s2 );
for(;;) {
s1len = end_of_s1 - s1;
if( s1len < s2len ) break;
#ifdef __WIDECHAR__
s1 = wcschr( s1, *s2 ); /* find start of possible match */
#else
s1 = memchr( s1, *s2, s1len ); /* find start of possible match */
#endif
if( s1 == NULL ) break;
if( memeq( s1, s2, s2len ) ) return( (CHAR_TYPE *)s1 );
++s1;
}
return( NULL );
}
/programs/develop/open watcom/trunk/clib/string/strtok.c
0,0 → 1,139
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <stdio.h>
#include <string.h>
#include "rtdata.h"
#ifdef __WIDECHAR__
#include "nextwtok.h"
#else
#include "nexttok.h"
#endif
#include "setbits.h"
 
 
#ifdef __WIDECHAR__
_WCRTLINK wchar_t *_ustrtok( wchar_t *str, const wchar_t *charset )
{
return( wcstok( str, charset, NULL ) );
}
#endif
 
 
#ifdef __WIDECHAR__
_WCRTLINK wchar_t *wcstok( wchar_t *str, const wchar_t *charset, wchar_t **ptr )
#else
_WCRTLINK char *strtok( char *str, const char *charset )
#endif
{
#if defined(__WIDECHAR__)
CHAR_TYPE *p1;
const CHAR_TYPE *p2;
CHAR_TYPE tc1;
CHAR_TYPE tc2;
#else
unsigned /*char*/ tc;
unsigned char vector[32];
unsigned char *p1;
#endif
 
#if defined(__WIDECHAR__)
/* if necessary, continue from where we left off */
if( str == NULL ) {
if( ptr == NULL ) {
str = _RWD_nextwtok;
} else {
str = *ptr; /* use previous value */
}
if( str == NULL ) return( NULL );
}
 
/* skip characters until we reach one not in charset */
for( ; tc1 = *str; str++ ) {
for( p2 = charset; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 == NULLCHAR ) break;
}
if( tc1 == NULLCHAR ) return( NULL );
/* skip characters until we reach one in charset */
for( p1 = str; tc1 = *p1; p1++ ) {
for( p2 = charset; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 != NULLCHAR ){
*p1 = NULLCHAR; /* terminate the token */
p1++; /* start of next token */
if( ptr == NULL ) {
_RWD_nextwtok = p1;
} else {
*ptr = p1;
}
return( str );
}
}
if( ptr == NULL ) {
_RWD_nextwtok = NULL;
} else {
*ptr = NULL;
}
#else
/* if necessary, continue from where we left off */
_INITNEXTTOK
if( str == NULL ) {
str = (CHAR_TYPE*)_RWD_nexttok; /* use previous value */
if( str == NULL ) return( NULL );
}
 
__setbits( vector, charset );
for( ; tc = (unsigned char) *str; ++str ) {
/* quit if we find any char not in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break;
}
if( tc == '\0' ) return( NULL );
p1 = str;
for( ; tc = *p1; ++p1 ) {
/* quit when we find any char in charset */
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) {
*p1 = '\0'; /* terminate the token */
p1++; /* start of next token */
_RWD_nexttok = p1;
return( str );
}
}
_RWD_nexttok = NULL;
#endif
 
return( str );
}
/programs/develop/open watcom/trunk/clib/string/strtok_s.c
0,0 → 1,137
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strtok_s() - bounds-checking strtok().
*
****************************************************************************/
 
 
#include "variety.h"
#include "saferlib.h"
#include "widechar.h"
#include <string.h>
#include <wchar.h>
#include "setbits.h"
 
 
_WCRTLINK CHAR_TYPE *__F_NAME(strtok_s,wcstok_s)( CHAR_TYPE * __restrict s1,
rsize_t * __restrict s1max, const CHAR_TYPE * __restrict s2,
CHAR_TYPE ** __restrict ptr )
/****************************************************************************/
{
#ifdef __WIDECHAR__
const CHAR_TYPE *p2;
CHAR_TYPE tc2;
#else
char vector[32];
#endif
char *msg = NULL;
CHAR_TYPE *p1 = s1;
CHAR_TYPE *str;
rsize_t m;
CHAR_TYPE tc1;
 
// Verify runtime-constraints
// s1max not NULL
// s2 not NULL
// ptr not NULL
// *s1max <= RSIZE_MAX
// if s1 == NULL then *ptr != NULL
if( __check_constraint_nullptr_msg( msg, s1max ) &&
__check_constraint_nullptr_msg( msg, s2 ) &&
__check_constraint_nullptr_msg( msg, ptr ) &&
__check_constraint_maxsize_msg( msg, *s1max ) &&
((s1 != NULL) || __check_constraint_nullptr_msg( msg, *ptr )) ) {
 
/* if necessary, continue from where we left off */
if( s1 == NULL ) {
p1 = *ptr; /* use previous value */
}
#ifndef __WIDECHAR__
__setbits( vector, s2 );
#endif
m = *s1max;
for( ; tc1 = *p1; ++p1 ) {
if( ! ((m == 0) ? ( msg = "no start of token found" ), 0 : 1 ) ) {
break; /* limit reached, quit */
}
 
#ifdef __WIDECHAR__
for( p2 = s2; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 == NULLCHAR ) break;
#else
/* quit if we find any char not in charset */
if( ( vector[ tc1 >> 3 ] & _Bits[ tc1 & 0x07 ] ) == 0 ) break;
#endif
--m;
}
 
if( msg == NULL ) { /* no rt-constraint violated */
if( tc1 == NULLCHAR ) return( NULL ); /* no (more) tokens */
} else {
/* Now call the handler */
__rtct_fail( __func__, msg, NULL );
return( NULL );
}
 
str = p1++; /* start of token */
 
for( ; tc1 = *p1; p1++ ) {
if( ! ((m == 0) ? ( msg = "no closing token delimiter found" ), 0 : 1 ) ) {
break; /* limit reached, quit */
}
 
--m;
 
/* skip characters until we reach one in delimiterset */
#ifdef __WIDECHAR__
for( p2 = s2; tc2 = *p2; p2++ ) {
if( tc1 == tc2 ) break;
}
if( tc2 != NULLCHAR ) {
#else
if( ( vector[ tc1 >> 3 ] & _Bits[ tc1 & 0x07 ] ) != 0 ) {
#endif
*p1 = NULLCHAR; /* terminate the token */
p1++; /* start of next token */
*ptr = p1;
*s1max = m;
return( str );
}
}
}
if( msg != NULL ) { /* rt-constraint violated */
/* Now call the handler */
__rtct_fail( __func__, msg, NULL );
return( NULL );
} else {
*ptr = NULL; /* last token reached */
*s1max = 0;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/strupr.c
0,0 → 1,59
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of strupr().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <ctype.h>
#include <string.h>
#include "riscstr.h"
 
 
#if defined(__RISCSTR__) && defined(__WIDECHAR__)
_WCRTLINK CHAR_TYPE *__simple__wcsupr( CHAR_TYPE *str ) {
#else
_WCRTLINK CHAR_TYPE *__F_NAME(strupr,_wcsupr)( CHAR_TYPE *str ) {
#endif
CHAR_TYPE *p;
UCHAR_TYPE c;
 
p = str;
while( (c = *p) ) {
if( IS_ASCII( c ) ) {
c -= 'a';
if( c <= 'z' - 'a' ) {
c += 'A';
*p = c;
}
}
++p;
}
return( str );
}
/programs/develop/open watcom/trunk/clib/string/strxfrm.c
0,0 → 1,55
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <string.h>
 
/* Transform the string so that two transformed strings can be properly
compared in the current locale.
We only support the "C" locale, so just copy the string.
*/
 
_WCRTLINK size_t __F_NAME(strxfrm,wcsxfrm)( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t n )
{
size_t len;
 
len = 0;
for(;;) {
if( len < n ) *dst = *src;
if( *src == __F_NAME('\0',L'\0') ) break;
++src;
++dst;
++len;
}
return( len );
}