/programs/develop/open watcom/trunk/clib/src/_clsewnt.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 <stdio.h> |
#include <errno.h> |
#include "fileacc.h" |
//#include <windows.h> |
#include "rtcheck.h" |
#include "rtdata.h" |
#include "iomode.h" |
#include "seterrno.h" |
//#include "defwin.h" |
#include "close.h" |
int __close( int hid ) |
{ |
int is_closed; |
int rc; |
HANDLE h; |
__handle_check( hid, -1 ); |
is_closed = 0; |
rc = 0; |
// h = __getOSHandle( hid ); |
// if( !is_closed && !CloseHandle( h ) ) |
// { |
// rc = __set_errno_nt(); |
// } |
// __freePOSIXHandle( hid ); |
// __SetIOMode_nogrow( hid, 0 ); |
return( rc ); |
} |
/programs/develop/open watcom/trunk/clib/src/abs.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: Implementation of abs(). |
* |
****************************************************************************/ |
#undef __INLINE_FUNCTIONS__ |
#include "variety.h" |
#include <stdlib.h> |
_WCRTLINK int abs( int i ) |
/************************/ |
{ |
if( i < 0 ) |
i = - i; |
return( i ); |
} |
/programs/develop/open watcom/trunk/clib/src/alphabet.c |
---|
0,0 → 1,33 |
/**************************************************************************** |
* |
* 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: Shared alphabet array for conversion of integers to ASCII. |
* |
****************************************************************************/ |
const char __based(__segname("_CONST")) __Alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/atoi.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#ifdef __WIDECHAR__ |
#include <wctype.h> |
#else |
#include <ctype.h> |
#endif |
_WCRTLINK int __F_NAME(atoi,_wtoi)( const CHAR_TYPE *p ) /* convert ASCII string to integer */ |
{ |
register int value; |
CHAR_TYPE sign; |
__ptr_check( p, 0 ); |
while( __F_NAME(isspace,iswspace)( *p ) ) ++p; |
sign = *p; |
if( sign == '+' || sign == '-' ) ++p; |
value = 0; |
while( __F_NAME(isdigit,iswdigit)(*p) ) { |
value = value * 10 + *p - '0'; |
++p; |
} |
if( sign == '-' ) value = - value; |
return( value ); |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/chipa32.asm |
---|
0,0 → 1,397 |
;***************************************************************************** |
;* |
;* 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! |
;* |
;***************************************************************************** |
; static char sccs_id[] = "@(#)fpatan32.asm 1.7 12/21/94 08:33:45"; |
; |
; This code is being published by Intel to users of the Pentium(tm) |
; processor. Recipients are authorized to copy, modify, compile, use and |
; distribute the code. |
; |
; Intel makes no warranty of any kind with regard to this code, including |
; but not limited to, implied warranties or merchantability and fitness for |
; a particular purpose. Intel assumes no responsibility for any errors that |
; may appear in this code. |
; |
; No patent licenses are granted, express or implied. |
; |
; |
include mdef.inc |
.386 |
.387 |
_TEXT SEGMENT PARA PUBLIC USE32 'CODE' |
_TEXT ENDS |
CONST SEGMENT DWORD PUBLIC USE32 'DATA' |
CONST ENDS |
CONST2 SEGMENT DWORD PUBLIC USE32 'DATA' |
CONST2 ENDS |
DATA32 SEGMENT DWORD PUBLIC USE32 'DATA' |
Y EQU 0 |
X EQU 12 |
PREV_CW EQU 24 |
PATCH_CW EQU 28 |
SPILL EQU 32 |
STACK_SIZE EQU 36 |
pos_1 DD 00000000H |
DD 3ff00000H |
neg_1 DD 00000000H |
DD 0bff00000H |
dispatch_table DD offset label0 |
DD offset label1 |
DD offset label2 |
DD offset label3 |
DD offset label4 |
DD offset label5 |
DD offset label6 |
DD offset label7 |
;end dispatch table |
pi DB 35H |
DB 0c2H |
DD 0daa22168H |
DD 4000c90fH |
pi_by_2 DB 35H |
DB 0c2H |
DD 0daa22168H |
DD 3fffc90fH |
flt_sixteen DD 41800000H |
one_by_sixteen DD 3d800000H |
B1 DW 0AAA8H |
DD 0AAAAAAAAH |
DD 0BFFDAAAAH |
B2 DW 2D6EH |
DD 0CCCCCCCCH |
DD 3FFCCCCCH |
B3 DW 4892H |
DD 249241F9H |
DD 0BFFC9249H |
B4 DW 0C592H |
DD 3897CDECH |
DD 3FFBE38EH |
B5 DW 5DDDH |
DD 0C17BC162H |
DD 0BFFBBA2DH |
B6 DW 4854H |
DD 77C7C78EH |
DD 3FFB9C80H |
atan_k_by_16 dd 000000000H, 000000000H, 000000000H, 000000000H |
dd 067EF4E37H, 0FFAADDB9H, 000003FFAH, 000000000H |
dd 0617B6E33H, 0FEADD4D5H, 000003FFBH, 000000000H |
dd 072D81135H, 0BDCBDA5EH, 000003FFCH, 000000000H |
dd 06406EB15H, 0FADBAFC9H, 000003FFCH, 000000000H |
dd 03F5E5E6AH, 09B13B9B8H, 000003FFDH, 000000000H |
dd 026F78474H, 0B7B0CA0FH, 000003FFDH, 000000000H |
dd 0611FE5B6H, 0D327761EH, 000003FFDH, 000000000H |
dd 00DDA7B45H, 0ED63382BH, 000003FFDH, 000000000H |
dd 0D9867E2AH, 0832BF4A6H, 000003FFEH, 000000000H |
dd 0F7F59F9BH, 08F005D5EH, 000003FFEH, 000000000H |
dd 071BDDA20H, 09A2F80E6H, 000003FFEH, 000000000H |
dd 034F70924H, 0A4BC7D19H, 000003FFEH, 000000000H |
dd 0B4D8C080H, 0AEAC4C38H, 000003FFEH, 000000000H |
dd 0C2319E74H, 0B8053E2BH, 000003FFEH, 000000000H |
dd 0AC526641H, 0C0CE85B8H, 000003FFEH, 000000000H |
dd 02168C235H, 0C90FDAA2H, 000003FFEH, 000000000H |
DATA32 ENDS |
BSS32 SEGMENT DWORD PUBLIC USE32 'BSS' |
BSS32 ENDS |
EXTRN __fdiv_fpr:NEAR |
DGROUP GROUP CONST,CONST2,DATA32,BSS32 |
_TEXT SEGMENT PARA PUBLIC USE32 'CODE' |
ASSUME CS:_TEXT,DS:DGROUP,ES:DGROUP, SS:nothing |
public __fpatan_chk |
defpe __fpatan_chk |
push eax |
push ecx |
push edx |
sub esp, STACK_SIZE |
fstp tbyte ptr [esp+X] ; save X |
fstp tbyte ptr [esp+Y] ; save Y |
mov ecx, [esp+Y+4] |
add ecx, ecx |
jnc hw_fpatan ; unnormals (explicit 1 missing) |
mov eax, [esp+X+4] |
add eax, eax |
jnc hw_fpatan ; unnormals (explicit 1 missing) |
mov ecx, [esp+Y+8] ; save high part of Y |
mov eax, [esp+X+8] ; save high part of Y |
and ecx, 7fffh ; Ey = exponent Y |
jz hw_fpatan ; Ey = 0 |
and eax, 7fffh ; Ex = exponent X |
jz hw_fpatan ; Ex = 0 |
cmp ecx, 7fffh ; check if Ey = 0x7fffh |
je hw_fpatan |
cmp eax, 7fffh ; check if Ex = 0x7fffh |
je hw_fpatan |
fld tbyte ptr [esp+X] ; reload X |
fabs ; |X| = u |
fld tbyte ptr [esp+Y] ; reload Y |
fabs ; |Y| = v |
; The following five lines turn off exceptions and set the |
; precision control to 80 bits. The former is necessary to |
; force any traps to be taken at the divide instead of the scaling |
; code. The latter is necessary in order to get full precision for |
; codes with incoming 32 and 64 bit precision settings. If |
; it can be guaranteed that before reaching this point, the underflow |
; exception is masked and the precision control is at 80 bits, these |
; five lines can be omitted. |
; |
fnstcw [PREV_CW+esp] ; save caller's control word |
mov edx, [PREV_CW+esp] |
or edx, 033fh ; mask exceptions, pc=80 |
and edx, 0f3ffh |
mov [PATCH_CW+esp], edx |
fldcw [PATCH_CW+esp] ; mask exceptions & pc=80 |
xor edx, edx ; initialize sflag = 0 |
fcom ; |Y| > |x| |
push eax |
fstsw ax |
sahf |
pop eax |
jb order_X_Y_ok |
fxch |
inc edx ; sflag = 1 |
order_X_Y_ok: |
push eax |
mov eax, 0fh |
call __fdiv_fpr ; v/u = z |
pop eax |
fld dword ptr flt_sixteen ; 16.0 |
fmul st, st(1) ; z*16.0 |
; Top of stack looks like k, z |
fistp dword ptr [SPILL+esp] ; store k as int |
mov ecx, [SPILL+esp] |
shl ecx, 4 |
fild dword ptr[SPILL+esp] |
fmul dword ptr one_by_sixteen; 1.0/16.0 |
; Top of stack looks like g, z |
fld st(1) ; duplicate g |
fsub st, st(1) ; z-g = r |
fxch |
; Top of stack looks like g, r, z |
fmulp st(2), st ; g*z |
; Top of stack looks like r, g*z |
fld qword ptr pos_1 ; load 1.0 |
faddp st(2), st ; 1+g*z |
; Top of stack looks like r, 1+g*z |
push eax |
mov eax, 0fh |
call __fdiv_fpr ; v/u = z |
pop eax |
fld st(0) ; duplicate s |
fmul st,st(1) ; t = s*s |
; Top of stack looks like t, s |
fld st(0) |
fmul st, st(1) |
; Top of stack looks like t2, t, s |
fld st(0) |
fmul st, st(1) |
fld tbyte ptr B6 |
fld tbyte ptr B5 |
; Top of stack looks like B5, B6, t4, t2, t, s |
fxch |
fmul st, st(2) |
fld tbyte ptr B4 |
fxch st(2) |
fmul st, st(3) |
; Top of stack looks like B5t4, B6t4, B4, t4, t2, t, s |
fld tbyte ptr B3 |
fxch st(2) |
fmul st, st(5) |
; Top of stack looks like B6t6, B5t4, B3, B4, t4, t2, t, s |
fxch st(3) |
fmulp st(4), st |
fld tbyte ptr B2 |
; Top of stack looks like B2, B5t4, B3, B6t6, B4t4, t2, t, s |
fxch st(3) |
faddp st(4), st |
mov eax, [esp+X+8] |
fld tbyte ptr B1 |
fxch |
shl eax, 16 |
; Top of stack looks like B5t4, B1, B3, B2, even, t2, t, s |
fmul st, st(6) |
fxch st(2) |
add eax, eax |
fmul st, st(5) |
; Top of stack looks like B3t2, B1, B5t5, B2, even, t2, t, s |
fxch st(3) |
adc edx, edx ; |sflag|Sx| |
fmulp st(5), st |
fxch st(2) |
mov eax, [Y+8+esp] ; save high part of Y |
fmul st, st(5) |
; Top of stack looks like B3t3, B5t5, B1, even, B2t2, t, s |
fxch st(2) |
shl eax, 16 |
fmulp st(5), st |
; Top of stack looks like B5t5, B3t3, even, B2t2, B1t, s |
fxch st(2) |
faddp st(3), st |
add eax, eax |
faddp st(1), st |
adc edx, edx ; |sflag|Sx|Sy| |
; Top of stack looks like odd, even, B1t, s |
faddp st(2), st |
faddp st(1), st |
fmul st,st(1) ; s*(odd+even) |
faddp st(1), st ; poly |
fld tbyte ptr atan_k_by_16[ecx] ; arctan[k;16] |
faddp st(1), st ; w = poly + arctan(g) |
jmp dword ptr dispatch_table[edx*4] |
label0: |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label1: |
fchs |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label2: |
fld tbyte ptr pi |
fsubrp st(1), st ; pi - w |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label3: |
fld tbyte ptr pi |
fsubrp st(1), st ; pi - w |
fchs ; - (pi - w) |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label4: |
fld tbyte ptr pi_by_2 |
fsubrp st(1), st ; pi/2 - w |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label5: |
fld tbyte ptr pi_by_2 |
fsubrp st(1), st ; pi/2 - w |
fchs ; - (pi/2 - w) |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label6: |
fld tbyte ptr pi_by_2 |
faddp st(1), st ; pi/2 + w |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
label7: |
fld tbyte ptr pi_by_2 |
faddp st(1), st ; pi/2 + w |
fchs ; -(pi/2+w) |
fldcw [esp+PREV_CW] |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
hw_fpatan: |
fld tbyte ptr [esp+Y] ; reload Y |
fld tbyte ptr [esp+X] ; reload X |
fpatan |
add esp, STACK_SIZE |
pop edx |
pop ecx |
pop eax |
ret |
__fpatan_chk ENDP |
_TEXT ENDS |
END |
/programs/develop/open watcom/trunk/clib/src/chipbug.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: verify Pentium processor divide bug |
* |
****************************************************************************/ |
#include "variety.h" |
#include "rtinit.h" |
#include "rtdata.h" |
extern unsigned _WCNEAR __chipbug; |
enum { |
PROB_P5_DIV = 0x0001 |
}; |
_WCRTLINK void __verify_pentium_fdiv_bug() |
{ |
/* |
Verify we have got the Pentium FDIV problem. |
The volatiles are to scare the optimizer away. |
*/ |
volatile double num = 4195835; |
volatile double denom = 3145727; |
if( _RWD_real87 >= 3 ) { |
if( (num - (num/denom)*denom) > 1.0e-8 ) { |
__chipbug |= PROB_P5_DIV; |
} |
} |
} |
AXI( __verify_pentium_fdiv_bug, INIT_PRIORITY_FPU + 4 ); |
/programs/develop/open watcom/trunk/clib/src/chipd32.asm |
---|
0,0 → 1,991 |
;***************************************************************************** |
;* |
;* 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! |
;* |
;***************************************************************************** |
; static char sccs_id[] = "@(#)patch32.asm 1.12 12/21/94 14:53:51"; |
; |
; This code is being published by Intel to users of the Pentium(tm) |
; processor. Recipients are authorized to copy, modify, compile, use and |
; distribute the code. |
; |
; Intel makes no warranty of any kind with regard to this code, including |
; but not limited to, implied warranties or merchantability and fitness for |
; a particular purpose. Intel assumes no responsibility for any errors that |
; may appear in this code. |
; |
; No patent licenses are granted, express or implied. |
; |
; |
include mdef.inc |
.386 |
.387 |
DENOM EQU 0 |
NUMER EQU 12 |
PREV_CW EQU 28 ; 24 + 4 (return size) |
PATCH_CW EQU 32 ; 28 + 4 (return size) |
DENOM_SAVE EQU 32 |
MAIN_DENOM EQU 4 |
MAIN_NUMER EQU 16 |
SPILL_SIZE EQU 12 |
MEM_OPERAND EQU 8 |
STACK_SIZE EQU 44 |
SPILL_MEM_OPERAND EQU 20 |
ONESMASK EQU 0e000000h |
SINGLE_NAN EQU 07f800000h |
DOUBLE_NAN EQU 07ff00000h |
ILLEGAL_OPC EQU 6 |
f_stsw macro where |
fstsw where |
endm |
fdivr_st MACRO reg_index, reg_index_minus1 |
fstp tbyte ptr [esp+DENOM] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fstp tbyte ptr [esp+NUMER] |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld tbyte ptr [esp+NUMER] |
fxch st(reg_index) |
add esp, STACK_SIZE |
ENDM |
fdivr_sti MACRO reg_index, reg_index_minus1 |
fstp tbyte ptr [esp+NUMER] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fstp tbyte ptr [esp+DENOM] |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld tbyte ptr [esp+NUMER] |
add esp, STACK_SIZE |
ENDM |
fdivrp_sti MACRO reg_index, reg_index_minus1 |
fstp tbyte ptr [esp+NUMER] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fstp tbyte ptr [esp+DENOM] |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
add esp, STACK_SIZE |
ENDM |
fdiv_st MACRO reg_index, reg_index_minus1 |
fstp tbyte ptr [esp+NUMER] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld st |
fstp tbyte ptr [esp+DENOM] |
fstp tbyte ptr [esp+DENOM_SAVE] ; save original denom, |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld tbyte ptr [esp+DENOM_SAVE] |
fxch st(reg_index) |
add esp, STACK_SIZE |
ENDM |
fdiv_sti MACRO reg_index, reg_index_minus1 |
fxch st(reg_index) |
fstp tbyte ptr [esp+NUMER] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld st |
fstp tbyte ptr [esp+DENOM] |
fstp tbyte ptr [esp+DENOM_SAVE] ; save original denom, |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fld tbyte ptr [esp+DENOM_SAVE] |
add esp, STACK_SIZE |
ENDM |
fdivp_sti MACRO reg_index, reg_index_minus1 |
fstp tbyte ptr [esp+DENOM] |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
fstp tbyte ptr [esp+NUMER] |
call fdiv_main_routine |
IF reg_index_minus1 GE 1 |
fxch st(reg_index_minus1) |
ENDIF |
add esp, STACK_SIZE |
ENDM |
_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' |
_TEXT ENDS |
DATA32 SEGMENT DWORD USE32 PUBLIC 'DATA' |
DATA32 ENDS |
CONST32 SEGMENT DWORD USE32 PUBLIC 'CONST' |
CONST32 ENDS |
BSS32 SEGMENT DWORD USE32 PUBLIC 'BSS' |
BSS32 ENDS |
DGROUP GROUP CONST32, BSS32, DATA32 |
DATA32 SEGMENT DWORD USE32 PUBLIC 'DATA' |
fdiv_risc_table DB 0, 1, 0, 0, 4, 0, 0, 7, 0, 0, 10, 0, 0, 13, 0, 0 |
fdiv_scale_1 DD 03f700000h ;0.9375 |
fdiv_scale_2 DD 03f880000h ;1.0625 |
one_shl_63 DD 05f000000h |
dispatch_table DD offset label0 |
DD offset label1 |
DD offset label2 |
DD offset label3 |
DD offset label4 |
DD offset label5 |
DD offset label6 |
DD offset label7 |
DD offset label8 |
DD offset label9 |
DD offset label10 |
DD offset label11 |
DD offset label12 |
DD offset label13 |
DD offset label14 |
DD offset label15 |
DD offset label16 |
DD offset label17 |
DD offset label18 |
DD offset label19 |
DD offset label20 |
DD offset label21 |
DD offset label22 |
DD offset label23 |
DD offset label24 |
DD offset label25 |
DD offset label26 |
DD offset label27 |
DD offset label28 |
DD offset label29 |
DD offset label30 |
DD offset label31 |
DD offset label32 |
DD offset label33 |
DD offset label34 |
DD offset label35 |
DD offset label36 |
DD offset label37 |
DD offset label38 |
DD offset label39 |
DD offset label40 |
DD offset label41 |
DD offset label42 |
DD offset label43 |
DD offset label44 |
DD offset label45 |
DD offset label46 |
DD offset label47 |
DD offset label48 |
DD offset label49 |
DD offset label50 |
DD offset label51 |
DD offset label52 |
DD offset label53 |
DD offset label54 |
DD offset label55 |
DD offset label56 |
DD offset label57 |
DD offset label58 |
DD offset label59 |
DD offset label60 |
DD offset label61 |
DD offset label62 |
DD offset label63 |
DATA32 ENDS |
_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' |
assume cs:_TEXT, ds:DGROUP, es:DGROUP, ss:nothing |
; |
; PRELIMINARY VERSION for register-register divides. |
; |
; In this implementation the |
; fdiv_main_routine is called, |
; therefore all the stack frame |
; locations are adjusted for the |
; return pointer. |
fdiv_main_routine PROC NEAR |
fld tbyte ptr [esp+MAIN_NUMER] ; load the numerator |
fld tbyte ptr [esp+MAIN_DENOM] ; load the denominator |
retry: |
; The following three lines test for denormals and zeros. |
; A denormal or zero has a 0 in the explicit digit to the left of the |
; binary point. Since that bit is the high bit of the word, adding |
; it to itself will produce a carry if and only if the number is not |
; denormal or zero. |
; |
mov eax, [esp+MAIN_DENOM+4] ; get mantissa bits 32-64 |
add eax,eax ; shift the one's bit onto carry |
jnc denormal ; if no carry, we're denormal |
; The following three lines test the three bits after the four bit |
; pattern (1,4,7,a,d). If these three bits are not all one, then |
; the denominator cannot expose the flaw. This condition is tested by |
; inverting the bits and testing that all are equal to zero afterward. |
xor eax, ONESMASK ; invert the bits that must be ones |
test eax, ONESMASK ; and make sure they are all ones |
jz scale_if_needed ; if all are one scale numbers |
fdivp st(1), st ; use of hardware is OK. |
ret |
; |
; Now we test the four bits for one of the five patterns. |
; |
scale_if_needed: |
shr eax, 28 ; keep first 4 bits after point |
cmp byte ptr fdiv_risc_table[eax], 0 ; check for (1,4,7,a,d) |
jnz divide_scaled ; are in potential problem area |
fdivp st(1), st ; use of hardware is OK. |
ret |
divide_scaled: |
mov eax, [esp + MAIN_DENOM+8] ; test denominator exponent |
and eax, 07fffh ; if pseudodenormal ensure that only |
jz invalid_denom ; invalid exception flag is set |
cmp eax, 07fffh ; if NaN or infinity ensure that only |
je invalid_denom ; invalid exception flag is set |
; |
; The following six lines turn off exceptions and set the |
; precision control to 80 bits. The former is necessary to |
; force any traps to be taken at the divide instead of the scaling |
; code. The latter is necessary in order to get full precision for |
; codes with incoming 32 and 64 bit precision settings. If |
; it can be guaranteed that before reaching this point, the underflow |
; exception is masked and the precision control is at 80 bits, these |
; six lines can be omitted. |
; |
fnstcw [esp+PREV_CW] ; save caller's control word |
mov eax, [esp+PREV_CW] |
or eax, 033fh ; mask exceptions, pc=80 |
and eax, 0f3ffh ; set rounding mode to nearest |
mov [esp+PATCH_CW], eax |
fldcw [esp+PATCH_CW] ; mask exceptions & pc=80 |
; The following lines check the numerator exponent before scaling. |
; This in order to prevent undeflow when scaling the numerator, |
; which will cause a denormal exception flag to be set when the |
; actual divide is preformed. This flag would not have been set |
; normally. If there is a risk of underflow, the scale factor is |
; 17/16 instead of 15/16. |
; |
mov eax, [esp+MAIN_NUMER+8] ; test numerator exponent |
and eax, 07fffh |
cmp eax, 00001h |
je small_numer |
fmul fdiv_scale_1 ; scale denominator by 15/16 |
fxch |
fmul fdiv_scale_1 ; scale numerator by 15/16 |
fxch |
; |
; The next line restores the users control word. If the incoming |
; control word had the underflow exception masked and precision |
; control set to 80 bits, this line can be omitted. |
; |
fldcw [esp+PREV_CW] ; restore caller's control word |
fdivp st(1), st ; use of hardware is OK. |
ret |
small_numer: |
fmul fdiv_scale_2 ; scale denominator by 17/16 |
fxch |
fmul fdiv_scale_2 ; scale numerator by 17/16 |
fxch |
; |
; The next line restores the users control word. If the incoming |
; control word had the underflow exception masked and precision |
; control set to 80 bits, this line can be omitted. |
; |
fldcw [esp+PREV_CW] ; restore caller's control word |
fdivp st(1), st ; use of hardware is OK. |
ret |
denormal: |
mov eax, [esp+MAIN_DENOM] ; test for whole mantissa == 0 |
or eax, [esp+MAIN_DENOM+4] ; test for whole mantissa == 0 |
jnz denormal_divide_scaled ; denominator is not zero |
invalid_denom: ; zero or invalid denominator |
fdivp st(1), st ; use of hardware is OK. |
ret |
denormal_divide_scaled: |
mov eax, [esp + MAIN_DENOM + 8] ; get exponent |
and eax, 07fffh ; check for zero exponent |
jnz invalid_denom ; |
; |
; The following six lines turn off exceptions and set the |
; precision control to 80 bits. The former is necessary to |
; force any traps to be taken at the divide instead of the scaling |
; code. The latter is necessary in order to get full precision for |
; codes with incoming 32 and 64 bit precision settings. If |
; it can be guaranteed that before reaching this point, the underflow |
; exception is masked and the precision control is at 80 bits, these |
; five lines can be omitted. |
; |
fnstcw [esp+PREV_CW] ; save caller's control word |
mov eax, [esp+PREV_CW] |
or eax, 033fh ; mask exceptions, pc=80 |
and eax, 0f3ffh ; set rounding mode to nearest |
mov [esp+PATCH_CW], eax |
fldcw [esp+PATCH_CW] ; mask exceptions & pc=80 |
mov eax, [esp + MAIN_NUMER +8] ; test numerator exponent |
and eax, 07fffh ; check for denormal numerator |
je denormal_numer |
cmp eax, 07fffh ; NaN or infinity |
je invalid_numer |
mov eax, [esp + MAIN_NUMER + 4] ; get bits 32..63 of mantissa |
add eax, eax ; shift the first bit into carry |
jnc invalid_numer ; if there is no carry, we have an |
; invalid numer |
jmp numer_ok |
denormal_numer: |
mov eax, [esp + MAIN_NUMER + 4] ; get bits 32..63 of mantissa |
add eax, eax ; shift the first bit into carry |
jc invalid_numer ; if there is a carry, we have an |
; invalid numer |
numer_ok: |
fxch |
fstp st ; pop numerator |
fld st ; make copy of denominator |
fmul dword ptr[one_shl_63] ; make denominator not denormal |
fstp tbyte ptr [esp+MAIN_DENOM] ; save modified denominator |
fld tbyte ptr [esp+MAIN_NUMER] ; load numerator |
fxch ; restore proper order |
fwait |
; The next line restores the users control word. If the incoming |
; control word had the underflow exception masked and precision |
; control set to 80 bits, this line can be omitted. |
; |
fldcw [esp+PREV_CW] ; restore caller's control word |
jmp retry ; start the whole thing over |
invalid_numer: |
; |
; The next line restores the users control word. If the incoming |
; control word had the underflow exception masked and precision |
; control set to 80 bits, this line can be omitted. |
; |
fldcw [esp + PREV_CW] |
fdivp st(1), st ; use of hardware is OK. |
ret |
fdiv_main_routine ENDP |
public __fdiv_fpr |
defpe __fdiv_fpr |
sub esp, STACK_SIZE |
jmp dword ptr dispatch_table[eax*4] |
label0: |
fdiv st,st(0) ; D8 F0 FDIV ST,ST(0) |
add esp, STACK_SIZE |
ret |
label1: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label2: |
fdivr st,st(0) ; D8 F8 FDIVR ST,ST(0) |
add esp, STACK_SIZE |
ret |
label3: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label4: |
fdiv st(0),st ; DC F8/D8 F0 FDIV ST(0),ST |
add esp, STACK_SIZE |
ret |
label5: |
fdivp st(0),st ; DE F8 FDIVP ST(0),ST |
add esp, STACK_SIZE |
ret |
label6: |
fdivr st(0),st ; DC F0/DE F0 FDIVR ST(0),ST |
add esp, STACK_SIZE |
ret |
label7: |
fdivrp st(0),st ; DE F0 FDIVRP ST(0),ST |
add esp, STACK_SIZE |
ret |
label8: |
fdiv_st 1, 0 |
ret |
label9: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label10: |
fdivr_st 1, 0 |
ret |
label11: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label12: |
fdiv_sti 1, 0 |
ret |
label13: |
fdivp_sti 1, 0 |
ret |
label14: |
fdivr_sti 1, 0 |
ret |
label15: |
fdivrp_sti 1, 0 |
ret |
label16: |
fdiv_st 2, 1 |
ret |
label17: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label18: |
fdivr_st 2, 1 |
ret |
label19: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label20: |
fdiv_sti 2, 1 |
ret |
label21: |
fdivp_sti 2, 1 |
ret |
label22: |
fdivr_sti 2, 1 |
ret |
label23: |
fdivrp_sti 2, 1 |
ret |
label24: |
fdiv_st 3, 2 |
ret |
label25: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label26: |
fdivr_st 3, 2 |
ret |
label27: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label28: |
fdiv_sti 3, 2 |
ret |
label29: |
fdivp_sti 3, 2 |
ret |
label30: |
fdivr_sti 3, 2 |
ret |
label31: |
fdivrp_sti 3, 2 |
ret |
label32: |
fdiv_st 4, 3 |
ret |
label33: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label34: |
fdivr_st 4, 3 |
ret |
label35: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label36: |
fdiv_sti 4, 3 |
ret |
label37: |
fdivp_sti 4, 3 |
ret |
label38: |
fdivr_sti 4, 3 |
ret |
label39: |
fdivrp_sti 4, 3 |
ret |
label40: |
fdiv_st 5, 4 |
ret |
label41: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label42: |
fdivr_st 5, 4 |
ret |
label43: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label44: |
fdiv_sti 5, 4 |
ret |
label45: |
fdivp_sti 5, 4 |
ret |
label46: |
fdivr_sti 5, 4 |
ret |
label47: |
fdivrp_sti 5, 4 |
ret |
label48: |
fdiv_st 6, 5 |
ret |
label49: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label50: |
fdivr_st 6, 5 |
ret |
label51: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label52: |
fdiv_sti 6, 5 |
ret |
label53: |
fdivp_sti 6, 5 |
ret |
label54: |
fdivr_sti 6, 5 |
ret |
label55: |
fdivrp_sti 6, 5 |
ret |
label56: |
fdiv_st 7, 6 |
ret |
label57: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label58: |
fdivr_st 7, 6 |
ret |
label59: |
add esp, STACK_SIZE |
int ILLEGAL_OPC |
label60: |
fdiv_sti 7, 6 |
ret |
label61: |
fdivp_sti 7, 6 |
ret |
label62: |
fdivr_sti 7, 6 |
ret |
label63: |
fdivrp_sti 7, 6 |
ret |
__fdiv_fpr ENDP |
__fdivp_sti_st PROC NEAR |
; for calling from mem routines |
sub esp, STACK_SIZE |
fdivp_sti 1, 0 |
ret |
__fdivp_sti_st ENDP |
__fdivrp_sti_st PROC NEAR |
; for calling from mem routines |
sub esp, STACK_SIZE |
fdivrp_sti 1, 0 |
ret |
__fdivrp_sti_st ENDP |
public __fdiv_chk |
defpe __fdiv_chk |
; for calling from mem routines |
sub esp, STACK_SIZE |
fdivrp_sti 1, 0 |
ret |
__fdiv_chk ENDP |
; |
; PRELIMINARY VERSIONS of the routines for register-memory |
; divide instructions |
; |
;;; FDIV_M32 - FDIV m32real FIX |
;; |
;; Input : Value of the m32real in the top of STACK |
;; |
;; Output: Result of FDIV in ST |
PUBLIC __fdiv_m32 |
defpe __fdiv_m32 |
push eax ; save eax |
mov eax, [esp + MEM_OPERAND] ; check for |
and eax, SINGLE_NAN ; NaN |
cmp eax, SINGLE_NAN ; |
je memory_divide_m32 ; |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack ; is FP stack full? |
fld dword ptr[esp + MEM_OPERAND] ; load m32real in ST |
call __fdivp_sti_st ; do actual divide |
pop eax |
ret 4 |
spill_fpstack: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fld dword ptr[esp + SPILL_MEM_OPERAND] ; load m32 real |
call __fdivp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivrp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret 4 |
memory_divide_m32: |
fdiv dword ptr[esp + MEM_OPERAND] ; do actual divide |
pop eax |
ret 4 |
__fdiv_m32 ENDP |
;;; FDIV_M64 - FDIV m64real FIX |
;; |
;; Input : Value of the m64real in the top of STACK |
;; |
;; Output: Result of FDIV in ST |
PUBLIC __fdiv_m64 |
defpe __fdiv_m64 |
push eax ; save eax |
mov eax, [esp + MEM_OPERAND + 4] ; check for |
and eax, DOUBLE_NAN ; NaN |
cmp eax, DOUBLE_NAN ; |
je memory_divide_m64 ; |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m64 ; is FP stack full? |
fld qword ptr[esp + MEM_OPERAND] ; load m64real in ST |
call __fdivp_sti_st ; do actual divide |
pop eax |
ret 8 |
spill_fpstack_m64: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp] ; save user's ST(1) |
fld qword ptr[esp + SPILL_MEM_OPERAND] ; load m64real |
call __fdivp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivrp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret 8 |
memory_divide_m64: |
fdiv qword ptr[esp + MEM_OPERAND] ; do actual divide |
pop eax |
ret 8 |
__fdiv_m64 ENDP |
;;; FDIVR_M32 - FDIVR m32real FIX |
;; |
;; Input : Value of the m32real in the top of STACK |
;; |
;; Output: Result of FDIVR in ST |
PUBLIC __fdiv_m32r |
defpe __fdiv_m32r |
push eax ; save eax |
mov eax, [esp + MEM_OPERAND] ; check for |
and eax, SINGLE_NAN ; NaN |
cmp eax, SINGLE_NAN ; |
je memory_divide_m32r ; |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m32r ; is FP stack full? |
fld dword ptr[esp + MEM_OPERAND] ; load m32real in ST |
call __fdivrp_sti_st ; do actual divide |
pop eax |
ret 4 |
spill_fpstack_m32r: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fld dword ptr[esp + SPILL_MEM_OPERAND] ; load m32 real |
call __fdivrp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret 4 |
memory_divide_m32r: |
fdivr dword ptr[esp + MEM_OPERAND] ; do actual divide |
pop eax |
ret 4 |
__fdiv_m32r ENDP |
;;; FDIVR_M64 - FDIVR m64real FIX |
;; |
;; Input : Value of the m64real in the top of STACK |
;; |
;; Output: Result of FDIVR in ST |
PUBLIC __fdiv_m64r |
defpe __fdiv_m64r |
push eax ; save eax |
mov eax, [esp + MEM_OPERAND + 4] ; check for |
and eax, DOUBLE_NAN ; NaN |
cmp eax, DOUBLE_NAN ; |
je memory_divide_m64r ; |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m64r ; is FP stack full? |
fld qword ptr[esp + MEM_OPERAND] ; load m64real in ST |
call __fdivrp_sti_st ; do actual divide |
pop eax |
ret 8 |
spill_fpstack_m64r: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fld qword ptr[esp + SPILL_MEM_OPERAND] ; load m64real |
call __fdivrp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret 8 |
memory_divide_m64r: |
fdivr qword ptr[esp + MEM_OPERAND] ; do actual divide |
pop eax |
ret 8 |
__fdiv_m64r ENDP |
comment ~****************************************************************** |
;;; FDIV_M16I - FDIV m16int FIX |
;; |
;; Input : Value of the m16int in the top of STACK |
;; |
;; Output: Result of FDIV in ST |
PUBLIC FDIV_M16I |
FDIV_M16I PROC NEAR |
push eax ; save eax |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m16i ; is FP stack full? |
fild word ptr[esp + MEM_OPERAND] ; load m16int in ST |
call __fdivp_sti_st ; do actual divide |
pop eax |
ret |
spill_fpstack_m16i: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fild word ptr[esp + SPILL_MEM_OPERAND] ; load m16int |
call __fdivp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivrp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret |
FDIV_M16I ENDP |
;;; FDIV_M32I - FDIV m16int FIX |
;; |
;; Input : Value of the m16int in the top of STACK |
;; |
;; Output: Result of FDIV in ST |
PUBLIC FDIV_M32I |
FDIV_M32I PROC NEAR |
push eax ; save eax |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m32i ; is FP stack full? |
fild dword ptr[esp + MEM_OPERAND] ; load m32int in ST |
call __fdivp_sti_st ; do actual divide |
pop eax |
ret |
spill_fpstack_m32i: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fild dword ptr[esp + SPILL_MEM_OPERAND] ; load m32int |
call __fdivp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivrp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret |
FDIV_M32I ENDP |
;;; FDIVR_M16I - FDIVR m16int FIX |
;; |
;; Input : Value of the m16int in the top of STACK |
;; |
;; Output: Result of FDIVR in ST |
PUBLIC FDIVR_M16I |
FDIVR_M16I PROC NEAR |
push eax ; save eax |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m16ir ; is FP stack full? |
fild word ptr[esp + MEM_OPERAND] ; load m16int in ST |
call __fdivrp_sti_st ; do actual divide |
pop eax |
ret |
spill_fpstack_m16ir: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fild word ptr[esp + SPILL_MEM_OPERAND] ; load m16int |
call __fdivrp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret |
FDIVR_M16I ENDP |
;;; FDIVR_M32I - FDIVR m32int FIX |
;; |
;; Input : Value of the m32int in the top of STACK |
;; |
;; Output: Result of FDIVR in ST |
PUBLIC FDIVR_M32I |
FDIVR_M32I PROC NEAR |
push eax ; save eax |
f_stsw ax ; get status word |
and eax, 3800h ; get top of stack |
je spill_fpstack_m32ir ; is FP stack full? |
fild dword ptr[esp + MEM_OPERAND] ; load m32int in ST |
call __fdivrp_sti_st ; do actual divide |
pop eax |
ret |
spill_fpstack_m32ir: |
fxch |
sub esp, SPILL_SIZE ; make temp space |
fstp tbyte ptr[esp ] ; save user's ST(1) |
fild dword ptr[esp + SPILL_MEM_OPERAND] ; load m32int |
call __fdivrp_sti_st ; do actual divide |
fld tbyte ptr[esp] ; restore user's ST(1) |
;esp is adjusted by fdivp fn |
fxch |
add esp, SPILL_SIZE |
pop eax |
ret |
FDIVR_M32I ENDP |
**********************************************************************~ |
_TEXT ENDS |
end |
/programs/develop/open watcom/trunk/clib/src/chipr32.asm |
---|
0,0 → 1,851 |
;***************************************************************************** |
;* |
;* 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! |
;* |
;***************************************************************************** |
; static char sccs_id[] = "@(#)fprem32.asm 1.5 12/22/94 12:48:07"; |
; |
; This code is being published by Intel to users of the Pentium(tm) |
; processor. Recipients are authorized to copy, modify, compile, use and |
; distribute the code. |
; |
; Intel makes no warranty of any kind with regard to this code, including |
; but not limited to, implied warranties or merchantability and fitness for |
; a particular purpose. Intel assumes no responsibility for any errors that |
; may appear in this code. |
; |
; No patent licenses are granted, express or implied. |
; |
; |
include mdef.inc |
.386 |
.387 |
; |
; PRELIMINARY VERSION of the software patch for the floating |
; point remainder. |
; |
CHECKSW MACRO |
ifdef DEBUG |
fnstsw [fpsw] |
fnstcw [fpcw] |
endif |
ENDM |
DATA32 SEGMENT DWORD USE32 PUBLIC 'DATA' |
; |
; Stack variables for remainder routines. |
; |
FLT_SIZE EQU 12 |
DENOM EQU 0 |
DENOM_SAVE EQU DENOM + FLT_SIZE |
NUMER EQU DENOM_SAVE + FLT_SIZE |
PREV_CW EQU NUMER + FLT_SIZE |
PATCH_CW EQU PREV_CW + 4 |
FPREM_SW EQU PATCH_CW + 4 |
STACK_SIZE EQU FPREM_SW + 4 |
RET_SIZE EQU 4 |
PUSH_SIZE EQU 4 |
MAIN_FUDGE EQU RET_SIZE + PUSH_SIZE + PUSH_SIZE + PUSH_SIZE |
MAIN_DENOM EQU DENOM + MAIN_FUDGE |
MAIN_DENOM_SAVE EQU DENOM_SAVE + MAIN_FUDGE |
MAIN_NUMER EQU NUMER + MAIN_FUDGE |
MAIN_PREV_CW EQU PREV_CW + MAIN_FUDGE |
MAIN_PATCH_CW EQU PATCH_CW + MAIN_FUDGE |
MAIN_FPREM_SW EQU FPREM_SW + MAIN_FUDGE |
ONESMASK EQU 700h |
fprem_risc_table DB 0, 1, 0, 0, 4, 0, 0, 7, 0, 0, 10, 0, 0, 13, 0, 0 |
fprem_scale DB 0, 0, 0, 0, 0, 0, 0eeh, 03fh |
one_shl_64 DB 0, 0, 0, 0, 0, 0, 0f0h, 043h |
one_shr_64 DB 0, 0, 0, 0, 0, 0, 0f0h, 03bh |
one DB 0, 0, 0, 0, 0, 0, 0f0h, 03fh |
half DB 0, 0, 0, 0, 0, 0, 0e0h, 03fh |
big_number DB 0, 0, 0, 0, 0, 0, 0ffh, 0ffh, 0feh, 07fh |
ifdef DEBUG |
public fpcw |
public fpsw |
fpcw dw 0 |
fpsw dw 0 |
endif |
FPU_STATE STRUC |
CONTROL_WORD DW ? |
reserved_1 DW ? |
STATUS_WORD DD ? |
TAG_WORD DW ? |
reserved_3 DW ? |
IP_OFFSET DD ? |
CS_SLCT DW ? |
OPCODE DW ? |
DATA_OFFSET DD ? |
OPERAND_SLCT DW ? |
reserved_4 DW ? |
FPU_STATE ENDS |
ENV_SIZE EQU 28 |
DATA32 ENDS |
_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' |
_TEXT ENDS |
DATA32 SEGMENT DWORD USE32 PUBLIC 'DATA' |
DATA32 ENDS |
CONST32 SEGMENT DWORD USE32 PUBLIC 'CONST' |
CONST32 ENDS |
BSS32 SEGMENT DWORD USE32 PUBLIC 'BSS' |
BSS32 ENDS |
DGROUP GROUP CONST32, BSS32, DATA32 |
CODE32 SEGMENT DWORD USE32 PUBLIC 'CODE' |
assume cs:_TEXT, ds:DGROUP, es:DGROUP, ss:nothing |
fprem_common PROC NEAR |
push eax |
push ebx |
push ecx |
mov eax, [MAIN_DENOM+6+esp] ; exponent and high 16 bits of mantissa |
xor eax, ONESMASK ; invert bits that have to be one |
test eax, ONESMASK ; check bits that have to be one |
jnz remainder_hardware_ok |
shr eax, 11 |
and eax, 0fh |
cmp byte ptr fprem_risc_table[eax], 0 ; check for (1,4,7,a,d) |
jz remainder_hardware_ok |
; The denominator has the bit pattern. Weed out the funny cases like NaNs |
; before applying the software version. Our caller guarantees that the |
; denominator is not a denormal. Here we check for: |
; denominator inf, NaN, unnormal |
; numerator inf, NaN, unnormal, denormal |
mov eax, [MAIN_DENOM+6+esp] ; exponent and high 16 bits of mantissa |
and eax, 07fff0000h ; mask the exponent only |
cmp eax, 07fff0000h ; check for INF or NaN |
je remainder_hardware_ok |
mov eax, [MAIN_NUMER+6+esp] ; exponent and high 16 bits of mantissa |
and eax, 07fff0000h ; mask the exponent only |
jz remainder_hardware_ok ; jif numerator denormal |
cmp eax, 07fff0000h ; check for INF or NaN |
je remainder_hardware_ok |
mov eax, [esp + MAIN_NUMER + 4] ; high mantissa bits - numerator |
add eax, eax ; set carry if explicit bit set |
jnz remainder_hardware_ok ; jmp if numerator is unnormal |
mov eax, [esp + MAIN_DENOM + 4] ; high mantissa bits - denominator |
add eax, eax ; set carry if explicit bit set |
jnz remainder_hardware_ok ; jmp if denominator is unnormal |
rem_patch: |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
add eax, 63 ; evaluate ey + 63 |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference (ex - ey) |
ja rem_large ; if ex > ey + 63, case of large arguments |
rem_patch_loop: |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
add eax, 10 ; evaluate ey + 10 |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference (ex - ey) |
js remainder_hardware_ok ; safe if ey + 10 > ex |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
mov ecx, ebx |
sub ebx, eax |
and ebx, 07h |
or ebx, 04h |
sub ecx, ebx |
mov ebx, eax |
and ebx, 08000h ; keep sy |
or ecx, ebx ; merge the sign of y |
mov dword ptr [MAIN_DENOM+8+esp], ecx |
fld tbyte ptr [MAIN_DENOM+esp] ; load the shifted denominator |
mov dword ptr [MAIN_DENOM+8+esp], eax ; restore the initial denominator |
fxch |
fprem ; this rem is safe |
fstp tbyte ptr [MAIN_NUMER+esp] ; update the numerator |
fstp st(0) ; pop the stack |
jmp rem_patch_loop |
rem_large: |
test edx, 02h ; is denominator already saved |
jnz already_saved |
fld tbyte ptr[esp + MAIN_DENOM] |
fstp tbyte ptr[esp + MAIN_DENOM_SAVE] ; save denominator |
already_saved: |
; Save user's precision control and institute 80. The fp ops in |
; rem_large_loop must not round to user's precision (if it is less |
; than 80) because the hardware would not have done so. We are |
; aping the hardware here, which is all extended. |
fnstcw [esp+MAIN_PREV_CW] ; save caller's control word |
mov eax, dword ptr[esp + MAIN_PREV_CW] |
or eax, 033fh ; mask exceptions, pc=80 |
mov [esp + MAIN_PATCH_CW], eax |
fldcw [esp + MAIN_PATCH_CW] |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference |
and ebx, 03fh |
or ebx, 020h |
add ebx, 1 |
mov ecx, ebx |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
and eax, 08000h ; keep sy |
or ebx, eax ; merge the sign of y |
mov dword ptr[MAIN_DENOM+8+esp], ebx ; make ey equal to ex (scaled denominator) |
fld tbyte ptr [MAIN_DENOM+esp] ; load the scaled denominator |
fabs |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
fabs |
rem_large_loop: |
fcom |
fstsw ax |
and eax, 00100h |
jnz rem_no_sub |
fsub st, st(1) |
rem_no_sub: |
fxch |
fmul qword ptr half |
fxch |
sub ecx, 1 ; decrement the loop counter |
jnz rem_large_loop |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
fstp tbyte ptr[esp + MAIN_NUMER] ; save result |
fstp st ; toss modified denom |
fld tbyte ptr[esp + MAIN_DENOM_SAVE] |
fld tbyte ptr[big_number] ; force C2 to be set |
fprem |
fstp st |
fld tbyte ptr[esp + MAIN_NUMER] ; restore saved result |
fldcw [esp + MAIN_PREV_CW] ; restore caller's control word |
and ebx, 08000h ; keep sx |
jz rem_done |
fchs |
jmp rem_done |
remainder_hardware_ok: |
fld tbyte ptr [MAIN_DENOM+esp] ; load the denominator |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
fprem ; and finally do a remainder |
; prem_main_routine end |
rem_done: |
test edx, 03h |
jz rem_exit |
fnstsw [esp + MAIN_FPREM_SW] ; save Q0 Q1 and Q2 |
test edx, 01h |
jz do_not_de_scale |
; De-scale the result. Go to pc=80 to prevent from fmul |
; from user precision (fprem does not round the result). |
fnstcw [esp + MAIN_PREV_CW] ; save callers control word |
mov eax, [esp + MAIN_PREV_CW] |
or eax, 0300h ; pc = 80 |
mov [esp + MAIN_PATCH_CW], eax |
fldcw [esp + MAIN_PATCH_CW] |
fmul qword ptr one_shr_64 |
fldcw [esp + MAIN_PREV_CW] ; restore callers CW |
do_not_de_scale: |
mov eax, [esp + MAIN_FPREM_SW] |
fxch |
fstp st |
fld tbyte ptr[esp + MAIN_DENOM_SAVE] |
fxch |
and eax, 04300h ; restore saved Q0, Q1, Q2 |
sub esp, ENV_SIZE |
fnstenv [esp] |
and [esp].STATUS_WORD, 0bcffh |
or [esp].STATUS_WORD, eax |
fldenv [esp] |
add esp, ENV_SIZE |
rem_exit: |
pop ecx |
pop ebx |
pop eax |
CHECKSW ; debug only: save status |
ret |
fprem_common ENDP |
comment ~**************************************************************** |
; |
; float frem_chk (float numer, float denom) |
; |
public frem_chk |
frem_chk PROC NEAR |
push edx |
sub esp, STACK_SIZE |
fld dword ptr [STACK_SIZE+8+esp] |
fstp tbyte ptr [NUMER+esp] |
fld dword ptr [STACK_SIZE+12+esp] |
fstp tbyte ptr [DENOM+esp] |
mov edx, 0 ; dx = 1 if denormal extended divisor |
call fprem_common |
fxch |
fstp st |
add esp, STACK_SIZE |
pop edx |
ret |
frem_chk ENDP |
; end frem_chk |
; |
; double drem_chk (double numer, double denom) |
; |
public drem_chk |
drem_chk PROC NEAR |
push edx |
sub esp, STACK_SIZE |
fld qword ptr [STACK_SIZE+8+esp] |
fstp tbyte ptr [NUMER+esp] |
fld qword ptr [STACK_SIZE+16+esp] |
fstp tbyte ptr [DENOM+esp] |
mov edx, 0 ; dx = 1 if denormal extended divisor |
call fprem_common |
fxch |
fstp st |
add esp, STACK_SIZE |
pop edx |
ret |
drem_chk ENDP |
; end drem_chk |
; |
; long double lrem_chk(long double number,long double denom) |
; |
public lrem_chk |
lrem_chk PROC NEAR |
fld tbyte ptr [20+esp] |
fld tbyte ptr [4+esp] |
call fprem_chk |
fxch |
fstp st |
ret |
lrem_chk ENDP |
**********************************************************************~ |
; |
; FPREM: ST = remainder(ST, ST(1)) |
; |
; Compiler version of the FPREM must preserve the arguments in the floating |
; point stack. |
public __fprem_chk |
defpe __fprem_chk |
push edx |
sub esp, STACK_SIZE |
fstp tbyte ptr [NUMER+esp] |
fstp tbyte ptr [DENOM+esp] |
xor edx, edx |
; prem_main_routine begin |
mov eax,[DENOM+6+esp] ; exponent and high 16 bits of mantissa |
test eax,07fff0000h ; check for denormal |
jz denormal |
call fprem_common |
add esp, STACK_SIZE |
pop edx |
ret |
denormal: |
fld tbyte ptr [DENOM+esp] ; load the denominator |
fld tbyte ptr [NUMER+esp] ; load the numerator |
mov eax, [DENOM+esp] ; test for whole mantissa == 0 |
or eax, [DENOM+4+esp] ; test for whole mantissa == 0 |
jz remainder_hardware_ok_l ; denominator is zero |
fxch |
fstp tbyte ptr[esp + DENOM_SAVE] ; save org denominator |
fld tbyte ptr[esp + DENOM] |
fxch |
or edx, 02h |
; |
; For this we need pc=80. Also, mask exceptions so we don't take any |
; denormal operand exceptions. It is guaranteed that the descaling |
; later on will take underflow, which is what the hardware would have done |
; on a normal fprem. |
; |
fnstcw [PREV_CW+esp] ; save caller's control word |
mov eax, [PREV_CW+esp] |
or eax, 0033fh ; mask exceptions, pc=80 |
mov [PATCH_CW+esp], eax |
fldcw [PATCH_CW+esp] ; mask exceptions & pc=80 |
; The denominator is a denormal. For most numerators, scale both numerator |
; and denominator to get rid of denormals. Then execute the common code |
; with the flag set to indicate that the result must be de-scaled. |
; For large numerators this won't work because the scaling would cause |
; overflow. In this case we know the numerator is large, the denominator |
; is small (denormal), so the exponent difference is also large. This means |
; the rem_large code will be used and this code depends on the difference |
; in exponents modulo 64. Adding 64 to the denominators exponent |
; doesn't change the modulo 64 difference. So we can scale the denominator |
; by 64, making it not denormal, and this won't effect the result. |
; |
; To start with, figure out if numerator is large |
mov eax, [esp + NUMER + 8] ; load numerator exponent |
and eax, 7fffh ; isolate numerator exponent |
cmp eax, 7fbeh ; compare Nexp to Maxexp-64 |
ja big_numer_rem_de ; jif big numerator |
; So the numerator is not large scale both numerator and denominator |
or edx, 1 ; edx = 1, if denormal extended divisor |
fmul qword ptr one_shl_64 ; make numerator not denormal |
fstp tbyte ptr[esp + NUMER] |
fmul qword ptr one_shl_64 ; make denominator not denormal |
fstp tbyte ptr[esp + DENOM] |
jmp scaling_done |
; The numerator is large. Scale only the denominator, which will not |
; change the result which we know will be partial. Set the scale flag |
; to false. |
big_numer_rem_de: |
; We must do this with pc=80 to avoid rounding to single/double. |
; In this case we do not mask exceptions so that we will take |
; denormal operand, as would the hardware. |
fnstcw [PREV_CW+esp] ; save caller's control word |
mov eax, [PREV_CW+esp] |
or eax, 00300h ; pc=80 |
mov [PATCH_CW+esp], eax |
fldcw [PATCH_CW+esp] ; pc=80 |
fstp st ; Toss numerator |
fmul qword ptr one_shl_64 ; make denominator not denormal |
fstp tbyte ptr[esp + DENOM] |
; Restore the control word which was fiddled to scale at 80-bit precision. |
; Then call the common code. |
scaling_done: |
fldcw [esp + PREV_CW] ; restore callers control word |
call fprem_common |
add esp, STACK_SIZE |
pop edx |
ret |
remainder_hardware_ok_l: |
fprem ; and finally do a remainder |
CHECKSW |
add esp, STACK_SIZE |
pop edx |
ret |
__fprem_chk ENDP |
; end fprem_chk |
; |
; FPREM1 code begins here |
; |
fprem1_common PROC NEAR |
push eax |
push ebx |
push ecx |
mov eax, [MAIN_DENOM+6+esp] ; exponent and high 16 bits of mantissa |
xor eax, ONESMASK ; invert bits that have to be one |
test eax, ONESMASK ; check bits that have to be one |
jnz remainder1_hardware_ok |
shr eax, 11 |
and eax, 0fh |
cmp byte ptr fprem_risc_table[eax], 0 ; check for (1,4,7,a,d) |
jz remainder1_hardware_ok |
; The denominator has the bit pattern. Weed out the funny cases like NaNs |
; before applying the software version. Our caller guarantees that the |
; denominator is not a denormal. Here we check for: |
; denominator inf, NaN, unnormal |
; numerator inf, NaN, unnormal, denormal |
mov eax, [MAIN_DENOM+6+esp] ; exponent and high 16 bits of mantissa |
and eax, 07fff0000h ; mask the exponent only |
cmp eax, 07fff0000h ; check for INF or NaN |
je remainder1_hardware_ok |
mov eax, [MAIN_NUMER+6+esp] ; exponent and high 16 bits of mantissa |
and eax, 07fff0000h ; mask the exponent only |
jz remainder1_hardware_ok ; jif numerator denormal |
cmp eax, 07fff0000h ; check for INF or NaN |
je remainder1_hardware_ok |
mov eax, [esp + MAIN_NUMER + 4] ; high mantissa bits - numerator |
add eax, eax ; set carry if explicit bit set |
jnz remainder1_hardware_ok ; jmp if numerator is unnormal |
mov eax, [esp + MAIN_DENOM + 4] ; high mantissa bits - denominator |
add eax, eax ; set carry if explicit bit set |
jnz remainder1_hardware_ok ; jmp if denominator is unnormal |
rem1_patch: |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
add eax, 63 ; evaluate ey + 63 |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference (ex - ey) |
ja rem1_large ; if ex > ey + 63, case of large arguments |
rem1_patch_loop: |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
add eax, 10 ; evaluate ey + 10 |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference (ex - ey) |
js remainder1_hardware_ok ; safe if ey + 10 > ex |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
mov ecx, ebx |
sub ebx, eax |
and ebx, 07h |
or ebx, 04h |
sub ecx, ebx |
mov ebx, eax |
and ebx, 08000h ; keep sy |
or ecx, ebx ; merge the sign of y |
mov dword ptr [MAIN_DENOM+8+esp], ecx |
fld tbyte ptr [MAIN_DENOM+esp] ; load the shifted denominator |
mov dword ptr [MAIN_DENOM+8+esp], eax ; restore the initial denominator |
fxch |
fprem ; this rem is safe |
fstp tbyte ptr [MAIN_NUMER+esp] ; update the numerator |
fstp st(0) ; pop the stack |
jmp rem1_patch_loop |
rem1_large: |
test ebx, 02h ; is denominator already saved |
jnz already_saved1 |
fld tbyte ptr[esp + MAIN_DENOM] |
fstp tbyte ptr[esp + MAIN_DENOM_SAVE] ; save denominator |
already_saved1: |
; Save user's precision control and institute 80. The fp ops in |
; rem1_large_loop must not round to user's precision (if it is less |
; than 80) because the hardware would not have done so. We are |
; aping the hardware here, which is all extended. |
fnstcw [esp+MAIN_PREV_CW] ; save caller's control word |
mov eax, dword ptr[esp + MAIN_PREV_CW] |
or eax, 033fh ; mask exceptions, pc=80 |
mov [esp + MAIN_PATCH_CW], eax |
fldcw [esp + MAIN_PATCH_CW] |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
and eax, 07fffh ; clear sy |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
sub ebx, eax ; evaluate the exponent difference |
and ebx, 03fh |
or ebx, 020h |
add ebx, 1 |
mov ecx, ebx |
mov eax, [MAIN_DENOM+8+esp] ; sign and exponent of y (denominator) |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
and ebx, 07fffh ; clear sx |
and eax, 08000h ; keep sy |
or ebx, eax ; merge the sign of y |
mov dword ptr[MAIN_DENOM+8+esp], ebx ; make ey equal to ex (scaled denominator) |
fld tbyte ptr [MAIN_DENOM+esp] ; load the scaled denominator |
fabs |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
fabs |
rem1_large_loop: |
fcom |
fstsw ax |
and eax, 00100h |
jnz rem1_no_sub |
fsub st, st(1) |
rem1_no_sub: |
fxch |
fmul qword ptr half |
fxch |
sub ecx, 1 ; decrement the loop counter |
jnz rem1_large_loop |
mov ebx, [MAIN_NUMER+8+esp] ; sign and exponent of x (numerator) |
fstp tbyte ptr[esp + MAIN_NUMER] ; save result |
fstp st ; toss modified denom |
fld tbyte ptr[esp + MAIN_DENOM_SAVE] |
fld tbyte ptr[big_number] ; force C2 to be set |
fprem1 |
fstp st |
fld tbyte ptr[esp + MAIN_NUMER] ; restore saved result |
fldcw [esp + MAIN_PREV_CW] ; restore caller's control word |
and ebx, 08000h ; keep sx |
jz rem1_done |
fchs |
jmp rem1_done |
remainder1_hardware_ok: |
fld tbyte ptr [MAIN_DENOM+esp] ; load the denominator |
fld tbyte ptr [MAIN_NUMER+esp] ; load the numerator |
fprem1 ; and finally do a remainder |
; prem1_main_routine end |
rem1_done: |
test edx, 03h |
jz rem1_exit |
fnstsw [esp + MAIN_FPREM_SW] ; save Q0 Q1 and Q2 |
test edx, 01h |
jz do_not_de_scale1 |
; De-scale the result. Go to pc=80 to prevent from fmul |
; from user precision (fprem does not round the result). |
fnstcw [esp + MAIN_PREV_CW] ; save callers control word |
mov eax, [esp + MAIN_PREV_CW] |
or eax, 0300h ; pc = 80 |
mov [esp + MAIN_PATCH_CW], eax |
fldcw [esp + MAIN_PATCH_CW] |
fmul qword ptr one_shr_64 |
fldcw [esp + MAIN_PREV_CW] ; restore callers CW |
do_not_de_scale1: |
mov eax, [esp + MAIN_FPREM_SW] |
fxch |
fstp st |
fld tbyte ptr[esp + MAIN_DENOM_SAVE] |
fxch |
and eax, 04300h ; restore saved Q0, Q1, Q2 |
sub esp, ENV_SIZE |
fnstenv [esp] |
and [esp].STATUS_WORD, 0bcffh |
or [esp].STATUS_WORD, eax |
fldenv [esp] |
add esp, ENV_SIZE |
rem1_exit: |
pop ecx |
pop ebx |
pop eax |
CHECKSW ; debug only: save status |
ret |
fprem1_common ENDP |
comment ~*************************************************************** |
; |
; float frem1_chk (float numer, float denom) |
; |
public frem1_chk |
frem1_chk PROC NEAR |
push edx |
sub esp, STACK_SIZE |
fld dword ptr [STACK_SIZE+8+esp] |
fstp tbyte ptr [NUMER+esp] |
fld dword ptr [STACK_SIZE+12+esp] |
fstp tbyte ptr [DENOM+esp] |
mov edx, 0 ; dx = 1 if denormal extended divisor |
call fprem1_common |
fxch |
fstp st |
add esp, STACK_SIZE |
pop edx |
ret |
frem1_chk ENDP |
; end frem1_chk |
; |
; double drem1_chk (double numer, double denom) |
; |
public drem1_chk |
drem1_chk PROC NEAR |
push edx |
sub esp, STACK_SIZE |
fld qword ptr [STACK_SIZE+8+esp] |
fstp tbyte ptr [NUMER+esp] |
fld qword ptr [STACK_SIZE+16+esp] |
fstp tbyte ptr [DENOM+esp] |
mov edx, 0 ; dx = 1 if denormal extended divisor |
call fprem1_common |
fxch |
fstp st |
add esp, STACK_SIZE |
pop edx |
ret |
drem1_chk ENDP |
; end drem1_chk |
; |
; long double lrem1_chk(long double number,long double denom) |
; |
public lrem1_chk |
lrem1_chk PROC NEAR |
fld tbyte ptr [20+esp] |
fld tbyte ptr [4+esp] |
call fprem1_chk |
fxch |
fstp st |
ret |
lrem1_chk ENDP |
********************************************************************~ |
; |
; FPREM1: ST = remainder(ST, ST(1)) - IEEE version of rounding |
; |
; Compiler version of the FPREM must preserve the arguments in the floating |
; point stack. |
public __fprem1_chk |
defpe __fprem1_chk |
push edx |
sub esp, STACK_SIZE |
fstp tbyte ptr [NUMER+esp] |
fstp tbyte ptr [DENOM+esp] |
mov edx, 0 |
; prem1_main_routine begin |
mov eax,[DENOM+6+esp] ; exponent and high 16 bits of mantissa |
test eax,07fff0000h ; check for denormal |
jz denormal1 |
call fprem1_common |
add esp, STACK_SIZE |
pop edx |
ret |
denormal1: |
fld tbyte ptr [DENOM+esp] ; load the denominator |
fld tbyte ptr [NUMER+esp] ; load the numerator |
mov eax, [DENOM+esp] ; test for whole mantissa == 0 |
or eax, [DENOM+4+esp] ; test for whole mantissa == 0 |
jz remainder1_hardware_ok_l ; denominator is zero |
fxch |
fstp tbyte ptr[esp + DENOM_SAVE] ; save org denominator |
fld tbyte ptr[esp + DENOM] |
fxch |
or edx, 02h |
; |
; For this we need pc=80. Also, mask exceptions so we don't take any |
; denormal operand exceptions. It is guaranteed that the descaling |
; later on will take underflow, which is what the hardware would have done |
; on a normal fprem. |
; |
fnstcw [PREV_CW+esp] ; save caller's control word |
mov eax, [PREV_CW+esp] |
or eax, 0033fh ; mask exceptions, pc=80 |
mov [PATCH_CW+esp], eax |
fldcw [PATCH_CW+esp] ; mask exceptions & pc=80 |
; The denominator is a denormal. For most numerators, scale both numerator |
; and denominator to get rid of denormals. Then execute the common code |
; with the flag set to indicate that the result must be de-scaled. |
; For large numerators this won't work because the scaling would cause |
; overflow. In this case we know the numerator is large, the denominator |
; is small (denormal), so the exponent difference is also large. This means |
; the rem1_large code will be used and this code depends on the difference |
; in exponents modulo 64. Adding 64 to the denominators exponent |
; doesn't change the modulo 64 difference. So we can scale the denominator |
; by 64, making it not denormal, and this won't effect the result. |
; |
; To start with, figure out if numerator is large |
mov eax, [esp + NUMER + 8] ; load numerator exponent |
and eax, 7fffh ; isolate numerator exponent |
cmp eax, 7fbeh ; compare Nexp to Maxexp-64 |
ja big_numer_rem1_de ; jif big numerator |
; So the numerator is not large scale both numerator and denominator |
or edx, 1 ; edx = 1, if denormal extended divisor |
fmul qword ptr one_shl_64 ; make numerator not denormal |
fstp tbyte ptr[esp + NUMER] |
fmul qword ptr one_shl_64 ; make denominator not denormal |
fstp tbyte ptr[esp + DENOM] |
jmp scaling_done1 |
; The numerator is large. Scale only the denominator, which will not |
; change the result which we know will be partial. Set the scale flag |
; to false. |
big_numer_rem1_de: |
; We must do this with pc=80 to avoid rounding to single/double. |
; In this case we do not mask exceptions so that we will take |
; denormal operand, as would the hardware. |
fnstcw [PREV_CW+esp] ; save caller's control word |
mov eax, [PREV_CW+esp] |
or eax, 00300h ; pc=80 |
mov [PATCH_CW+esp], eax |
fldcw [PATCH_CW+esp] ; pc=80 |
fstp st ; Toss numerator |
fmul qword ptr one_shl_64 ; make denominator not denormal |
fstp tbyte ptr[esp + DENOM] |
; Restore the control word which was fiddled to scale at 80-bit precision. |
; Then call the common code. |
scaling_done1: |
fldcw [esp + PREV_CW] ; restore callers control word |
call fprem1_common |
add esp, STACK_SIZE |
pop edx |
ret |
remainder1_hardware_ok_l: |
fprem ; and finally do a remainder |
CHECKSW |
add esp, STACK_SIZE |
pop edx |
ret |
__fprem1_chk ENDP |
; end fprem1_chk |
ifdef DEBUG |
public fpinit |
fpinit PROC NEAR |
fninit |
ret |
fpinit ENDP |
endif |
CODE32 ENDS |
END |
/programs/develop/open watcom/trunk/clib/src/chipt32.asm |
---|
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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
;* DESCRIBE IT HERE! |
;* |
;***************************************************************************** |
; static char sccs_id[] = "@(#)fptan32.asm 1.4 12/20/94 16:51:51"; |
; |
; This code is being published by Intel to users of the Pentium(tm) |
; processor. Recipients are authorized to copy, modify, compile, use and |
; distribute the code. |
; |
; Intel makes no warranty of any kind with regard to this code, including |
; but not limited to, implied warranties or merchantability and fitness for |
; a particular purpose. Intel assumes no responsibility for any errors that |
; may appear in this code. |
; |
; No patent licenses are granted, express or implied. |
; |
; |
; The following code is a PRELIMINARY IMPLEMENTATION of a |
; software patch for the floating point divide instructions. |
; |
; |
include mdef.inc |
.386 |
.387 |
PATCH_CW EQU 00ch |
PREV_CW EQU 010h |
COSINE EQU 0 ; These two are overlaid because they |
ANGLE EQU 0 ; are not live at the same time. |
STACK_SIZE EQU 014h |
ONESMASK EQU 0e000000h |
DATA32 SEGMENT DWORD USE32 PUBLIC 'DATA' |
fdiv_risk_table DB 0, 1, 0, 0, 4, 0, 0, 7, 0, 0, 10, 0, 0, 13, 0, 0 |
fdiv_scale DD 03f700000h ; 0.9375 |
one_shl_63 DD 05f000000h |
DATA32 ENDS |
DGROUP GROUP DATA32 |
_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' |
assume cs:_TEXT, ds:DGROUP, es:DGROUP, ss:nothing |
public __fptan_chk |
; |
; PRELIMINARY VERSION for register-register divides. |
; |
defpe __fptan_chk |
push eax |
sub esp, STACK_SIZE |
fstp tbyte ptr [esp+ANGLE] |
mov eax, [esp+ANGLE+8] |
and eax, 07fffh |
jz use_hardware ; denormals, ... |
cmp eax, 07fffh |
je use_hardware ; NaNs, infinities, ... |
mov eax, [esp+ANGLE+4] |
add eax, eax |
jnc use_hardware ; unnormals (explicit 1 missing) |
fld tbyte ptr [esp+ANGLE] |
; |
; Check for proper parameter range ( |<angle>| < 2^63) |
; |
fabs |
fcomp one_shl_63 |
fstsw ax |
sahf |
jae use_hardware |
fld tbyte ptr [esp+ANGLE] |
fsincos |
fstp tbyte ptr [esp+COSINE] |
fld tbyte ptr [esp+COSINE] ; load the denominator (cos(x)) |
mov eax, [esp+COSINE+4] ; get mantissa bits 32-64 |
add eax,eax ; shift the one's bit onto carry |
xor eax, ONESMASK ; invert the bits that must be ones |
test eax, ONESMASK ; and make sure they are all ones |
jz scale_if_needed ; if all are one scale numbers |
fdivp st(1), st ; use of hardware is OK. |
fld1 ; push 1.0 onto FPU stack |
add esp, STACK_SIZE |
pop eax |
ret |
scale_if_needed: |
shr eax, 28 ; keep first 4 bits after point |
cmp fdiv_risk_table[eax], ah ; check for (1,4,7,a,d) |
jnz divide_scaled ; are in potential problem area |
fdivp st(1), st ; use of hardware is OK. |
fld1 ; push 1.0 onto FPU stack |
add esp, STACK_SIZE |
pop eax |
ret |
divide_scaled: |
fwait ; catch preceding exceptions |
fstcw [esp+PREV_CW] ; save caller's control word |
mov eax, [esp+PREV_CW] |
or eax, 033fh ; mask exceptions, pc=80 |
mov [esp+PATCH_CW], eax |
fldcw [esp+PATCH_CW] ; mask exceptions & pc=80 |
fmul fdiv_scale ; scale denominator by 15/16 |
fxch |
fmul fdiv_scale ; scale numerator by 15/16 |
fxch |
; This assures correctly rounded result if pc=64 as well |
fldcw [esp+PREV_CW] ; restore caller's control word |
fdivp st(1), st ; use of hardware is OK. |
fld1 ; push 1.0 onto FPU stack |
add esp, STACK_SIZE |
pop eax |
ret |
use_hardware: |
fld tbyte ptr [esp+ANGLE] |
fptan |
add esp, STACK_SIZE |
pop eax |
ret |
__fptan_chk ENDP |
_TEXT ENDS |
end |
/programs/develop/open watcom/trunk/clib/src/chipvar.asm |
---|
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 mdef.inc |
xref "C",__verify_pentium_fdiv_bug |
name chipvar |
datasegment |
xdefp ___chipbug |
xdefp __chipbug |
___chipbug label byte |
__chipbug label byte |
dd 0 |
enddata |
end |
/programs/develop/open watcom/trunk/clib/src/chktty.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 chktty() - check if stream is teletype. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <malloc.h> |
#include <unistd.h> |
#include "rtdata.h" |
#include "fileacc.h" |
#include "streamio.h" |
void __chktty( FILE *fp ) |
{ |
/* if we have not determined that we've got a tty then check for one */ |
if( !(fp->_flag & _ISTTY) ) { |
if( isatty( fileno( fp ) ) ) { |
fp->_flag |= _ISTTY; |
if( ( fp->_flag & (_IONBF | _IOLBF | _IOFBF) ) == 0 ) { |
fp->_flag |= _IOLBF; |
} |
} |
} |
} |
/programs/develop/open watcom/trunk/clib/src/fclose.c |
---|
0,0 → 1,134 |
/**************************************************************************** |
* |
* 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: Platform independent fclose() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include "liballoc.h" |
#include "mf.h" |
#include <string.h> |
#include "fileacc.h" |
#include "tmpfname.h" |
#include "rtdata.h" |
#include "lseek.h" |
#include "streamio.h" |
#include "close.h" |
#include "flush.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_free dlfree |
#endif |
#ifndef __UNIX__ |
void (*__RmTmpFileFn)( FILE *fp ); |
#endif |
int __doclose( FILE *fp, int close_handle ) |
{ |
int ret; |
if( fp->_flag == 0 ) { |
return( -1 ); /* file already closed */ |
} |
ret = 0; |
if( fp->_flag & _DIRTY ) { |
ret = __flush( fp ); |
} |
_AccessFile( fp ); |
/* |
* 02-nov-92 G.Turcotte Syncronize buffer pointer with the file pointer |
* IEEE Std 1003.1-1988 B.8.2.3.2 |
* 03-nov-03 B.Oldeman Inlined ftell; we already know the buffer isn't |
* dirty (because of the flush), so only a "get" applies |
*/ |
if( fp->_cnt != 0 ) { /* if something in buffer */ |
__lseek( fileno( fp ), -fp->_cnt, SEEK_CUR ); |
} |
if( close_handle ) { |
#if defined( __UNIX__ ) || defined( __NETWARE__ ) |
// we don't get to implement the close function on these systems |
ret |= close( fileno( fp ) ); |
#else |
ret |= __close( fileno( fp ) ); |
#endif |
} |
if( fp->_flag & _BIGBUF ) { /* if we allocated the buffer */ |
lib_free( _FP_BASE(fp) ); |
_FP_BASE(fp) = NULL; |
} |
#ifndef __UNIX__ |
/* this never happens under UNIX */ |
if( fp->_flag & _TMPFIL ) { /* if this is a temporary file */ |
__RmTmpFileFn( fp ); |
} |
#endif |
_ReleaseFile( fp ); |
return( ret ); |
} |
int __shutdown_stream( FILE *fp, int close_handle ) |
{ |
int ret; |
ret = __doclose( fp, close_handle ); |
__freefp( fp ); |
return( ret ); |
} |
_WCRTLINK int fclose( FILE *fp ) |
{ |
__stream_link *link; |
_AccessIOB(); |
link = _RWD_ostream; |
for( ;; ) { |
if( link == NULL ) { |
_ReleaseIOB(); |
return( -1 ); /* file not open */ |
} |
if( link->stream == fp ) break; |
link = link->next; |
} |
_ReleaseIOB(); |
return( __shutdown_stream( fp, 1 ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/fflush.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: Implementation of fflush() - flush streams. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <errno.h> |
#include <fcntl.h> |
#include "rtdata.h" |
#include "fileacc.h" |
#include "flush.h" |
_WCRTLINK int fflush( FILE *fp ) |
{ |
if( fp == NULL ) { |
flushall(); |
return( 0 ); |
} |
_ValidFile( fp, EOF ); |
return( __flush( fp ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/flush.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 fflush() helper routine. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include <fcntl.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "qwrite.h" |
#include "lseek.h" |
#include "flush.h" |
#if defined( __NETWARE__ ) && defined( _THIN_LIB ) |
/* Take flush from LibC */ |
_WCRTLINK int __flush( FILE *fp ) |
{ |
return( fflush( fp ) ); |
} |
#else |
_WCRTLINK int __flush( FILE *fp ) |
{ |
int len; |
long offset; |
int ret; |
char *ptr; |
unsigned amount; |
ret = 0; |
_AccessFile( fp ); |
if( fp->_flag & _DIRTY ) { |
fp->_flag &= ~_DIRTY; |
if( (fp->_flag & _WRITE) && (_FP_BASE(fp) != NULL) ) { |
ptr = _FP_BASE(fp); |
amount = fp->_cnt; |
while( amount != 0 && ret == 0 ) { |
len = __qwrite( fileno( fp ), ptr, amount ); /* 02-aug-90 */ |
if( len == -1 ) { |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
#ifndef __UNIX__ |
else if( len == 0 ) { |
__set_errno( ENOSPC ); /* 12-nov-88 */ |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
#endif |
ptr += len; |
amount -= len; |
} |
} |
} else if( _FP_BASE(fp) != NULL ) { /* not dirty */ |
/* fseek( fp, ftell(fp), SEEK_SET ); */ |
fp->_flag &= ~_EOF; |
if( !(fp->_flag & _ISTTY) ) { |
offset = fp->_cnt; |
if( offset != 0 ) { /* 10-aug-89 JD */ |
offset = __lseek( fileno( fp ), -offset, SEEK_CUR ); |
} |
if( offset == -1 ) { |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
} |
} |
fp->_ptr = _FP_BASE(fp); /* reset ptr to start of buffer */ |
fp->_cnt = 0; |
#if !defined( __NETWARE__ ) && !defined( __OSI__ ) |
if( ret == 0 && (_FP_EXTFLAGS(fp) & _COMMIT) ) { |
if( fsync( fileno( fp ) ) == -1 ) { |
ret = EOF; |
} |
} |
#endif |
_ReleaseFile( fp ); |
return( ret ); |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/fputc.c |
---|
0,0 → 1,145 |
/**************************************************************************** |
* |
* 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: Platform independent fputc() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include <errno.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "orient.h" |
#ifdef __WIDECHAR__ |
#include <mbstring.h> |
#include <wchar.h> |
#endif |
#include "flush.h" |
#include "streamio.h" |
#ifndef __WIDECHAR__ |
_WCRTLINK int fputc( int c, FILE *fp ) |
{ |
int flags; |
_ValidFile( fp, EOF ); |
_AccessFile( fp ); |
/*** Deal with stream orientation ***/ |
ORIENT_STREAM(fp,EOF); |
if( !(fp->_flag & _WRITE) ) { |
__set_errno( EBADF ); |
fp->_flag |= _SFERR; |
_ReleaseFile( fp ); |
return( EOF ); |
} |
if( _FP_BASE(fp) == NULL ) { |
__ioalloc( fp ); |
} |
flags = _IONBF; |
if( c == '\n' ) { |
flags = _IONBF | _IOLBF; |
#ifndef __UNIX__ |
if( !(fp->_flag & _BINARY) ) { |
fp->_flag |= _DIRTY; |
*(char*)fp->_ptr = '\r'; /* '\n' -> '\r''\n' */ |
fp->_ptr++; |
fp->_cnt++; |
if( fp->_cnt == fp->_bufsize ) { |
if( __flush( fp ) ) { |
_ReleaseFile( fp ); |
return( EOF ); |
} |
} |
} |
#endif |
} |
fp->_flag |= _DIRTY; |
*(char *)fp->_ptr = c; |
fp->_ptr++; |
fp->_cnt++; |
if( (fp->_flag & flags) || (fp->_cnt == fp->_bufsize) ) { |
if( __flush( fp ) ) { |
_ReleaseFile( fp ); |
return( EOF ); |
} |
} |
_ReleaseFile( fp ); |
return( (UCHAR_TYPE)c ); |
} |
#else |
static int __write_wide_char( FILE *fp, wchar_t wc ) |
/**************************************************/ |
{ |
if( fp->_flag & _BINARY ) { |
/*** Dump the wide character ***/ |
return( fwrite( &wc, sizeof( wchar_t ), 1, fp ) ); |
} else { |
char mbc[MB_CUR_MAX]; |
int rc; |
/*** Convert the wide character to multibyte form and write it ***/ |
rc = wctomb( mbc, wc ); |
if( rc > 0 ) { |
return( fwrite( mbc, rc, 1, fp ) ); |
} else { |
__set_errno( EILSEQ ); |
return( 0 ); |
} |
} |
} |
_WCRTLINK wint_t fputwc( wint_t c, FILE *fp ) |
{ |
_ValidFile( fp, WEOF ); |
_AccessFile( fp ); |
/*** Deal with stream orientation ***/ |
ORIENT_STREAM(fp,WEOF); |
/*** Write the character ***/ |
if( !__write_wide_char( fp, c ) ) { |
_ReleaseFile( fp ); |
return( WEOF ); |
} else { |
_ReleaseFile( fp ); |
return( c ); |
} |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/fputs.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: Implementation of fputs() - put string to stream. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "flush.h" |
#include "streamio.h" |
_WCRTLINK int __F_NAME(fputs,fputws)( const CHAR_TYPE *s, FILE *fp ) |
{ |
const CHAR_TYPE *start; |
int c; |
int not_buffered; |
int rc; |
_ValidFile( fp, __F_NAME(EOF,WEOF) ); |
_AccessFile( fp ); |
if( _FP_BASE(fp) == NULL ) { |
__ioalloc( fp ); /* allocate buffer */ |
} |
not_buffered = 0; |
if( fp->_flag & _IONBF ) { |
not_buffered = 1; |
fp->_flag &= ~_IONBF; |
fp->_flag |= _IOLBF; |
} |
rc = 0; |
start = s; |
while( c = *s ) { |
s++; |
#ifndef __WIDECHAR__ |
if( (fputc)( c, fp ) == EOF ) { /* 23-oct-91 */ |
rc = EOF; |
break; |
} |
#else |
if( (fputwc)( c, fp ) == WEOF ) { /* 23-oct-91 */ |
rc = -1; |
break; |
} |
#endif |
} |
if( not_buffered ) { |
fp->_flag &= ~_IOLBF; |
fp->_flag |= _IONBF; |
if( rc == 0 ) { |
rc = __flush( fp ); /* 23-oct-91 */ |
} |
} |
if( rc == 0 ) { |
/* return the number of items written */ |
/* this is ok by ANSI which says that success is */ |
/* indicated by a non-negative return value */ |
rc = s - start; |
} |
_ReleaseFile( fp ); |
return( rc ); |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/freefp.c |
---|
0,0 → 1,92 |
/**************************************************************************** |
* |
* 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: Platform independent __allocfp() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "liballoc.h" |
#include "fileacc.h" |
#include "rtdata.h" |
#include "streamio.h" |
#ifdef DLHEAP |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_free dlfree |
#endif |
/* |
NOTE: This routine does not actually free the link/FILE structures. |
That is because code assumes that it can fclose the file and then |
freopen is a short time later. The __purgefp routine can be called |
to actually release the storage. |
*/ |
void __freefp( FILE * fp ) |
{ |
__stream_link **owner; |
__stream_link *link; |
_AccessIOB(); |
owner = &_RWD_ostream; |
for( ;; ) { |
link = *owner; |
if( link == NULL ) |
return; |
if( link->stream == fp ) |
break; |
owner = &link->next; |
} |
fp->_flag |= _READ | _WRITE; |
(*owner) = link->next; |
link->next = _RWD_cstream; |
_RWD_cstream = link; |
_ReleaseIOB(); |
} |
void __purgefp( void ) |
{ |
__stream_link *next; |
_AccessIOB(); |
while( _RWD_cstream != NULL ) { |
next = _RWD_cstream->next; |
lib_free( _RWD_cstream ); |
_RWD_cstream = next; |
} |
_ReleaseIOB(); |
} |
/programs/develop/open watcom/trunk/clib/src/fsync.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <errno.h> |
#if defined(__DOS__) || defined(__WINDOWS__) |
#elif defined(__NT__) |
#elif defined(__OS2__) |
#elif defined(__NETWARE__) |
#endif |
#include <unistd.h> |
#include "iomode.h" |
#include "rtcheck.h" |
#include "seterrno.h" |
/* |
// take fsync from LIBC import file |
*/ |
#if !defined (_NETWARE_LIBC) |
_WCRTLINK int fsync( int handle ) |
/*******************************/ |
{ |
int ret = 0; |
__handle_check( handle, -1 ); |
#if defined(__DOS__) || defined(__WINDOWS__) |
#elif defined(__NT__) |
// if( !FlushFileBuffers( __getOSHandle( handle ) ) ) |
// { |
// __set_errno_nt(); |
// ret = -1; |
// } |
#elif defined(__OS2__) |
#elif defined(__NETWARE__) |
#else |
#error Unknown target system |
#endif |
return( ret ); |
} |
#endif /* !defined (_NETWARE_LIBC) */ |
/programs/develop/open watcom/trunk/clib/src/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/src/hdlman.c |
---|
0,0 → 1,286 |
/**************************************************************************** |
* |
* 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: Handle manager routines. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include "liballoc.h" |
#include <string.h> |
#ifdef _M_IX86 |
#include <i86.h> |
#endif |
#include <unistd.h> |
#include <errno.h> |
#if defined(__OS2__) |
#elif defined(__WINDOWS__) || defined(__NT__) |
#endif |
#include "iomode.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "handleio.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_malloc dlmalloc |
#define lib_free dlfree |
#define lib_realloc dlrealloc |
#endif |
#undef __getOSHandle |
extern unsigned __NFiles; // the size of the iomode array |
extern void __grow_iomode( int num ); |
unsigned __NHandles = 0; |
#if defined(__NT__) |
HANDLE *__OSHandles = NULL; |
unsigned __growPOSIXHandles( unsigned num ) |
{ |
HANDLE *new2; |
unsigned i; |
if( num > __NHandles ) |
{ |
_AccessFList(); |
if( __OSHandles == NULL ) |
{ |
new2 = lib_malloc( num * sizeof( int ) ); |
} |
else |
{ |
new2 = lib_realloc( __OSHandles, num * sizeof( int ) ); |
} |
if( new2 == NULL ) |
{ |
__set_errno( ENOMEM ); |
num = __NHandles; |
} |
else |
{ |
for( i = __NHandles; i < num; i++ ) |
{ |
new2[ i ] = NULL_HANDLE; |
} |
__OSHandles = new2; |
__NHandles = num; |
} |
_ReleaseFList(); |
} |
return( __NHandles ); |
} |
int __allocPOSIXHandle( HANDLE hdl ) |
{ |
int i; |
_AccessFList(); |
for( i = 0; i < __NHandles; i++ ) |
{ |
if( __OSHandles[i] == NULL_HANDLE ) break; |
} |
if( i >= __NHandles ) |
{ |
// 20 -> (20+10+1) -> 31 |
// 31 -> (31+15+1) -> 47 |
// 47 -> (47+23+1) -> 71 |
__growPOSIXHandles( i + (i >> 1) + 1 ); |
// keep iomode array in sync |
if( __NHandles > __NFiles ) __grow_iomode( __NHandles ); |
for( ; i < __NHandles; i++ ) |
{ |
if( __OSHandles[i] == NULL_HANDLE ) break; |
} |
} |
if( i >= __NHandles ) |
{ |
i = -1; |
} else { |
__OSHandles[i] = hdl; |
} |
_ReleaseFList(); |
return( i ); |
} |
void __freePOSIXHandle( int hid ) |
{ |
__OSHandles[ hid ] = NULL_HANDLE; |
} |
HANDLE __getOSHandle( int hid ) |
{ |
return( __OSHandles[ hid ] ); |
} |
int __setOSHandle( unsigned hid, HANDLE hdl ) |
{ |
// call the Win32 API for a standard file handle |
switch( hid ) { |
case STDIN_FILENO: |
// SetStdHandle( STD_INPUT_HANDLE, hdl ); |
break; |
case STDOUT_FILENO: |
// SetStdHandle( STD_OUTPUT_HANDLE, hdl ); |
break; |
case STDERR_FILENO: |
// SetStdHandle( STD_ERROR_HANDLE, hdl ); |
break; |
} |
if( hid < __NHandles ) |
{ |
__OSHandles[ hid ] = hdl; |
} |
else |
{ |
hid = (unsigned)-1; // this should never happen |
} |
return( hid ); |
} |
HANDLE *__FakeHandles = 0; |
static int __topFakeHandle = 0; |
HANDLE __NTGetFakeHandle( void ) |
{ |
HANDLE os_handle; |
_AccessFList(); |
// os_handle = CreateEvent( 0, 0, 0, 0 ); |
os_handle = 0; |
if( os_handle == NULL ) |
{ |
// win32s does not support event handles |
static DWORD fakeHandle = 0x80000000L; |
fakeHandle++; |
os_handle = (HANDLE)fakeHandle; |
} |
else |
{ |
__FakeHandles = lib_realloc( __FakeHandles, (__topFakeHandle+1) * sizeof( HANDLE ) ); |
__FakeHandles[ __topFakeHandle ] = os_handle; |
__topFakeHandle++; |
} |
_ReleaseFList(); |
return( os_handle ); |
} |
// called from library startup code |
void __initPOSIXHandles( void ) |
{ |
HANDLE h; |
// __OSHandles = NULL; |
// __NHandles = 0; |
__growPOSIXHandles( __NFiles ); |
h = 0; //GetStdHandle( STD_INPUT_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 0==STDIN_FILENO |
h = 0; //GetStdHandle( STD_OUTPUT_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 1==STDOUT_FILENO |
h = 0; //GetStdHandle( STD_ERROR_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 3==STDERR_FILENO |
} |
static void __finiPOSIXHandles( void ) |
{ |
if( __OSHandles != NULL ) { |
lib_free( __OSHandles ); |
__OSHandles = NULL; |
} |
if( __FakeHandles != NULL ) |
{ |
int i; |
for( i = 0 ; i < __topFakeHandle ; i++ ) |
{ |
// CloseHandle( __FakeHandles[i] ); |
} |
lib_free( __FakeHandles ); |
__FakeHandles = 0; |
} |
} |
AYI( __finiPOSIXHandles, INIT_PRIORITY_LIBRARY-1 ) |
#endif |
void __set_handles( int num ) |
{ |
__NHandles = num; |
} |
_WCRTLINK int _grow_handles( int num ) |
{ |
if( num > __NHandles ) |
{ |
#if defined(MSDOS) |
#elif defined( __OS2_286__ ) |
#elif defined( __WARP__ ) |
#elif defined(__WINDOWS__) |
#elif defined(__NT__) |
{ |
num = __growPOSIXHandles( num ); |
} |
#elif defined(__NETWARE__) |
#elif defined(__UNIX__) |
#endif |
if( num > __NFiles ) { |
__grow_iomode( num ); // sets new __NFiles if successful |
} |
__NHandles = num; |
} |
return( __NHandles ); |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/hugeval.c |
---|
0,0 → 1,34 |
/**************************************************************************** |
* |
* 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" |
_WCRTLINKD unsigned short const _HUGEDATA _HugeValue[] = { 0x0000, 0x0000, 0x0000, 0x7ff0 }; |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/initfile.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: Stream I/O initializer. |
* |
****************************************************************************/ |
//#include "dll.h" // needs to be first |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include "liballoc.h" |
#include "mf.h" |
#include "rtdata.h" |
#include "exitwmsg.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_malloc dlmalloc |
#define lib_free dlfree |
#define lib_realloc dlrealloc |
#endif |
void __InitFiles( void ) |
{ |
__stream_link *link; |
FILE *fp; |
fp = _RWD_iob; |
stderr->_flag &= ~(_IONBF | _IOLBF | _IOFBF); |
stderr->_flag |= _IONBF; |
for( fp = _RWD_iob; fp->_flag != 0; ++fp ) |
{ |
link = lib_malloc( sizeof( __stream_link ) ); |
if( link == NULL ) |
{ |
__fatal_runtime_error( |
"Not enough memory to allocate file structures\r\n", 1 ); |
} |
link->stream = fp; |
link->next = _RWD_ostream; |
_RWD_ostream = link; |
fp->_link = link; |
fp->_link->_base = NULL; |
fp->_link->_tmpfchar = 0; |
fp->_link->_orientation = _NOT_ORIENTED; |
} |
_RWD_cstream = NULL; |
} |
/programs/develop/open watcom/trunk/clib/src/ioalloc.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: Platform independent __ioalloc() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "liballoc.h" |
#include <unistd.h> |
#include "rtdata.h" |
#include "streamio.h" |
void __ioalloc( FILE *fp ) |
{ |
__chktty( fp ); /* JBS 28-aug-90 */ |
if( fp->_bufsize == 0 ) { |
if( fp->_flag & _IOLBF ) { |
fp->_bufsize = 134; |
} else if( fp->_flag & _IONBF ) { |
/* Use small but reasonably sized buffer; otherwise we will end |
* up calling into the OS for every character, completely killing |
* performance on unbuffered stream output through printf() etc., |
* especially in extended DOS because of mode switches. |
*/ |
fp->_bufsize = 64; |
} else { |
fp->_bufsize = BUFSIZ; |
} |
} |
_FP_BASE(fp) = lib_malloc( fp->_bufsize ); |
if( _FP_BASE(fp) == NULL ) { |
fp->_flag &= ~(_IONBF | _IOLBF | _IOFBF); |
fp->_flag |= _IONBF; /* can't get big buffer */ |
_FP_BASE(fp) = (char *)&(fp->_ungotten); |
fp->_bufsize = 1; |
} else { |
fp->_flag |= _BIGBUF; /* got big buffer */ |
} |
fp->_ptr = _FP_BASE(fp); |
fp->_cnt = 0; |
} |
/programs/develop/open watcom/trunk/clib/src/iob.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: Definition of __iob array. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include "rtdata.h" |
#include "rtinit.h" |
#include "tmpfname.h" |
_WCRTLINKD FILE _WCNEAR __iob[_NFILES] = { |
{ NULL, 0, NULL, _READ, 0, 0, 0 } /* stdin */ |
,{ NULL, 0, NULL, _WRITE, 1, 0, 0 } /* stdout */ |
,{ NULL, 0, NULL, _WRITE, 2, 0, 0 } /* stderr */ |
#if defined( __DOS__ ) || defined( __WINDOWS__ ) || defined( __OSI__ ) |
,{ NULL, 0, NULL, _READ|_WRITE, 3, 0, 0 } /* stdaux */ |
,{ NULL, 0, NULL, _WRITE, 4, 0, 0 } /* stdprn */ |
#endif |
}; |
__stream_link *__ClosedStreams; |
__stream_link *__OpenStreams; |
#if !defined( __UNIX__ ) |
_WCRTLINKD int _WCNEAR _fmode = O_TEXT; /* default file translation mode */ |
#endif |
extern void __InitFiles(); |
extern void __full_io_exit(); |
AXI(__InitFiles,INIT_PRIORITY_LIBRARY); |
AYI(__full_io_exit,INIT_PRIORITY_LIBRARY); |
/programs/develop/open watcom/trunk/clib/src/iobaddr.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: Standard stream/file accessor routines. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "rtdata.h" |
#if !defined( __NETWARE__ ) && !defined( _THIN_LIB ) |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
if( handle > NUM_STD_STREAMS ) { |
return( NULL ); |
} else { |
return( &_RWD_iob[handle] ); |
} |
} |
_WCRTLINK FILE *__get_std_file( unsigned handle ) |
{ |
return( __get_std_stream( handle ) ); |
} |
#else |
#include <io.h> |
#if defined( _NETWARE_LIBC ) |
extern FILE **___stdin ( void ); |
extern FILE **___stdout( void ); |
extern FILE **___stderr( void ); |
extern FILE **___cin ( void ); |
extern FILE **___cout ( void ); |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
FILE *pFile = NULL; |
switch( handle ) { |
case STDIN_FILENO: |
pFile = *___stdin(); |
break; |
case STDOUT_FILENO: |
pFile = *___stdout(); |
break; |
case STDERR_FILENO: |
pFile = *___stderr(); |
break; |
default: |
break; |
} |
return( pFile ); |
} |
#elif defined( _NETWARE_CLIB ) |
extern FILE **__get_stdin ( void ); |
extern FILE **__get_stdout( void ); |
extern FILE **__get_stderr( void ); |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
FILE *pFile = NULL; |
switch( handle ) { |
case STDIN_FILENO: |
pFile = *__get_stdin(); |
break; |
case STDOUT_FILENO: |
pFile = *__get_stdout(); |
break; |
case STDERR_FILENO: |
pFile = *__get_stderr(); |
break; |
default: |
break; |
} |
return( pFile ); |
} |
#endif |
#endif |
#if defined( __NETWARE__ ) && !defined( _THIN_LIB ) |
#include <io.h> |
FILE **__get_stdin( void ) |
{ |
static FILE *stdin_ptr; |
stdin_ptr = __get_std_stream( STDIN_FILENO ); |
return( &stdin_ptr ); |
} |
FILE **__get_stdout( void ) |
{ |
static FILE *stdout_ptr; |
stdout_ptr = __get_std_stream( STDOUT_FILENO ); |
return( &stdout_ptr ); |
} |
FILE **__get_stderr( void ) |
{ |
static FILE *stderr_ptr; |
stderr_ptr = __get_std_stream( STDERR_FILENO ); |
return( &stderr_ptr ); |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/ioexit.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: I/O streams shutdown. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "rtdata.h" |
extern void __purgefp(void); |
extern int __shutdown_stream( FILE *fp, int ); |
static int docloseall( unsigned dont_close ) |
{ |
FILE *fp; |
int number_of_files_closed; |
__stream_link *link; |
__stream_link *next; |
FILE *bottom; |
FILE *standards; |
int close_handle; |
bottom = &_RWD_iob[dont_close]; |
standards = &_RWD_iob[NUM_STD_STREAMS]; |
number_of_files_closed = 0; |
for( link = _RWD_ostream; link != NULL; link = next ) { |
next = link->next; |
fp = link->stream; |
close_handle = 1; |
if ((fp->_flag & _DYNAMIC) || (fp->_flag & _TMPFIL)) |
{ |
__shutdown_stream( fp, close_handle ); |
++number_of_files_closed; |
} |
else if( fp >= bottom ) { |
#ifndef __NETWARE__ |
/* close the file, but leave the handle open */ |
if( fp < standards ) { |
close_handle = 0; |
} |
#endif |
__shutdown_stream( fp, close_handle ); |
++number_of_files_closed; |
} |
} |
return( number_of_files_closed ); |
} |
_WCRTLINK int fcloseall( void ) |
{ |
return( docloseall( NUM_STD_STREAMS ) ); |
} |
void __full_io_exit( void ) |
{ |
docloseall( 0 ); |
__purgefp(); |
} |
/programs/develop/open watcom/trunk/clib/src/iomode.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: io_mode handle information array manipulation |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <string.h> |
#include <errno.h> |
#include "rtdata.h" |
//#include "liballoc.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "iomode.h" |
unsigned __NFiles = _NFILES; /* maximum # of files we can open */ |
#if defined(__NETWARE__) |
#error NO IO MODE MANAGER UNDER NETWARE |
#endif |
#if !defined(__UNIX__) |
unsigned _HUGEDATA __init_mode[_NFILES] = { /* file mode information (flags) */ |
_READ, /* stdin */ |
_WRITE, /* stdout */ |
_WRITE, /* stderr */ |
_READ|_WRITE, /* stdaux */ |
_WRITE /* stdprn */ |
}; |
unsigned *__io_mode = __init_mode; /* initially points to static array */ |
unsigned __GetIOMode( int handle ) |
{ |
if( handle >= __NFiles ) |
{ |
return( 0 ); |
} |
return( __io_mode[handle] ); |
} |
void __SetIOMode_nogrow( int handle, unsigned value ) |
{ |
if( handle < __NFiles ) |
{ |
__io_mode[handle] = value; /* we're closing it; smite _INITIALIZED */ |
} |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/iomodtty.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: check tty for standard handles in the iomode array |
* |
****************************************************************************/ |
#include "variety.h" |
#include <unistd.h> |
#include "rtdata.h" |
//#include "liballoc.h" |
#include "fileacc.h" |
#include "handleio.h" |
#include "iomode.h" |
#define _INITIALIZED _DYNAMIC |
void __ChkTTYIOMode( int handle ) |
{ |
if( handle < NUM_STD_STREAMS && !(__io_mode[handle] & _INITIALIZED) ) |
{ |
__io_mode[handle] |= _INITIALIZED; |
if( isatty( handle ) ) |
{ |
__io_mode[handle] |= _ISTTY; |
} |
} |
} |
// For F77 to call |
unsigned __IOMode( int handle ) |
{ |
__ChkTTYIOMode( handle ); |
return( __GetIOMode( handle ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/isattwnt.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: Implementation of isatty() for Win32. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <unistd.h> |
//#include <windows.h> |
//#include "defwin.h" |
#include "iomode.h" |
#include "fileacc.h" |
/* |
DWORD GetFileType( |
HANDLE hFile // handle to file |
); |
Return value can be: |
FILE_TYPE_CHAR The specified file is a character file, |
typically an LPT device or a console |
*/ |
_WCRTLINK int isatty( int hid ) |
{ |
// if( GetFileType( __getOSHandle( hid ) ) == FILE_TYPE_CHAR ) { |
// return( 1 ); |
// } |
return( 0 ); |
} |
/programs/develop/open watcom/trunk/clib/src/istable.c |
---|
0,0 → 1,295 |
/**************************************************************************** |
* |
* 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: Character classification table. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <ctype.h> |
_WCRTLINKD const char _HUGEDATA _IsTable[257] = { |
#define ___0__ 0 |
/* -1,EOF */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 00,NUL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 01,SOH */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 02,STX */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 03,ETX */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 04,EOT */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 05,ENQ */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 06,NAK */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 07,BEL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 08,BS */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 09,TAB */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0A,LF */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0B,VT */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0C,FF */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0D,CR */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0E,SI */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 0F,SO */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 10, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 11, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 12, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 13, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 14, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 15, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 16, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 17, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 18, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 19, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 20, */ ___0__|___0__|___0__|___0__|_PRINT|___0__|_SPACE|___0__, |
/* 21, ! */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 22, " */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 23, # */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 24, $ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 25, % */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 26, & */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 27, ' */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 28, ( */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 29, ) */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2A, * */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2B, + */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2C, , */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2D, - */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2E, . */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2F, / */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 30, 0 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 31, 1 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 32, 2 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 33, 3 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 34, 4 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 35, 5 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 36, 6 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 37, 7 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 38, 8 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 39, 9 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 3A, : */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3B, ; */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3C, < */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3D, = */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3E, > */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3F, ? */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 40, @ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 41, A */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 42, B */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 43, C */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 44, D */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 45, E */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 46, F */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 47, G */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 48, H */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 49, I */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4A, J */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4B, K */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4C, L */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4D, M */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4E, N */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4F, O */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 50, P */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 51, Q */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 52, R */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 53, S */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 54, T */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 55, U */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 56, V */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 57, W */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 58, X */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 59, Y */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 5A, Z */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 5B, [ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5C, \ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5D, ] */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5E, ^ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5F, _ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 60, ` */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 61, a */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 62, b */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 63, c */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 64, d */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 65, e */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 66, f */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 67, g */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 68, h */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 69, i */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6A, j */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6B, k */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6C, l */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6D, m */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6E, n */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6F, o */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 70, p */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 71, q */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 72, r */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 73, s */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 74, t */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 75, u */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 76, v */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 77, w */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 78, x */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 79, y */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 7A, z */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 7B, { */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7C, | */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7D, } */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7E, ~ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7F,DEL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 80, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 81, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 82, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 83, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 84, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 85, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 86, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 87, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 88, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 89, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 90, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 91, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 92, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 93, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 94, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 95, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 96, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 97, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 98, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 99, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* ED, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__ }; |
/programs/develop/open watcom/trunk/clib/src/itoa.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 itoa() and utoa(). |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdlib.h> |
extern const char __based(__segname("_CONST")) __Alphabet[]; |
unsigned __udiv( unsigned, unsigned _WCNEAR * ); |
#if defined(__386__) |
#pragma aux __udiv = \ |
"xor edx,edx" \ |
"div dword ptr [ebx]" \ |
"mov [ebx],eax" \ |
parm caller [eax] [ebx] \ |
modify exact [eax edx] \ |
value [edx]; |
#elif defined(M_I86) && defined(__BIG_DATA__) |
#pragma aux __udiv = \ |
"xor dx,dx" \ |
"div word ptr ss:[bx]" \ |
"mov ss:[bx],ax" \ |
parm caller [ax] [bx] \ |
modify exact [ax dx] \ |
value [dx]; |
#elif defined(M_I86) && defined(__SMALL_DATA__) |
#pragma aux __udiv = \ |
"xor dx,dx" \ |
"div word ptr [bx]" \ |
"mov [bx],ax" \ |
parm caller [ax] [bx] \ |
modify exact [ax dx] \ |
value [dx]; |
#endif |
_WCRTLINK CHAR_TYPE *__F_NAME(utoa,_utow)( unsigned value, CHAR_TYPE *buffer, int radix ) |
{ |
CHAR_TYPE *p = buffer; |
char *q; |
unsigned rem; |
unsigned quot; |
char buf[34]; // only holds ASCII so 'char' is OK |
buf[0] = '\0'; |
q = &buf[1]; |
do { |
#if defined(_M_IX86) && defined(__WATCOMC__) |
quot = radix; |
rem = __udiv( value, (unsigned _WCNEAR *) " ); |
#else |
rem = value % radix; |
quot = value / radix; |
#endif |
*q = __Alphabet[rem]; |
++q; |
value = quot; |
} while( value != 0 ); |
while( (*p++ = (CHAR_TYPE)*--q) ) |
; |
return( buffer ); |
} |
_WCRTLINK CHAR_TYPE *__F_NAME(itoa,_itow)( int value, CHAR_TYPE *buffer, int radix ) |
{ |
CHAR_TYPE *p = buffer; |
if( radix == 10 ) { |
if( value < 0 ) { |
*p++ = '-'; |
value = - value; |
} |
} |
__F_NAME(utoa,_utow)( value, p, radix ); |
return( buffer ); |
} |
/programs/develop/open watcom/trunk/clib/src/lltoa.c |
---|
0,0 → 1,212 |
/**************************************************************************** |
* |
* 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: Long long integer to ASCII conversion routines. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include "watcom.h" |
#include "clibi64.h" |
#include <stdlib.h> |
extern const char __based(__segname("_CONST")) __Alphabet[]; |
#if defined(__386__) || defined(M_I86) |
unsigned long long __ulldiv( unsigned long long, unsigned _WCNEAR *); |
#if defined(__386__) |
#pragma aux __ulldiv = \ |
"xor ecx,ecx" /* set high word of quotient to 0 */ \ |
"cmp edx,dword ptr[ebx]" /* if quotient will be >= 4G */ \ |
"jb less4g" /* then */ \ |
"mov ecx,eax" /* - save low word of dividend */ \ |
"mov eax,edx" /* - get high word of dividend */ \ |
"xor edx,edx" /* - zero high part */ \ |
"div dword ptr[ebx]" /* - divide into high part of dividend */ \ |
"xchg eax,ecx" /* - swap high part of quot,low word of dvdnd */ \ |
"less4g:" \ |
"div dword ptr[ebx]" /* calculate low part */ \ |
"mov [ebx],edx" /* store remainder */ \ |
parm [eax edx] [ebx] value [eax ecx]; |
#elif defined(M_I86) && defined(__BIG_DATA__) |
#pragma aux __ulldiv = \ |
"mov di,dx" /* initial dividend = ax:bx:cx:dx(di); save dx */ \ |
"test ax,ax" /* less work to do if ax == 0 */ \ |
"jz skip1" \ |
"mov dx,ax" /* dx:ax = ax:bx */ \ |
"mov ax,bx" \ |
"xor bx,bx" /* set word 3 of quotient to 0 */ \ |
"cmp dx,word ptr ss:[si]" /* if quotient will be >= 64K */ \ |
"jb div2" /* then */ \ |
"mov bx,ax" /* restore word 2 of dividend */ \ |
"mov ax,dx" /* restore word 3 of dividend */ \ |
"xor dx,dx" /* - zero high part */ \ |
"div word ptr ss:[si]" /* - divide into word 3 of dividend */ \ |
"xchg ax,bx" /* - swap word 3,word 2 of dvdnd */ \ |
"div2:" \ |
"div word ptr ss:[si]" /* - divide into word 2 of dividend */ \ |
"xchg ax,cx" /* - swap word 2,word 1 of dvdnd */ \ |
"div3:" \ |
"div word ptr ss:[si]" /* - divide into word 1 of dividend */ \ |
"xchg ax,di" /* - swap word 1,word 0 of dvdnd */ \ |
"div4:" \ |
"div word ptr ss:[si]" /* calculate low part */ \ |
"mov ss:[si],dx" /* store remainder */ \ |
"mov dx,ax" /* dx is word 0 */ \ |
"mov ax,bx" /* ax:bx:cx:dx = bx:cx:di:ax */ \ |
"mov bx,cx" \ |
"mov cx,di" \ |
"jmp end_div" \ |
"skip1:" /* ax==0 */ \ |
"test bx,bx" /* even less work to do if bx == 0 too */ \ |
"jz skip2" \ |
"mov dx,bx" /* dx:ax = bx:cx */ \ |
"mov ax,cx" \ |
"xor bx,bx" /* set word 3 of quotient to 0 */ \ |
"xor cx,cx" /* set word 2 of quotient to 0 */ \ |
"cmp dx,word ptr ss:[si]" /* if quotient will be < 64K */ \ |
"jb div3" /* then need to do two divisions */ \ |
"mov cx,ax" /* restore word 1 of dividend */ \ |
"mov ax,dx" /* restore word 2 of dividend */ \ |
"xor dx,dx" /* zero high part */ \ |
"jmp div2" /* do three divisions*/ \ |
"skip2:" /* ax==bx==0 */ \ |
"mov dx,cx" /* dx:ax = cx:di */ \ |
"mov ax,di" \ |
"xor cx,cx" /* set word 2 of quotient to 0 */ \ |
"xor di,di" /* set word 1 of quotient to 0 */ \ |
"cmp dx,word ptr ss:[si]" /* if quotient will be < 64K */ \ |
"jb div4" /* then only one division to do */ \ |
"mov di,ax" /* restore word 0 of dividend */ \ |
"mov ax,dx" /* restore word 1 of dividend */ \ |
"xor dx,dx" /* zero high part */ \ |
"jmp div3" /* do two divisions */ \ |
"end_div:" \ |
parm [ax bx cx dx] [si] modify [di] value [ax bx cx dx]; |
#elif defined(M_I86) && defined(__SMALL_DATA__) |
#pragma aux __ulldiv = \ |
"mov di,dx" /* initial dividend = ax:bx:cx:dx(di); save dx */ \ |
"test ax,ax" /* less work to do if ax == 0 */ \ |
"jz skip1" \ |
"mov dx,ax" /* dx:ax = ax:bx */ \ |
"mov ax,bx" \ |
"xor bx,bx" /* set word 3 of quotient to 0 */ \ |
"cmp dx,word ptr[si]" /* if quotient will be >= 64K */ \ |
"jb div2" /* then */ \ |
"mov bx,ax" /* restore word 2 of dividend */ \ |
"mov ax,dx" /* restore word 3 of dividend */ \ |
"xor dx,dx" /* - zero high part */ \ |
"div word ptr[si]" /* - divide into word 3 of dividend */ \ |
"xchg ax,bx" /* - swap word 3,word 2 of dvdnd */ \ |
"div2:" \ |
"div word ptr[si]" /* - divide into word 2 of dividend */ \ |
"xchg ax,cx" /* - swap word 2,word 1 of dvdnd */ \ |
"div3:" \ |
"div word ptr[si]" /* - divide into word 1 of dividend */ \ |
"xchg ax,di" /* - swap word 1,word 0 of dvdnd */ \ |
"div4:" \ |
"div word ptr[si]" /* calculate low part */ \ |
"mov [si],dx" /* store remainder */ \ |
"mov dx,ax" /* dx is word 0 */ \ |
"mov ax,bx" /* ax:bx:cx:dx = bx:cx:di:ax */ \ |
"mov bx,cx" \ |
"mov cx,di" \ |
"jmp end_div" \ |
"skip1:" /* dx==0 */ \ |
"test bx,bx" /* even less work to do if bx == 0 too */ \ |
"jz skip2" \ |
"mov dx,bx" /* dx:ax = bx:cx */ \ |
"mov ax,cx" \ |
"xor bx,bx" /* set word 3 of quotient to 0 */ \ |
"xor cx,cx" /* set word 2 of quotient to 0 */ \ |
"cmp dx,word ptr[si]" /* if quotient will be < 64K */ \ |
"jb div3" /* then need to do two divisions */ \ |
"mov cx,ax" /* restore word 1 of dividend */ \ |
"mov ax,dx" /* restore word 2 of dividend */ \ |
"xor dx,dx" /* zero high part */ \ |
"jmp div2" /* do three divisions*/ \ |
"skip2:" /* ax==bx==0 */ \ |
"mov dx,cx" /* dx:ax = cx:di */ \ |
"mov ax,di" \ |
"xor cx,cx" /* set word 2 of quotient to 0 */ \ |
"xor di,di" /* set word 1 of quotient to 0 */ \ |
"cmp dx,word ptr[si]" /* if quotient will be < 64K */ \ |
"jb div4" /* then only one division to do */ \ |
"mov di,ax" /* restore word 0 of dividend */ \ |
"mov ax,dx" /* restore word 1 of dividend */ \ |
"xor dx,dx" /* zero high part */ \ |
"jmp div3" /* do two divisions */ \ |
"end_div:" \ |
parm [ax bx cx dx] [si] modify [di] value [ax bx cx dx]; |
#endif |
#endif |
_WCRTLINK CHAR_TYPE *__F_NAME(ulltoa,_ulltow)( |
unsigned long long int value, |
CHAR_TYPE *buffer, |
int radix ) |
{ |
CHAR_TYPE *p = buffer; |
char *q; |
unsigned rem; |
auto char buf[66]; // only holds ASCII so 'char' is OK |
buf[0] = '\0'; |
q = &buf[1]; |
do { |
#if defined(__386__) || defined(M_I86) |
rem = radix; |
value = __ulldiv( value, (unsigned _WCNEAR *) &rem ); |
#else |
rem = value % radix; |
value = value / radix; |
#endif |
*q = __Alphabet[ rem ]; |
++q; |
} while( value ); |
while( *p++ = (CHAR_TYPE)*--q ); |
return( buffer ); |
} |
_WCRTLINK CHAR_TYPE *__F_NAME(lltoa,_lltow)( |
long long int value, |
CHAR_TYPE *buffer, |
int radix ) |
{ |
register CHAR_TYPE *p = buffer; |
if( radix == 10 ) { |
if( value < 0 ) { |
*p++ = '-'; |
value = -value; |
} |
} |
__F_NAME(ulltoa,_ulltow)( value, p, radix ); |
return( buffer ); |
} |
/programs/develop/open watcom/trunk/clib/src/lseekwnt.c |
---|
0,0 → 1,66 |
/**************************************************************************** |
* |
* 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: low level lseek without file extend for Windows NT |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include "iomode.h" |
#include "rtcheck.h" |
#include "seterrno.h" |
#include "lseek.h" |
#include "handleio.h" |
/* |
DWORD SetFilePointer( |
HANDLE hFile, // handle to file |
LONG lDistanceToMove, // bytes to move pointer |
PLONG lpDistanceToMoveHigh, // bytes to move pointer |
DWORD dwMoveMethod // starting point |
); |
*/ |
#ifndef INVALID_SET_FILE_POINTER |
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF |
#endif |
_WCRTLINK long __lseek( int hid, long offset, int origin ) |
{ |
DWORD rc; |
__handle_check( hid, -1 ); |
rc = offset; |
// rc = SetFilePointer( __getOSHandle( hid ), offset, 0, origin ); |
// if( rc == INVALID_SET_FILE_POINTER ) { |
// return( __set_errno_nt() ); |
// } |
return( rc ); |
} |
/programs/develop/open watcom/trunk/clib/src/ltoa.c |
---|
0,0 → 1,120 |
/**************************************************************************** |
* |
* 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 ltoa(). |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdlib.h> |
extern const char __based(__segname("_CONST")) __Alphabet[]; |
unsigned long __uldiv( unsigned long, unsigned _WCNEAR * ); |
#if defined(__386__) |
#pragma aux __uldiv = \ |
"xor edx,edx" \ |
"div dword ptr [ebx]" \ |
"mov [ebx],edx" \ |
parm caller [eax] [ebx] \ |
modify exact [eax edx] \ |
value [eax]; |
#elif defined(M_I86) && defined(__BIG_DATA__) |
#pragma aux __uldiv = \ |
"xor cx,cx" \ |
"cmp dx,ss:[bx]" \ |
"jb short SMALL_ENOUGH" \ |
"xchg ax,dx" \ |
"xchg cx,dx" \ |
"div word ptr ss:[bx]" \ |
"xchg ax,cx" \ |
"SMALL_ENOUGH:" \ |
"div word ptr ss:[bx]" \ |
"mov ss:[bx],dx" \ |
"mov dx,cx" \ |
parm caller [ax dx] [bx] \ |
modify exact [ax cx dx] \ |
value [ax dx]; |
#elif defined(M_I86) && defined(__SMALL_DATA__) |
#pragma aux __uldiv = \ |
"xor cx,cx" \ |
"cmp dx,[bx]" \ |
"jb short SMALL_ENOUGH" \ |
"xchg ax,dx" \ |
"xchg cx,dx" \ |
"div word ptr [bx]" \ |
"xchg ax,cx" \ |
"SMALL_ENOUGH:" \ |
"div word ptr [bx]" \ |
"mov [bx],dx" \ |
"mov dx,cx" \ |
parm caller [ax dx] [bx] \ |
modify exact [ax cx dx] \ |
value [ax dx]; |
#endif |
_WCRTLINK CHAR_TYPE *__F_NAME(ultoa,_ultow)( unsigned long value, CHAR_TYPE *buffer, int radix ) |
{ |
CHAR_TYPE *p = buffer; |
char *q; |
unsigned rem; |
char buf[34]; // only holds ASCII so 'char' is OK |
buf[0] = '\0'; |
q = &buf[1]; |
do { |
#if defined(_M_IX86) && defined(__WATCOMC__) |
rem = radix; |
value = __uldiv( value, (unsigned _WCNEAR *) &rem ); |
#else |
rem = value % radix; |
value = value / radix; |
#endif |
*q = __Alphabet[rem]; |
++q; |
} while( value != 0 ); |
while( (*p++ = (CHAR_TYPE)*--q) ) |
; |
return( buffer ); |
} |
_WCRTLINK CHAR_TYPE *__F_NAME(ltoa,_ltow)( long value, CHAR_TYPE *buffer, int radix ) |
{ |
CHAR_TYPE *p = buffer; |
if( radix == 10 ) { |
if( value < 0 ) { |
*p++ = '-'; |
value = - value; |
} |
} |
__F_NAME(ultoa,_ultow)( value, p, radix ); |
return( buffer ); |
} |
/programs/develop/open watcom/trunk/clib/src/mbinit.c |
---|
0,0 → 1,306 |
/**************************************************************************** |
* |
* 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 <mbstring.h> |
#include "mbchar.h" |
unsigned int __MBCodePage = 0; /* default code page */ |
static void set_dbcs_table( int low, int high ) |
{ |
memset( __MBCSIsTable + low + 1, _MB_LEAD, high - low + 1 ); |
} |
static void clear_dbcs_table( void ) |
{ |
__IsDBCS = 0; /* SBCS for now */ |
__MBCodePage = 0; |
memset( __MBCSIsTable, 0, 257 ); |
} |
/**** |
***** Initialize a multi-byte character set. Returns 0 on success. |
****/ |
int __mbinit( int codepage ) |
{ |
/*** Handle values from _setmbcp ***/ |
if( codepage == _MBINIT_CP_ANSI ) |
{ |
codepage = 0; |
} |
else |
if( codepage == _MBINIT_CP_OEM ) |
{ |
codepage = 0; |
} |
else |
if( codepage == _MBINIT_CP_SBCS ) |
{ |
clear_dbcs_table(); |
return( 0 ); |
} |
else |
if( codepage == _MBINIT_CP_932 ) |
{ |
clear_dbcs_table(); |
set_dbcs_table( 0x81, 0x9F ); |
set_dbcs_table( 0xE0, 0xFC ); |
__IsDBCS = 1; |
__MBCodePage = 932; |
return( 0 ); |
} |
return( 0 ); /* return success code */ |
} |
/**** |
***** Query DOS to find the valid lead byte ranges. |
****/ |
#if defined(__DOS__) && !defined(__OSI__) |
#ifndef __386__ |
// for some unknown reason NT DPMI returns for DOS service 6300h |
// Carry=0, odd SI value and DS stay unchanged |
// this case is also tested as wrong int 21h result |
#if 1 |
#pragma aux dos_get_dbcs_lead_table = \ |
"push ds" \ |
"xor ax,ax" \ |
"mov ds,ax" \ |
"mov ah,63h" /* get DBCS vector table */ \ |
"int 21h" \ |
"mov di,ds" \ |
"jnc label1" \ |
"xor di,di" \ |
"label1:" \ |
"test di,di" \ |
"jnz exit1" \ |
"mov si,di" \ |
"exit1:" \ |
"pop ds" \ |
value [di si] \ |
modify [ax bx cx dx si di es]; |
#else |
unsigned short _WCFAR *dos_get_dbcs_lead_table( void ) |
/****************************************************/ |
{ |
union REGS regs; |
struct SREGS sregs; |
regs.w.ax = 0x6300; /* get lead byte table code */ |
sregs.ds = 0; |
sregs.es = 0; |
intdosx( ®s, ®s, &sregs ); /* call DOS */ |
if( regs.w.cflag || ( sregs.ds == 0 )) /* ensure function succeeded */ |
return( NULL ); |
return( MK_FP( sregs.ds, regs.w.si ) ); /* return pointer to table */ |
} |
#endif |
#if 0 |
unsigned short dos_get_code_page( void ) |
/**************************************/ |
{ |
union REGS regs; |
struct SREGS sregs; |
unsigned char buf[7]; |
regs.w.ax = 0x6501; /* get international info */ |
regs.w.bx = 0xFFFF; /* global code page */ |
regs.w.cx = 7; /* buffer size */ |
regs.w.dx = 0xFFFF; /* current country */ |
regs.w.di = FP_OFF( (void __far*)buf ); /* buffer offset */ |
sregs.es = FP_SEG( (void __far*)buf ); /* buffer segment */ |
sregs.ds = 0; /* in protected mode (dos16m) DS must be initialized */ |
intdosx( ®s, ®s, &sregs ); /* call DOS */ |
if( regs.w.cflag ) return( 0 ); /* ensure function succeeded */ |
return( * (unsigned short*)(buf+5) ); /* return code page */ |
} |
#else |
#pragma aux dos_get_code_page = \ |
"push ds" \ |
"push bp" \ |
"mov bp,sp" \ |
"sub sp,8" \ |
"xor ax,ax" \ |
"mov ds,ax" \ |
"mov ax,6501h" /* get international info */ \ |
"mov bx,0ffffh" /* global code page */ \ |
"mov cx,0007h" /* buffer size */ \ |
"mov dx,0ffffh" /* current country */ \ |
"lea di,[bp-8]" /* buffer offset */ \ |
"push ss" \ |
"pop es" /* buffer segment */ \ |
"int 21h" /* call DOS */ \ |
"mov ax,[bp-8+5]" /* code page */ \ |
"jnc NoError" \ |
"xor ax,ax" \ |
"NoError:" \ |
"mov sp,bp" \ |
"pop bp" \ |
"pop ds" \ |
value [ax] \ |
modify [ax bx cx dx di es]; |
#endif |
#else |
#pragma pack(__push,1); |
typedef struct { |
unsigned short int_num; |
unsigned short real_ds; |
unsigned short real_es; |
unsigned short real_fs; |
unsigned short real_gs; |
unsigned long real_eax; |
unsigned long real_edx; |
} PHARLAP_block; |
#pragma pack(__pop); |
unsigned short _WCFAR *dos_get_dbcs_lead_table( void ) |
/****************************************************/ |
{ |
union REGPACK regs; |
if( _IsPharLap() ) { |
PHARLAP_block pblock; |
memset( &pblock, 0, sizeof( pblock ) ); |
memset( ®s, 0, sizeof( regs ) ); |
pblock.real_eax = 0x6300; /* get DBCS vector table */ |
pblock.int_num = 0x21; /* DOS call */ |
regs.x.eax = 0x2511; /* issue real-mode interrupt */ |
regs.x.edx = FP_OFF( &pblock ); /* DS:EDX -> parameter block */ |
regs.w.ds = FP_SEG( &pblock ); |
intr( 0x21, ®s ); |
if( pblock.real_ds != 0xFFFF ) { /* weird OS/2 value */ |
return( MK_FP( _ExtenderRealModeSelector, |
(((unsigned)pblock.real_ds)<<4) + regs.w.si ) ); |
} |
} else if( _IsRational() ) { |
rm_call_struct dblock; |
memset( &dblock, 0, sizeof( dblock ) ); |
dblock.eax = 0x6300; /* get DBCS vector table */ |
DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); |
if( (dblock.flags & 1) == 0 ) { |
return( MK_FP( _ExtenderRealModeSelector, |
(((unsigned)dblock.ds)<<4) + dblock.esi ) ); |
} |
} |
return( NULL ); |
} |
unsigned short dos_get_code_page( void ) |
/**************************************/ |
{ |
union REGPACK regs; |
unsigned short __far * temp; |
unsigned short real_seg; |
unsigned short codepage = 0; |
/*** Get the code page ***/ |
if( _IsPharLap() ) { |
union REGS r; |
PHARLAP_block pblock; |
/*** Alloc DOS Memory under Phar Lap ***/ |
memset( &r, 0, sizeof( r ) ); |
r.x.ebx = 1; |
r.x.eax = 0x25c0; |
intdos( &r, &r ); |
real_seg = r.w.ax; |
memset( &pblock, 0, sizeof( pblock ) ); |
memset( ®s, 0, sizeof( regs ) ); |
pblock.real_eax = 0x6501; /* get international info */ |
pblock.real_edx = 0xFFFF; /* current country */ |
pblock.real_es = real_seg; /* buffer segment */ |
regs.x.ebx = 0xFFFF; /* global code page */ |
regs.x.ecx = 7; /* buffer size */ |
regs.x.edi = 0; /* buffer offset */ |
pblock.int_num = 0x21; /* DOS call */ |
regs.x.eax = 0x2511; /* issue real-mode interrupt */ |
regs.x.edx = FP_OFF( &pblock ); /* DS:EDX -> parameter block */ |
regs.w.ds = FP_SEG( &pblock ); |
intr( 0x21, ®s ); |
if( pblock.real_ds != 0xFFFF ) { /* weird OS/2 value */ |
temp = MK_FP( _ExtenderRealModeSelector, (real_seg<<4) + 5 ); |
codepage = *temp; |
} |
/*** Free DOS Memory under Phar Lap ***/ |
r.x.ecx = real_seg; |
r.x.eax = 0x25c1; |
intdos( &r, &r ); |
} else if( _IsRational() ) { |
unsigned long dpmi_rc; |
unsigned short selector; |
rm_call_struct dblock; |
/*** Allocate some DOS memory with DPMI ***/ |
dpmi_rc = DPMIAllocateDOSMemoryBlock( 1 ); /* one paragraph is enough */ |
real_seg = (unsigned short) dpmi_rc; |
selector = (unsigned short) (dpmi_rc>>16); |
memset( &dblock, 0, sizeof( dblock ) ); |
dblock.eax = 0x6501; /* get international info */ |
dblock.ebx = 0xFFFF; /* global code page */ |
dblock.ecx = 7; /* buffer size */ |
dblock.edx = 0xFFFF; /* current country */ |
dblock.edi = 0; /* buffer offset */ |
dblock.es = real_seg; /* buffer segment */ |
DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); |
if( (dblock.flags & 1) == 0 ) { |
temp = MK_FP( _ExtenderRealModeSelector, (real_seg<<4) + 5 ); |
codepage = *temp; |
} |
/*** Free DOS memory with DPMI ***/ |
DPMIFreeDOSMemoryBlock( selector ); |
} |
return( codepage ); |
} |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/src/mbisdbcs.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* 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 <mbstring.h> |
#include "rtinit.h" |
_WCRTLINKD int __IsDBCS; |
/programs/develop/open watcom/trunk/clib/src/mbislead.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <mbstring.h> |
#include "mbchar.h" |
#include "rtinit.h" |
_WCRTLINKD unsigned char __MBCSIsTable[257]; |
/** |
* Determine whether or not the specified byte is a lead byte. |
*/ |
_WCRTLINK int (_ismbblead)( const unsigned int ch ) |
{ |
return( __MBCSIsTable[ch+1] & _MB_LEAD ); |
} |
/** |
* If this module is linked in, the startup code will call this function, |
* which will initialize the default multibyte code page. |
*/ |
static void __mbInitOnStartup( void ) |
{ |
__mbinit( 0 ); |
} |
AXI( __mbInitOnStartup, INIT_PRIORITY_LIBRARY ) |
/programs/develop/open watcom/trunk/clib/src/mbtowc.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 <mbstring.h> |
#include "farfunc.h" |
/**** |
***** Convert a multibyte character to a wide character. |
****/ |
_WCRTLINK int _NEARFAR(mbtowc,_fmbtowc)( wchar_t _FFAR *pwc, const char _FFAR *ch, size_t n ) |
{ |
/*** Catch special cases ***/ |
if( ch == NULL ) return( 0 ); |
if( n == 0 ) return( -1 ); |
if( *ch == '\0' ) { |
if( pwc != NULL ) *pwc = L'\0'; |
return( 0 ); |
} |
if( _ismbblead( ch[0] ) && ch[1] == '\0' ) return( -1 ); /* invalid */ |
/*** Convert the character ***/ |
if( _ismbblead(*ch) && n>=2 ) { /* lead byte present? */ |
if( pwc != NULL ) { |
*pwc = (((wchar_t)ch[0])<<8) | /* convert to lead:trail */ |
(wchar_t)ch[1]; |
} |
return( 2 ); /* return char size */ |
} else if( !_ismbblead(*ch) ) { |
if( pwc != NULL ) { |
*pwc = (wchar_t)ch[0]; /* convert to 00:byte */ |
} |
return( 1 ); /* return char size */ |
} else { |
return( -1 ); /* n==1, but char 2 bytes */ |
} |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/printf.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 printf() - formatted output. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include "farsupp.h" |
#include "printf.h" |
#include "fprtf.h" |
void debug_out_str(const char* str); |
void _stdcall debug_out(int ch); |
static char _dest[512]; |
_WCRTLINK int __F_NAME(printf,wprintf)( const CHAR_TYPE *format, ... ) |
{ |
int retval; |
auto va_list args; |
va_start( args, format ); |
// return( __F_NAME(__fprtf,__fwprtf)( stdout, format, args ) ); |
va_start( args, format ); |
#ifdef __WIDECHAR__ |
retval = _vswprintf( _dest, format, args ); |
#else |
retval = vsprintf( _dest, format, args ); |
#endif |
debug_out_str(_dest); |
return retval; |
} |
void debug_out_str(const char* str) |
{ |
while (*str != 0) |
{ |
debug_out(*str); |
str++; |
} |
} |
/programs/develop/open watcom/trunk/clib/src/prtf.c |
---|
0,0 → 1,1100 |
/**************************************************************************** |
* |
* 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: __prtf() - low level string formatter. |
* |
****************************************************************************/ |
#define __LONG_LONG_SUPPORT__ |
#if !defined( __NETWARE__ ) && !defined( __UNIX__ ) |
#define USE_MBCS_TRANSLATION |
#endif |
#include "variety.h" |
#ifdef SAFE_PRINTF |
#include "saferlib.h" |
#endif |
#include "widechar.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdlib.h> |
#include <string.h> |
#include <ctype.h> |
#if defined( __WIDECHAR__ ) || defined( USE_MBCS_TRANSLATION ) |
#include <mbstring.h> |
#endif |
#include "ftos.h" |
#include "farsupp.h" |
#include "printf.h" |
#include "prtscncf.h" |
#include "fixpoint.h" |
#include "myvalist.h" |
#define BUF_SIZE 72 /* 64-bit ints formatted as binary can get big */ |
#define TRUE 1 |
#define FALSE 0 |
#define PASCAL_STRING 'S' /* for Novell */ |
#define WIDE_CHAR_STRING 'S' |
#if defined( __QNX_386__ ) |
/* for use in QNX 32-bit shared library */ |
#pragma aux __prtf "_sl_*" far; |
#endif |
#if defined( __QNX__ ) |
#define EFG_PRINTF __EFG_Format |
#else |
#define EFG_PRINTF (*__EFG_printf) |
#endif |
extern FAR_STRING EFG_PRINTF( char *buffer, my_va_list *args, _mbcs_SPECS __SLIB *specs ); |
#if defined( __WIDECHAR__ ) |
#define _FAR_OTHER_STRING FAR_ASCII_STRING |
#else |
#define _FAR_OTHER_STRING FAR_UNI_STRING |
#endif |
#if defined( __WINDOWS_386__ ) |
#ifdef __SW_3S |
#pragma aux slib_callback_t modify [eax edx ecx fs gs]; |
#else |
#pragma aux slib_callback_t modify [fs gs]; |
#endif |
#endif |
/* forward references */ |
static const CHAR_TYPE *evalflags( const CHAR_TYPE *, SPECS __SLIB * ); |
static FAR_STRING formstring( CHAR_TYPE *, my_va_list *, SPECS __SLIB *, CHAR_TYPE * ); |
static const CHAR_TYPE * getprintspecs( const CHAR_TYPE *, my_va_list *, SPECS __SLIB * ); |
#ifdef USE_MBCS_TRANSLATION |
static void write_wide_string( FAR_UNI_STRING str, SPECS *specs, |
slib_callback_t *out_putc ); |
static void write_skinny_string( FAR_ASCII_STRING str, SPECS *specs, |
slib_callback_t *out_putc ); |
#endif |
#ifdef SAFE_PRINTF |
int __F_NAME(__prtf_s,__wprtf_s) |
#else |
int __F_NAME(__prtf,__wprtf) |
#endif |
( void __SLIB *dest, /* parm for use by out_putc */ |
const CHAR_TYPE *format, /* pointer to format string */ |
va_list args, /* pointer to pointer to args*/ |
#ifdef SAFE_PRINTF |
const char **msg, /* rt-constraint message */ |
#endif |
slib_callback_t *out_putc ) /* char output routine */ |
{ |
CHAR_TYPE buffer[ BUF_SIZE ]; |
CHAR_TYPE null_char = '\0'; |
CHAR_TYPE *a; |
FAR_STRING arg; |
const CHAR_TYPE *ctl; |
SPECS specs; |
specs._dest = dest; |
specs._flags = 0; |
specs._version = SPECS_VERSION; |
specs._output_count = 0; |
ctl = format; |
while( *ctl != NULLCHAR ) { |
if( *ctl != '%' ) { |
(out_putc)( &specs, *ctl++ ); |
} else { |
++ctl; |
{ |
my_va_list pargs; |
pargs = MY_VA_LIST( args ); |
ctl = getprintspecs( ctl, &pargs, &specs ); |
MY_VA_LIST( args ) = pargs; |
} |
specs._character = *ctl++; |
if( specs._character == NULLCHAR ) |
break; /* 05-jan-89 */ |
if( specs._character == 'n' ) { |
#ifdef SAFE_PRINTF |
/* The %n specifier is not allowed - too dangerous. */ |
*msg = "%n"; |
break; |
#else |
FAR_INT iptr; |
#if defined( __FAR_SUPPORT__ ) |
if( specs._flags & SPF_FAR ) { |
iptr = va_arg( args, int _WCFAR * ); |
} else if( specs._flags & SPF_NEAR ) { |
iptr = va_arg( args, int _WCNEAR * ); |
} else { |
iptr = va_arg( args, int * ); |
} |
#else |
iptr = va_arg( args, int * ); |
#endif |
if( specs._flags & SPF_CHAR ) { |
*((FAR_CHAR)iptr) = specs._output_count; |
} else if( specs._flags & SPF_SHORT ) { |
*((FAR_SHORT)iptr) = specs._output_count; |
} else if( specs._flags & SPF_LONG ) { |
*((FAR_LONG)iptr) = specs._output_count; |
#if defined( __LONG_LONG_SUPPORT__ ) |
} else if( specs._flags & SPF_LONG_LONG ) { |
*((FAR_INT64)iptr) = specs._output_count; |
#endif |
} else { |
*iptr = specs._output_count; |
} |
#endif /* SAFE_PRINTF */ |
} else { |
#ifdef SAFE_PRINTF |
if( specs._character == 's' || specs._character == 'S' ) { |
FAR_STRING str; |
va_list args_copy; |
/* Make sure %s argument is not NULL. Note that near pointers |
* in segmented models need special handling because only |
* offset will be NULL, not segment. |
*/ |
va_copy( args_copy, args ); |
#if defined( __FAR_SUPPORT__ ) |
if( specs._flags & SPF_FAR ) { |
str = va_arg( args_copy, CHAR_TYPE _WCFAR * ); |
} else if( specs._flags & SPF_NEAR ) { |
CHAR_TYPE _WCNEAR *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE _WCNEAR * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} else { |
CHAR_TYPE *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} |
#else |
str = va_arg( args_copy, CHAR_TYPE * ); |
#endif |
va_end( args_copy ); |
if( str == NULL ) { |
*msg = "%s -> NULL"; |
break; /* bail out */ |
} |
} |
#endif /* SAFE_PRINTF */ |
{ |
my_va_list pargs; |
pargs = MY_VA_LIST( args ); |
arg = formstring( buffer, &pargs, &specs, &null_char ); |
MY_VA_LIST( args ) = pargs; |
} |
specs._fld_width -= specs._n0 + |
specs._nz0 + |
specs._n1 + |
specs._nz1 + |
specs._n2 + |
specs._nz2; |
if( !(specs._flags & SPF_LEFT_ADJUST) ) { |
if( specs._pad_char == ' ' ) { |
while( specs._fld_width > 0 ) { |
(out_putc)( &specs, ' ' ); |
--specs._fld_width; |
} |
} |
} |
a = buffer; |
while( specs._n0 > 0 ) { |
(out_putc)( &specs, *a ); |
++a; |
--specs._n0; |
} |
while( specs._nz0 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz0; |
} |
if( specs._character == 's' ) { |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs._flags & SPF_SHORT ) { |
write_skinny_string( (FAR_ASCII_STRING)arg, &specs, out_putc ); |
} else |
#elif !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs._flags & SPF_LONG ) { |
write_wide_string( (FAR_UNI_STRING)arg, &specs, out_putc ); |
} else |
#endif |
{ |
while( specs._n1 > 0 ) { |
(out_putc)( &specs, *arg++ ); |
--specs._n1; |
} |
} |
} |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
else if( specs._character == WIDE_CHAR_STRING ) { |
write_wide_string( (FAR_UNI_STRING)arg, &specs, out_putc ); |
} else |
#elif !defined( __WIDECHAR__ ) && defined( __NETWARE__ ) |
else if( specs._character == WIDE_CHAR_STRING ) { |
} else |
#endif |
{ |
while( specs._n1 > 0 ) { |
(out_putc)( &specs, *arg++ ); |
--specs._n1; |
} |
} |
while( specs._nz1 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz1; |
} |
while( specs._n2 > 0 ) { |
(out_putc)( &specs, *arg ); |
++arg; |
--specs._n2; |
} |
while( specs._nz2 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz2; |
} |
if( specs._flags & SPF_LEFT_ADJUST ) { |
while( specs._fld_width > 0 ) { |
(out_putc)( &specs, ' ' ); |
--specs._fld_width; |
} |
} |
} |
} |
} |
return( specs._output_count ); |
} |
static const CHAR_TYPE * getprintspecs( const CHAR_TYPE *ctl, |
my_va_list *pargs, |
SPECS __SLIB *specs ) |
{ |
specs->_pad_char = ' '; |
ctl = evalflags( ctl, specs ); |
specs->_fld_width = 0; |
if( *ctl == '*' ) { |
specs->_fld_width = va_arg( pargs->v, int ); |
if( specs->_fld_width < 0 ) { |
specs->_fld_width = - specs->_fld_width; |
specs->_flags |= SPF_LEFT_ADJUST; |
} |
ctl++; |
} else { |
while(( *ctl >= '0' ) && ( *ctl <= '9' )) { |
specs->_fld_width = specs->_fld_width * 10 + ( *ctl++ - '0' ); |
} |
} |
specs->_prec = -1; |
if( *ctl == '.' ) { |
specs->_prec = 0; |
ctl++; |
if( *ctl == '*' ) { |
specs->_prec = va_arg( pargs->v, int ); |
if( specs->_prec < 0 ) |
specs->_prec = -1; /* 19-jul-90 */ |
ctl++; |
} else { |
while(( *ctl >= '0' ) && ( *ctl <= '9' )) { |
specs->_prec = specs->_prec * 10 + ( *ctl++ - '0' ); |
} |
} |
/* |
"For b, d, i, o, u, x, X, e, E, f, g and G conversions, leading |
zeros (following any indication of sign or base) are used to |
pad the field width; no space padding is performed. If the 0 |
or - flags both appear, the 0 flag is ignored. For b, d, i, o, |
u, x or X conversions, if a precision is specified, the 0 flag |
is ignored. For other conversions, the behaviour is undefined." |
*/ |
// if( specs->_prec != -1 ) specs->_pad_char = ' '; /* 30-jul-95 *//*removed by JBS*/ |
} |
switch( *ctl ) { |
case 'l': |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( ctl[1] == 'l' ) { |
specs->_flags |= SPF_LONG_LONG; |
ctl += 2; |
break; |
} |
#endif |
/* fall through */ |
ZSPEC_CASE_LONG |
TSPEC_CASE_LONG |
case 'w': |
specs->_flags |= SPF_LONG; |
ctl++; |
break; |
case 'h': |
if( ctl[1] == 'h' ) { |
specs->_flags |= SPF_CHAR; |
ctl += 2; |
break; |
} |
specs->_flags |= SPF_SHORT; |
ctl++; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
case 'I': |
if(( ctl[1] == '6' ) && ( ctl[2] == '4' )) { |
specs->_flags |= SPF_LONG_LONG; |
ctl += 3; |
} |
break; |
JSPEC_CASE_LLONG |
/* fall through */ |
#endif |
case 'L': |
specs->_flags |= SPF_LONG_DOUBLE | SPF_LONG_LONG; |
ctl++; |
break; |
#if defined( __FAR_SUPPORT__ ) |
case 'F': /* conflicts with ISO-defined 'F' conversion */ |
/* fall through */ |
#endif |
case 'W': /* 8086 specific flag for FAR pointer */ |
specs->_flags |= SPF_FAR; |
ctl++; |
break; |
case 'N': /* 8086 specific flag for NEAR pointer */ |
specs->_flags |= SPF_NEAR; |
ctl++; |
break; |
#if defined( TSPEC_IS_INT ) || defined( ZSPEC_IS_INT ) |
TSPEC_CASE_INT /* If either 't' or 'z' spec corresponds to 'int', */ |
ZSPEC_CASE_INT /* we need to parse and ignore the spec. */ |
ctl++; |
break; |
#endif |
} |
return( ctl ); |
} |
static const CHAR_TYPE *evalflags( const CHAR_TYPE *ctl, SPECS __SLIB *specs ) |
{ |
specs->_flags = 0; |
for( ; ; ctl++ ) { |
if( *ctl == '-' ) { |
specs->_flags |= SPF_LEFT_ADJUST; |
} else if( *ctl == '#' ) { |
specs->_flags |= SPF_ALT; |
} else if( *ctl == '+' ) { |
specs->_flags |= SPF_FORCE_SIGN; |
specs->_flags &= ~SPF_BLANK; |
} else if( *ctl == ' ' ) { |
if( ( specs->_flags & SPF_FORCE_SIGN ) == 0 ) { |
specs->_flags |= SPF_BLANK; |
} |
} else if( *ctl == '0' ) { |
specs->_pad_char = '0'; |
#ifdef __QNX__ |
specs->_flags |= SPF_ZERO_PAD; |
#endif |
} else { |
break; |
} |
} |
return( ctl ); |
} |
static int far_strlen( FAR_STRING s, int precision ) |
{ |
int len; |
len = 0; |
while(( len != precision ) && ( *s++ != NULLCHAR )) |
++len; |
return( len ); |
} |
/* |
* far_other_strlen - calculates the length of an ascii string |
* for the unicode version |
* - calculates the length of a unicode string for |
* the standard version |
*/ |
static int far_other_strlen( FAR_STRING s, int precision ) |
{ |
int len = 0; |
_FAR_OTHER_STRING ptr = (_FAR_OTHER_STRING)s; |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
char mbBuf[MB_CUR_MAX]; |
int chBytes; |
if( precision == -1 ) { |
while( *ptr ) { |
chBytes = wctomb( mbBuf, *ptr++ ); |
if( chBytes != -1 ) { |
len += chBytes; |
} |
} |
return( len ); |
} |
while( *ptr && ( len <= precision )) { |
chBytes = wctomb( mbBuf, *ptr++ ); |
if( chBytes != -1 ) { |
len += chBytes; |
} |
} |
return(( len <= precision ) ? len : precision ); |
#else |
while( *ptr++ && ( len != precision )) |
++len; |
return( len ); |
#endif |
} |
static void fmt4hex( unsigned value, CHAR_TYPE *buf, int maxlen ) |
{ |
int i, len; |
__F_NAME(itoa,_itow)( value, buf, 16 ); |
len = __F_NAME(strlen,wcslen)( buf ); |
for( i = maxlen - 1; len; --i ) { |
--len; |
buf[i] = buf[len]; |
} |
while( i >= 0 ) { |
buf[i] = '0'; |
--i; |
} |
buf[maxlen] = NULLCHAR; |
} |
static void FixedPoint_Format( CHAR_TYPE *buf, long value, SPECS __SLIB *specs ) |
{ |
T32 at; |
int i; |
CHAR_TYPE *bufp; |
at.sWhole = value; |
if( at.sWhole < 0 ) { |
at.sWhole = - at.sWhole; |
*buf++ = '-'; |
} |
if( specs->_prec == -1 ) |
specs->_prec = 4; |
__F_NAME(itoa,_itow)( at.wd.hi, buf, 10 ); |
bufp = buf; /* remember start address of buffer */ |
while( *buf ) |
++buf; |
if( specs->_prec != 0 ) { |
*buf++ = '.'; |
for( i = 0; i < specs->_prec; i++ ) { |
at.wd.hi = 0; |
at.uWhole *= 10; |
*buf++ = at.bite.b3 + '0'; |
} |
*buf = NULLCHAR; |
} |
if( at.wd.lo & 0x8000 ) { /* fraction >= .5, need to round */ |
for(;;) { /* 22-dec-91 */ |
if( buf == bufp ) { |
*buf++ = '1'; |
while( *buf == '0' ) |
++buf; |
if( *buf == '.' ) { |
*buf++ = '0'; |
*buf++ = '.'; |
while( *buf == '0' ) { |
++buf; |
} |
} |
*buf++ = '0'; |
*buf = NULLCHAR; |
break; |
} |
--buf; |
if( *buf == '.' ) |
--buf; |
if( *buf != '9' ) { |
++ *buf; |
break; |
} |
*buf = '0'; |
} |
} |
} |
static void float_format( CHAR_TYPE *buffer, my_va_list *pargs, SPECS __SLIB *specs ) |
{ |
#ifdef __WIDECHAR__ |
char mbBuffer[BUF_SIZE*MB_CUR_MAX]; |
_mbcs_SPECS mbSpecs; |
int count; |
size_t rc; |
char *p; |
#endif // __WIDECHAR__ |
#ifdef __WIDECHAR__ |
/* |
* EFG_PRINTF can only handle MBCS buffers and the MBCS version of the |
* SPECS structure. So, make a _mbcs_SPECS structure equivalent to the |
* _wide_SPECS one, and use that instead. Note that we can't use |
* memcpy() because some field sizes are different. |
*/ |
mbSpecs._dest = NULL; /* this field isn't actually used */ |
mbSpecs._flags = specs->_flags; |
mbSpecs._version = specs->_version; |
mbSpecs._fld_width = specs->_fld_width; |
mbSpecs._prec = specs->_prec; |
mbSpecs._output_count = specs->_output_count; |
mbSpecs._n0 = specs->_n0; |
mbSpecs._nz0 = specs->_nz0; |
mbSpecs._n1 = specs->_n1; |
mbSpecs._nz1 = specs->_nz1; |
mbSpecs._n2 = specs->_n2; |
mbSpecs._nz2 = specs->_nz2; |
mbSpecs._character = (char)specs->_character; |
mbSpecs._pad_char = (char)specs->_pad_char; |
#endif |
#ifdef __WIDECHAR__ |
EFG_PRINTF( mbBuffer, pargs, &mbSpecs ); |
#else |
EFG_PRINTF( buffer, pargs, specs ); |
#endif |
#ifdef __WIDECHAR__ |
/* |
* Now convert the returned information back into our _wide_SPECS |
* structure. We can't just use mbstowcs because it's an array of |
* characters, not a string. |
*/ |
p = mbBuffer; |
for( count = 0; count < BUF_SIZE; count++ ) { |
rc = mbtowc( &(buffer[count]), p, MB_CUR_MAX ); |
if( rc == -1 ) { |
buffer[count] = L'?'; |
} |
p = _mbsinc( p ); |
} |
specs->_flags = mbSpecs._flags; |
specs->_version = mbSpecs._version; |
specs->_fld_width = mbSpecs._fld_width; |
specs->_prec = mbSpecs._prec; |
specs->_output_count = mbSpecs._output_count; |
specs->_n0 = mbSpecs._n0; |
specs->_nz0 = mbSpecs._nz0; |
specs->_n1 = mbSpecs._n1; |
specs->_nz1 = mbSpecs._nz1; |
specs->_n2 = mbSpecs._n2; |
specs->_nz2 = mbSpecs._nz2; |
specs->_character = (wchar_t) mbSpecs._character; |
specs->_pad_char = (wchar_t) mbSpecs._pad_char; |
#endif |
} |
static void SetZeroPad( SPECS __SLIB *specs ) |
{ |
int n; |
if( !(specs->_flags & SPF_LEFT_ADJUST) ) { |
if( specs->_pad_char == '0' ) { |
n = specs->_fld_width - specs->_n0 - specs->_nz0 - |
specs->_n1 - specs->_nz1 - specs->_n2 - specs->_nz2; |
if( n > 0 ) { |
specs->_nz0 += n; |
} |
} |
} |
} |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
static void write_wide_string( FAR_UNI_STRING str, SPECS *specs, |
slib_callback_t *out_putc ) |
{ |
int bytes; |
char mbBuf[MB_CUR_MAX]; |
char *mbBufPtr; |
while( specs->_n1 > 0 ) { |
bytes = wctomb( mbBuf, *str++ ); |
if( bytes != -1 ) { |
if( bytes <= specs->_n1 ) { |
mbBufPtr = mbBuf; |
while( bytes-- ) { |
(out_putc)( specs, *mbBufPtr++ ); |
--specs->_n1; |
} |
} else { |
specs->_n1 = 0; |
} |
} |
} |
} |
#endif |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
static void write_skinny_string( FAR_ASCII_STRING str, SPECS *specs, |
slib_callback_t *out_putc ) |
{ |
int bytes; |
wchar_t wc; |
FAR_ASCII_STRING mbPtr = str; |
char mbBuf[MB_CUR_MAX]; |
while( specs->_n1 > 0 ) { |
mbBuf[0] = *mbPtr++; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = *mbPtr++; |
bytes = mbtowc( &wc, mbBuf, MB_CUR_MAX ); |
if( bytes <= specs->_n1 ) { |
if( bytes != -1 ) { |
(out_putc)( specs, wc ); |
specs->_n1 -= bytes; |
} |
} else { |
specs->_n1 = 0; |
} |
} |
} |
#endif |
static FAR_STRING formstring( CHAR_TYPE *buffer, my_va_list *pargs, |
SPECS __SLIB *specs, CHAR_TYPE *null_string ) |
{ |
FAR_STRING arg; |
int length; |
int radix; |
#if defined( __LONG_LONG_SUPPORT__ ) |
unsigned long long long_long_value; |
#endif |
unsigned long long_value; |
unsigned int int_value; |
#if defined( __FAR_SUPPORT__ ) |
unsigned int seg_value; |
#endif |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
int bytes; |
#endif |
arg = buffer; |
specs->_n0 = specs->_nz0 = |
specs->_n1 = specs->_nz1 = |
specs->_n2 = specs->_nz2 = 0; |
if( ( specs->_character == 'b' ) || |
( specs->_character == 'o' ) || |
( specs->_character == 'u' ) || |
( specs->_character == 'x' ) || |
( specs->_character == 'X' ) ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = va_arg( pargs->v, unsigned long long ); |
} else |
#endif |
if( specs->_flags & SPF_LONG ) { |
long_value = va_arg( pargs->v, unsigned long ); |
} else { |
long_value = va_arg( pargs->v, unsigned ); |
if( specs->_flags & SPF_SHORT ) { /* JBS 92/02/12 */ |
long_value = (unsigned short) long_value; |
} else if( specs->_flags & SPF_CHAR ) { |
long_value = (unsigned char)long_value; |
} |
} |
} else |
if( ( specs->_character == 'd' ) || |
( specs->_character == 'i' ) ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = va_arg( pargs->v, long long ); |
} else |
#endif |
if( specs->_flags & SPF_LONG ) { |
long_value = va_arg( pargs->v, long ); |
} else { |
long_value = va_arg( pargs->v, int ); |
if( specs->_flags & SPF_SHORT ) { /* JBS 92/02/12 */ |
long_value = (short) long_value; |
} else if( specs->_flags & SPF_CHAR ) { |
long_value = (signed char)long_value; |
} |
} |
{ |
int negative = FALSE; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if( (long long)long_long_value < 0 ) { |
negative = TRUE; |
} |
} else |
#endif |
if( (long)long_value < 0 ) { |
negative = TRUE; |
} |
if( negative ) { |
buffer[specs->_n0++] = '-'; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = -long_long_value; |
} else |
#endif |
long_value = - long_value; |
} else if( specs->_flags & SPF_FORCE_SIGN ) { |
buffer[specs->_n0++] = '+'; |
} else if( specs->_flags & SPF_BLANK ) { |
buffer[specs->_n0++] = ' '; |
} |
} |
} |
radix = 10; /* base 10 for 'd', 'i' and 'u' */ |
switch( specs->_character ) { |
case 'f': |
case 'F': |
if( specs->_flags & SPF_SHORT ) { /* "%hf" 13-jun-91 */ |
long_value = va_arg( pargs->v, long ); |
FixedPoint_Format( buffer, long_value, specs ); |
specs->_n1 = far_strlen( buffer, -1 ); |
break; |
} |
/* types f & F fall through */ |
case 'g': |
case 'G': |
case 'e': |
case 'E': |
float_format( buffer, pargs, specs ); |
SetZeroPad( specs ); |
arg++; // = &buffer[1]; |
break; |
case 's': |
#ifndef __NETWARE__ |
case WIDE_CHAR_STRING: |
#else |
case PASCAL_STRING: |
#endif |
// arg has been initialized to point to buffer |
// set buffer[0] to a null character assuming pointer will be NULL |
// If pointer is not null, then arg will be assigned the pointer |
buffer[0] = '\0'; // assume null pointer |
#if defined( __FAR_SUPPORT__ ) |
if( specs->_flags & SPF_FAR ) { |
CHAR_TYPE _WCFAR *temp = va_arg( pargs->v, CHAR_TYPE _WCFAR * ); |
if( temp ) { |
arg = temp; |
} |
} else if( specs->_flags & SPF_NEAR ) { |
CHAR_TYPE _WCNEAR *temp = va_arg( pargs->v, CHAR_TYPE _WCNEAR * ); |
if( temp ) { |
arg = (void *)temp; |
} |
} else { |
CHAR_TYPE *temp = va_arg( pargs->v, CHAR_TYPE * ); |
if( temp ) { |
arg = temp; |
} |
} |
#else |
{ |
CHAR_TYPE *temp = va_arg( pargs->v, CHAR_TYPE * ); |
if( temp ) { |
arg = temp; |
} |
} |
#endif |
#ifdef __NETWARE__ |
if( specs->_character == PASCAL_STRING ) { |
#ifdef __WIDECHAR__ |
if( specs->_flags & SPF_SHORT ) |
#else |
if( specs->_flags & SPF_LONG ) |
#endif |
{ |
length = *( (_FAR_OTHER_STRING)arg ); |
arg = (FAR_STRING)( (_FAR_OTHER_STRING)arg + 1 ); |
} else { |
length = *arg++; |
} |
} else |
#elif !defined( __NETWARE__ ) && !defined( __WIDECHAR__ ) |
if( specs->_character == WIDE_CHAR_STRING ) { |
if( specs->_flags & SPF_SHORT ) { |
length = far_strlen( arg, specs->_prec ); |
} else { |
length = far_other_strlen( arg, specs->_prec ); |
} |
} else |
#endif |
#ifdef __WIDECHAR__ |
if( specs->_flags & SPF_SHORT ) { |
#else |
if( specs->_flags & SPF_LONG ) { |
#endif |
length = far_other_strlen( arg, specs->_prec ); |
} else { |
length = far_strlen( arg, specs->_prec ); |
} |
specs->_n1 = length; |
if(( specs->_prec >= 0 ) && ( specs->_prec < length )) { |
specs->_n1 = specs->_prec; |
} |
break; |
case 'x': |
case 'X': |
if( specs->_flags & SPF_ALT ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if( long_long_value != 0 ) { |
buffer[specs->_n0++] = '0'; |
buffer[specs->_n0++] = specs->_character; |
} |
} else |
#endif |
if( long_value != 0 ) { |
buffer[specs->_n0++] = '0'; |
buffer[specs->_n0++] = specs->_character; |
} |
} |
radix = 16; /* base 16 */ |
goto processNumericTypes; |
case 'b': /* CDH 2003 Apr 23 *//* Add binary mode */ |
radix = 2; /* base 2 */ |
goto processNumericTypes; |
case 'o': |
radix = 8; /* base 8 */ |
/* 'o' conversion falls through */ |
case 'd': |
case 'i': |
case 'u': |
// 'x' and 'X' jumps here |
processNumericTypes: |
if( specs->_prec != -1 ) |
specs->_pad_char = ' '; /* 30-jul-95, 11-may-99 */ |
/* radix contains the base; 8 for 'o', 10 for 'd' and 'i' and 'u', |
16 for 'x' and 'X', and 2 for 'b' */ |
arg = &buffer[ specs->_n0 ]; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if(( specs->_prec == 0 ) && ( long_long_value == 0 )) { |
*arg = '\0'; |
length = 0; |
} else { |
__F_NAME(ulltoa,_ulltow)( long_long_value, &buffer[specs->_n0], radix ); |
if( specs->_character == 'X' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
length = far_strlen( arg, -1 ); |
} |
} else |
#endif |
if(( specs->_prec == 0 ) && ( long_value == 0 )) { |
*arg = '\0'; |
length = 0; |
} else { |
__F_NAME(ultoa,_ultow)( long_value, &buffer[specs->_n0], radix ); |
if( specs->_character == 'X' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
length = far_strlen( arg, -1 ); |
} |
specs->_n1 = length; |
if( specs->_n1 < specs->_prec ) { |
specs->_nz0 = specs->_prec - specs->_n1; |
} else if( specs->_flags & SPF_ALT && radix < 10 |
&& (!length || (arg[0] != '0')) ) { |
/* For 'b' and 'o' conversions, alternate format forces the number to |
* start with a zero (effectively increases precision by one), but |
* only if it doesn't start with a zero already. |
*/ |
++specs->_nz0; |
} |
if( specs->_prec == -1 ) { |
SetZeroPad( specs ); |
} |
break; |
case 'p': |
case 'P': |
#if defined( __FAR_SUPPORT__ ) |
#if defined( __BIG_DATA__ ) |
if( !( specs->_flags & (SPF_NEAR|SPF_FAR) ) ) { |
specs->_flags |= SPF_FAR; |
} |
if( specs->_fld_width == 0 ) { |
if( specs->_flags & SPF_NEAR ) { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} else { |
specs->_fld_width = sizeof( CHAR_TYPE _WCFAR * ) * 2 + 1; |
} |
} |
#else |
if( specs->_fld_width == 0 ) { |
if( specs->_flags & SPF_FAR ) { |
specs->_fld_width = sizeof( CHAR_TYPE _WCFAR * ) * 2 + 1; |
} else { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} |
} |
#endif |
#else |
if( specs->_fld_width == 0 ) { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} |
#endif |
specs->_flags &= ~( SPF_BLANK | SPF_FORCE_SIGN ); |
int_value = va_arg( pargs->v, unsigned ); /* offset */ |
#if defined( __FAR_SUPPORT__ ) |
if( specs->_flags & SPF_FAR ) { |
seg_value = va_arg( pargs->v, unsigned ) & 0xFFFF; /* segment */ |
/* use "unsigned short" for 386 instead of "unsigned" 21-jul-89 */ |
fmt4hex( seg_value, buffer, sizeof( unsigned short ) * 2 ); |
buffer[sizeof(unsigned short)*2] = ':'; |
fmt4hex( int_value, buffer + sizeof( unsigned short ) * 2 + 1, |
sizeof( unsigned ) * 2 ); |
} else { |
fmt4hex( int_value, buffer, sizeof( unsigned ) * 2 ); |
} |
#else |
fmt4hex( int_value, buffer, sizeof( unsigned ) * 2 ); |
#endif |
if( specs->_character == 'P' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
specs->_n0 = far_strlen( arg, -1 ); |
break; |
case 'c': |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs->_flags & SPF_SHORT ) { |
char * mbPtr; |
char mbBuf[MB_CUR_MAX]; |
wchar_t wc; |
mbPtr = va_arg( pargs->v, char* ); |
mbBuf[0] = mbPtr[0]; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = mbPtr[1]; |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
buffer[0] = wc; |
} |
} else { |
buffer[0] = va_arg( pargs->v, int ); |
} |
specs->_n0 = 1; |
#elif !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
specs->_n0 = 1; |
if( specs->_flags & SPF_LONG ) { |
char mbBuf[MB_CUR_MAX]; |
wchar_t wc; |
wc = va_arg( pargs->v, int ); |
if( wctomb( mbBuf, wc ) != -1 ) { |
buffer[0] = mbBuf[0]; |
if( _ismbblead( mbBuf[0] ) ) { |
buffer[1] = mbBuf[1]; |
specs->_n0++; |
} |
} |
} else { |
buffer[0] = va_arg( pargs->v, int ); |
} |
#else |
specs->_n0 = 1; |
buffer[0] = va_arg( pargs->v, int ); |
#endif |
break; |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
case 'C': |
bytes = wctomb( buffer, va_arg( pargs->v, int ) ); |
// if( bytes != -1 && bytes <= specs->_prec ) { |
if( bytes != -1 ) { /* Normative Addendum 4.5.3.3.1: no precision */ |
specs->_n0 = bytes; |
} else { |
specs->_n0 = 0; |
} |
break; |
#endif |
default: |
specs->_fld_width = 0; |
buffer[ 0 ] = specs->_character; |
specs->_n0 = 1; |
break; |
} |
return( arg ); |
} |
/programs/develop/open watcom/trunk/clib/src/qwrit.c |
---|
0,0 → 1,138 |
/**************************************************************************** |
* |
* 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 <errno.h> |
//#if defined(__NT__) |
//#elif defined(__OS2__) |
//#else |
// #include "tinyio.h" |
//#endif |
#include "iomode.h" |
#include "fileacc.h" |
#include "rtcheck.h" |
#include "rtdata.h" |
#include "seterrno.h" |
//#include "defwin.h" |
#include "qwrite.h" |
/* |
Use caution when setting the file pointer in a multithreaded |
application. You must synchronize access to shared resources. For |
example, an application whose threads share a file handle, update the |
file pointer, and read from the file must protect this sequence by |
using a critical section object or a mutex object. |
*/ |
int __qwrite( int handle, const void *buffer, unsigned len ) |
{ |
int atomic; |
#if defined(__NT__) |
DWORD len_written; |
HANDLE h; |
int error; |
#elif defined(__WARP__) |
#elif defined(__OS2_286__) |
#else |
#endif |
#if !defined(__NT__) |
tiny_ret_t rc; |
#endif |
__handle_check( handle, -1 ); |
#if defined(__NT__) |
h = __getOSHandle( handle ); |
#endif |
atomic = 0; |
if( __GetIOMode( handle ) & _APPEND ) |
{ |
_AccessFileH( handle ); |
atomic = 1; |
#if defined(__NT__) |
// if( SetFilePointer( h, 0, NULL, FILE_END ) == -1 ) |
// { |
// error = GetLastError(); |
// _ReleaseFileH( handle ); |
// return( __set_errno_dos( error ) ); |
// } |
#elif defined(__OS2__) |
#else |
rc = TinySeek( handle, 0L, SEEK_END ); |
#endif |
#if !defined(__NT__) |
if( TINY_ERROR( rc ) ) { |
_ReleaseFileH( handle ); |
return( __set_errno_dos( TINY_INFO( rc ) ) ); |
} |
#endif |
} |
#if defined(__NT__) |
// if( !WriteFile( h, buffer, len, &len_written, NULL ) ) |
// { |
// error = GetLastError(); |
// if( atomic == 1 ) { |
// _ReleaseFileH( handle ); |
// } |
// return( __set_errno_dos( error ) ); |
// } |
#elif defined(__OS2__) |
#elif defined(__WINDOWS_386__) |
#else |
rc = TinyWrite( handle, buffer, len ); |
len_written = TINY_LINFO( rc ); |
#endif |
#if !defined(__NT__) |
if( TINY_ERROR( rc ) ) { |
if( atomic == 1 ) { |
_ReleaseFileH( handle ); |
} |
return( __set_errno_dos( TINY_INFO( rc ) ) ); |
} |
#endif |
if( len_written != len ) { |
__set_errno( ENOSPC ); |
} |
if( atomic == 1 ) |
{ |
_ReleaseFileH( handle ); |
} |
return( len_written ); |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/scnf.c |
---|
0,0 → 1,1116 |
/**************************************************************************** |
* |
* 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: Platform independent worker routines for scanf(). |
* |
****************************************************************************/ |
#define __LONG_LONG_SUPPORT__ |
#if !defined( __NETWARE__ ) && !defined( __UNIX__ ) |
#define USE_MBCS_TRANSLATION |
#endif |
#include "variety.h" |
#ifdef SAFE_SCANF |
#include "saferlib.h" |
#endif |
#include "widechar.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#ifdef __WIDECHAR__ |
#include <wctype.h> |
#else |
#include <ctype.h> |
#endif |
#include <stdarg.h> |
#include "scanf.h" |
#include "prtscncf.h" |
#include "fixpoint.h" |
#include "ftos.h" |
#include "farsupp.h" |
#include "myvalist.h" |
#if defined( __WIDECHAR__ ) || defined( USE_MBCS_TRANSLATION ) |
#include <mbstring.h> |
#endif |
#define TRUE 1 |
#define FALSE 0 |
#define STOP_CHR 0xFFFFFFFF |
#define EFG_SCANF (*__EFG_scanf) |
/* internal file/string get, unget routines */ |
#ifdef __WINDOWS_386__ |
#ifdef __SW_3S |
#pragma aux cget modify [eax edx ecx fs gs] |
#pragma aux uncget modify [eax edx ecx fs gs] |
#else |
#pragma aux cget modify [fs gs] |
#pragma aux uncget modify [fs gs] |
#endif |
#endif |
#if defined(__HUGE__) |
#define SCNF_FAR _WCFAR |
#else |
#define SCNF_FAR |
#endif |
/* Macros to reduce the already large number of ifdefs in the code */ |
#ifdef SAFE_SCANF |
#define GET_MAXELEM(x) x = va_arg( arg->v, size_t ) |
#define DEFINE_VARS(x,y) size_t x, y = 0 |
#define CHECK_ELEMS(x,y,z) if( x < ++y ) return( z ) |
#else |
#define GET_MAXELEM(x) |
#define DEFINE_VARS(x,y) |
#define CHECK_ELEMS(x,y,z) |
#endif |
static int cget( PTR_SCNF_SPECS specs ) |
{ |
return( (*((specs)->cget_rtn))( specs ) ); |
} |
static void uncget( int c, PTR_SCNF_SPECS specs ) |
{ |
((*((specs)->uncget_rtn))( c, specs )); |
} |
/* |
* get_opt -- get option string for current conversion directive |
* and fills in the SCNF_SPECS structure. |
* returns advanced format string pointer. |
*/ |
static const CHAR_TYPE *get_opt( const CHAR_TYPE *opt_str, PTR_SCNF_SPECS specs ) |
{ |
int c, width; |
specs->assign = TRUE; |
specs->far_ptr = 0; |
specs->near_ptr = 0; |
specs->char_var = 0; |
specs->short_var = 0; |
specs->long_var = 0; |
specs->long_long_var = 0; |
specs->long_double_var = 0; |
specs->p_format = 0; /* 21-nov-89 */ |
specs->width = -1; |
if( *opt_str == '*' ) { |
specs->assign = FALSE; |
++opt_str; |
} |
c = *opt_str; |
if( __F_NAME(isdigit,iswdigit)( c ) ) { |
width = 0; |
do { |
width *= 10; |
width += ( c - '0' ); |
c = *++opt_str; |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
specs->width = width; |
} |
switch( *opt_str ) { |
case 'N': |
specs->near_ptr = 1; |
++opt_str; |
break; |
#if defined( __FAR_SUPPORT__ ) |
case 'F': /* conflicts with ISO-defined 'F' conversion */ |
/* fall through */ |
#endif |
case 'W': |
specs->far_ptr = 1; |
++opt_str; |
break; |
} |
switch( *opt_str ) { |
case 'h': |
if( opt_str[1] == 'h' ) { |
specs->char_var = 1; |
opt_str += 2; |
break; |
} |
specs->short_var = 1; |
++opt_str; |
break; |
case 'l': |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( opt_str[1] == 'l' ) { |
specs->long_long_var = 1; |
opt_str += 2; |
break; |
} |
#endif |
/* fall through */ |
ZSPEC_CASE_LONG |
TSPEC_CASE_LONG |
case 'w': |
specs->long_var = 1; |
++opt_str; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
JSPEC_CASE_LLONG |
/* fall through */ |
#endif |
case 'L': |
specs->long_double_var = 1; |
specs->long_long_var = 1; |
++opt_str; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
case 'I': |
if( opt_str[1] == '6' && opt_str[2] == '4' ) { |
specs->long_long_var = 1; |
opt_str += 3; |
} |
break; |
#endif |
#if defined( TSPEC_IS_INT ) || defined( ZSPEC_IS_INT ) |
TSPEC_CASE_INT /* If either 't' or 'z' spec corresponds to 'int', */ |
ZSPEC_CASE_INT /* we need to parse and ignore the spec. */ |
++opt_str; |
break; |
#endif |
} |
return( opt_str ); |
} |
/* |
* scan_white -- scan white space from input stream |
*/ |
static int scan_white( PTR_SCNF_SPECS specs ) |
{ |
int c, len; |
len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++len; |
} |
if( !specs->eoinp ) |
uncget( c, specs ); |
return( len ); |
} |
/* |
* scan_char -- handles %c and %C |
*/ |
static int scan_char( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
int len; |
int width; |
FAR_STRING str; |
int c; |
DEFINE_VARS( maxelem, nelem ); |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCNEAR * ); |
} else { |
str = va_arg( arg->v, CHAR_TYPE * ); |
} |
#else |
str = va_arg( arg->v, CHAR_TYPE * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
if( (width = specs->width) == -1 ) |
width = 1; |
while( width > 0 ) { |
c = cget( specs ); |
if( specs->eoinp ) |
break; |
++len; |
--width; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs->short_var ) { |
char mbBuf[MB_CUR_MAX]; |
if( wctomb( mbBuf, c ) != -1 ) { |
*(FAR_ASCII_STRING)str = mbBuf[0]; |
str = (FAR_STRING) ( (FAR_ASCII_STRING)str + 1 ); |
if( _ismbblead( mbBuf[0] ) ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*(FAR_ASCII_STRING)str = mbBuf[1]; |
str = (FAR_STRING) ( (FAR_ASCII_STRING)str + 1 ); |
} |
} else { |
return( 0 ); |
} |
} else { |
*str++ = c; |
} |
#elif defined( USE_MBCS_TRANSLATION ) |
if( specs->long_var ) { |
wchar_t wc; |
char mbBuf[MB_CUR_MAX]; |
mbBuf[0] = c; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = cget( specs ); |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
*(FAR_UNI_STRING)str = wc; |
str = (FAR_STRING) ( (FAR_UNI_STRING)str + 1 ); |
} else { |
return( 0 ); |
} |
} else { |
*str++ = c; |
} |
#else |
*str++ = c; |
#endif |
} |
} |
return( len ); |
} |
/* |
* cgetw -- cget which keeps track of field width. |
* returns STOP_CHR on end of field or end of file. |
*/ |
static long cgetw( PTR_SCNF_SPECS specs ) |
{ |
int c; |
if( specs->width-- == 0 ) |
return( STOP_CHR ); |
c = cget( specs ); |
return( !( specs->eoinp ) ? c : STOP_CHR ); |
} |
/* |
* scan_string -- handles %s and %S |
*/ |
static int scan_string( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
int c; |
int len; |
FAR_ASCII_STRING str; |
char chsize; |
DEFINE_VARS( maxelem, nelem ); |
if( specs->long_var ) { /* %ls or %ws */ |
chsize = sizeof( wchar_t ); |
} else if( specs->short_var ) { /* %hs */ |
chsize = 1; |
} else { /* %s */ |
chsize = CHARSIZE; |
} |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, char _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, char _WCNEAR * ); |
} else { |
str = va_arg( arg->v, char * ); |
} |
#else |
str = va_arg( arg->v, char * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++len; |
} |
if( specs->eoinp ) { |
len = 0; /* since this is eof, no input done */ |
goto done; |
} |
if( specs->width-- == 0 ) |
goto ugdone; |
do { |
++len; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
if( chsize == 1 ) { |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
char mbBuf[MB_CUR_MAX]; |
if( wctomb( mbBuf, c ) != -1 ) { |
*(FAR_ASCII_STRING)str = mbBuf[0]; |
if( _ismbblead( mbBuf[0] ) ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
str++; |
*(FAR_ASCII_STRING)str = mbBuf[1]; |
} |
} else { |
return( 0 ); |
} |
#else |
*str = c; |
#endif |
} else { |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
wchar_t wc; |
char mbBuf[MB_CUR_MAX]; |
mbBuf[0] = c; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = cget( specs ); |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
*(FAR_UNI_STRING)str = wc; |
} else { |
return( 0 ); |
} |
#else |
*(FAR_UNI_STRING)str = c; |
#endif |
} |
str += chsize; |
} |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( !__F_NAME(isspace,iswspace)( c ) ); |
ugdone: |
uncget( c, specs ); |
done: |
if( specs->assign && len > 0 ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
if( chsize == 1 ) { |
*str = '\0'; |
} else { |
*(FAR_UNI_STRING)str = 0; |
} |
} |
return( len ); |
} |
/* |
* report_scan -- handles %n |
*/ |
static void report_scan( PTR_SCNF_SPECS specs, my_va_list *arg, int match ) |
{ |
FAR_INT iptr; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
iptr = va_arg( arg->v, int _WCFAR * ); |
} else if( specs->near_ptr ) { |
iptr = va_arg( arg->v, int _WCNEAR * ); |
} else { |
iptr = va_arg( arg->v, int * ); |
} |
#else |
iptr = va_arg( arg->v, int * ); |
#endif |
if( specs->char_var ) { |
*((FAR_CHAR)iptr) = match; |
} else if( specs->short_var ) { |
*((FAR_SHORT)iptr) = match; |
} else if( specs->long_var ) { |
*((FAR_LONG)iptr) = match; |
#if defined( __LONG_LONG_SUPPORT__ ) |
} else if( specs->long_long_var ) { |
*((FAR_INT64)iptr) = match; |
#endif |
} else { |
*iptr = match; |
} |
} |
} |
#if !defined( __WIDECHAR__ ) |
#define SCANSET_LENGTH (256 / 8) |
static const char lst_mask[8] = { |
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 |
}; |
/* |
* makelist -- create scanset for %[ directive. |
* scanset is stored as 256 bit flags in a 32 byte array. |
*/ |
static const char *makelist( const char *format, char *scanset ) |
{ |
int lst_chr; |
memset( scanset, 0, SCANSET_LENGTH ); |
if( (lst_chr = *format++) == '\0' ) |
return( format ); |
do { |
scanset[lst_chr >> 3] |= lst_mask[lst_chr & 0x07]; |
if( (lst_chr = *format) == '\0' ) |
break; |
++format; |
} while( lst_chr != ']' ); |
return( format ); |
} |
#endif |
/* |
* scan_arb -- handles %[ |
*/ |
static int scan_arb( PTR_SCNF_SPECS specs, my_va_list *arg, const CHAR_TYPE **format ) |
{ |
unsigned width; |
FAR_STRING str; |
int len, c, not_flag; |
#if defined( __WIDECHAR__ ) |
const CHAR_TYPE *list; |
CHAR_TYPE ch; |
char in_list; |
#else |
char scanset[SCANSET_LENGTH]; |
#endif |
DEFINE_VARS( maxelem, nelem ); |
if( not_flag = (**format == '^') ) { |
++(*format); |
} |
#if !defined( __WIDECHAR__ ) |
*format = makelist( *format, scanset ); |
#endif |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCNEAR * ); |
} else { |
str = va_arg( arg->v, CHAR_TYPE * ); |
} |
#else |
str = va_arg( arg->v, CHAR_TYPE * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
width = specs->width; |
while( width > 0 ) { |
c = cget( specs ); |
if( specs->eoinp ) |
break; |
#if defined( __WIDECHAR__ ) |
list = *format; |
ch = *list; |
in_list = TRUE; |
while( c != ch ) { |
list++; |
ch = *list; |
if( ch == ']' ) { |
in_list = FALSE; |
break; |
} |
} |
if( in_list == not_flag ) { |
uncget( c, specs ); |
break; |
} |
#else |
if( ((scanset[c >> 3] & lst_mask[c & 0x07]) == 0) != not_flag ) { |
uncget( c, specs ); |
break; |
} |
#endif |
++len; |
--width; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*str++ = c; |
} |
} |
if( specs->assign && len > 0 ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*str = '\0'; |
} |
#if defined( __WIDECHAR__ ) |
while( *(*format)++ != ']' ) /* skip past format specifier */ |
; |
#endif |
return( len ); |
} |
/* |
* scan_float -- handles floating point numerical conversion |
* *** should implement buffer overflow protection *** |
*/ |
static int scan_float( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
double value; |
char *num_str, buf[80]; |
int len; |
int pref_len; |
long c; |
int digit_found; |
FAR_FLOAT fptr; |
char *p; |
T32 at; |
T32 ft; |
num_str = buf; |
pref_len = len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++pref_len; |
} |
if( specs->eoinp ) |
goto done; |
if( specs->width-- == 0 ) |
goto ugdone; |
if( c == '+' || c == '-' ) { |
*num_str++ = c; |
++pref_len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( !__F_NAME(isdigit,iswdigit)( c ) && c != '.' ) |
goto ugdone; |
at.uWhole = 0; |
digit_found = FALSE; |
if( __F_NAME(isdigit,iswdigit)( c ) ) { |
digit_found = TRUE; |
do { |
*num_str++ = c; |
if( specs->short_var ) |
at.wd.hi = at.wd.hi * 10 + c - '0'; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
} |
if( c == '.' ) { |
*num_str++ = c; |
++len; /* account for the '.' */ |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( !digit_found && !__F_NAME(isdigit,iswdigit)(c) ) |
goto ugdone; |
while( __F_NAME(isdigit,iswdigit)( c ) ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
break; |
} |
} |
if( specs->short_var ) { /* %hf fixed-point format 05-feb-92 */ |
ft.uWhole = 0; |
p = num_str; |
for( ;; ) { |
--p; |
if( *p == '.' ) |
break; |
ft.bite.b3 = *p - '0'; |
ft.uWhole = ft.uWhole / 10; |
} |
at.wd.lo = ft.wd.lo; |
} |
if( c == STOP_CHR ) { |
goto done; |
} |
} |
if( specs->short_var == 0 && (c == 'e' || c == 'E') ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == '+' || c == '-' ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( !__F_NAME(isdigit,iswdigit)( c ) ) { |
len = 0; /* fast way to flag error */ |
} else { |
do { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
} |
} |
ugdone: |
uncget( (int)c, specs ); |
done: |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
*num_str = NULLCHAR; |
if( specs->short_var ) { |
if( buf[0] == '-' ) { |
at.sWhole = - at.sWhole; |
} |
} else { |
EFG_SCANF( buf, (void *)&value ); /* 27-mar-90 */ |
} |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
fptr = va_arg( arg->v, float _WCFAR * ); |
} else if( specs->near_ptr ) { |
fptr = va_arg( arg->v, float _WCNEAR * ); |
} else { |
fptr = va_arg( arg->v, float * ); |
} |
#else |
fptr = va_arg( arg->v, float * ); |
#endif |
if( specs->short_var ) { /* 05-feb-92 */ |
*((FAR_LONG) fptr) = at.uWhole; |
} else if( specs->long_var || specs->long_double_var ) { |
*((FAR_DOUBLE) fptr) = value; |
} else { |
*fptr = value; |
} |
} |
} |
return( len ); |
} |
static int radix_value( int c ) |
{ |
if( c >= '0' && c <= '9' ) |
return( c - '0' ); |
c = __F_NAME(tolower,towlower)( c ); |
if( c >= 'a' && c <= 'f' ) |
return( c - 'a' + 10 ); |
return( 16 ); |
} |
/* |
* scan_int -- handles integer numeric conversion |
*/ |
static int scan_int( PTR_SCNF_SPECS specs, my_va_list *arg, int base, int sign_flag ) |
{ |
long value; |
int len; |
int pref_len; |
int c; |
int sign; |
int digit; |
FAR_INT iptr; |
#if defined( __LONG_LONG_SUPPORT__ ) |
unsigned long long long_value; |
FAR_INT64 llptr; |
long_value = 0; |
#endif |
value = 0; |
pref_len = len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++pref_len; |
} |
if( specs->eoinp ) |
goto done; |
if( specs->width-- == 0 ) |
goto ugdone; |
sign = '+'; |
if( sign_flag && (c == '+' || c == '-') ) { |
sign = c; |
++pref_len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( base == 0 ) { |
if( c == '0' ) { |
len = 1; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == 'x' || c == 'X' ) { |
len = 0; |
++pref_len; /* for the '0' */ |
++pref_len; /* for the 'x' */ |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
base = 16; |
} else { |
base = 8; |
} |
} else { |
base = 10; |
} |
} else if( base == 16 ) { |
if( c == '0' ) { |
len = 1; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == 'x' || c == 'X' ) { |
len = 0; |
++pref_len; /* for the '0' */ |
++pref_len; /* for the 'x' */ |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
} |
} |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->long_long_var ) { |
for( ;; ) { |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
long_value = long_value * base + digit; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( c == ':' && specs->p_format ) { |
for( ;; ) { |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
long_value = long_value * base + digit; |
} |
} |
} else |
#endif |
{ |
for( ;; ) { |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
value = value * base + digit; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( c == ':' && specs->p_format ) { |
for( ;; ) { |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
value = value * base + digit; |
} |
} |
} |
ugdone: |
uncget( c, specs ); |
done: |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->long_long_var ) { |
if( sign == '-' ) { |
long_value =- long_value; |
} |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
llptr = va_arg( arg->v, unsigned long long _WCFAR * ); |
} else if( specs->near_ptr ) { |
llptr = va_arg( arg->v, unsigned long long _WCNEAR * ); |
} else { |
llptr = va_arg( arg->v, unsigned long long * ); |
} |
#else |
llptr = va_arg( arg->v, unsigned long long * ); |
#endif |
*llptr = long_value; |
} |
} |
} else |
#endif |
{ |
if( sign == '-' ) { |
value = -value; |
} |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
iptr = va_arg( arg->v, int _WCFAR * ); |
} else if( specs->near_ptr ) { |
iptr = va_arg( arg->v, int _WCNEAR * ); |
} else { |
iptr = va_arg( arg->v, int * ); |
} |
#else |
iptr = va_arg( arg->v, int * ); |
#endif |
if( specs->char_var ) { |
*((FAR_CHAR)iptr) = value; |
} else if( specs->short_var ) { |
*((FAR_SHORT)iptr) = value; |
} else if( specs->long_var ) { |
*((FAR_LONG)iptr) = value; |
} else { |
*iptr = value; |
} |
} |
} |
} |
return( len ); |
} |
#ifdef SAFE_SCANF |
/* |
* null_arg -- check for a null pointer passed in arguments |
*/ |
static int null_arg( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
FAR_STRING str = NULL; |
va_list args_copy; |
va_copy( args_copy, arg->v ); |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( args_copy, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
CHAR_TYPE _WCNEAR *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE _WCNEAR * ); |
/* The following should work: |
* |
* str = (ptr == NULL) ? (void _WCFAR *)NULL : ptr; |
* |
* but doesn't due to a bug in C compiler introduced in |
* 11.0 and fixe in OW 1.4. Ternary operator may be used |
* when building with OW 1.5. See also similar code in prtf.c. |
*/ |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} else { |
CHAR_TYPE *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} |
#else |
str = va_arg( args_copy, CHAR_TYPE * ); |
#endif |
va_end( args_copy ); |
return( str == NULL ? 1 : 0 ); |
} |
#endif |
#ifdef SAFE_SCANF |
int __F_NAME(__scnf_s,__wscnf_s)( PTR_SCNF_SPECS specs, const CHAR_TYPE *format, const char **msg, va_list args ) |
#else |
int __F_NAME(__scnf,__wscnf)( PTR_SCNF_SPECS specs, const CHAR_TYPE *format, va_list args ) |
#endif |
{ |
int char_match; |
int items_converted; |
int items_assigned; |
int match_len; |
int c; |
int fmt_chr; |
my_va_list margs; |
margs = MY_VA_LIST( args ); |
char_match = items_assigned = items_converted = 0; |
specs->eoinp = 0; |
while( (fmt_chr = *format++) != NULLCHAR ) { |
if( __F_NAME(isspace,iswspace)( fmt_chr ) ) { |
char_match += scan_white( specs ); |
} else if( fmt_chr != '%' ) { |
if( (c = cget( specs )) != fmt_chr ) { |
if( !specs->eoinp ) |
uncget( c, specs ); |
break; |
} |
++char_match; /* 27-oct-88 */ |
} else { /* fmt_chr == '%' */ |
format = get_opt( format, specs ); |
if( (fmt_chr = *format) != NULLCHAR ) |
++format; |
#ifdef SAFE_SCANF |
if( fmt_chr != '%' ) { |
/* The '%' specifier is the only one not expecting pointer arg */ |
if( specs->assign && null_arg( specs, &margs ) ) { |
*msg = "%ptr -> NULL"; |
return( __F_NAME(EOF,WEOF) ); |
} |
} |
#endif |
switch( fmt_chr ) { |
case 'd': |
match_len = scan_int( specs, &margs, 10, TRUE ); |
goto check_match; |
case 'i': |
match_len = scan_int( specs, &margs, 0, TRUE ); |
goto check_match; |
case 'o': |
match_len = scan_int( specs, &margs, 8, TRUE ); |
goto check_match; |
case 'u': |
match_len = scan_int( specs, &margs, 10, TRUE ); |
goto check_match; |
case 'p': |
#if defined( __BIG_DATA__ ) |
specs->long_var = 1; /* indicate far pointer */ |
specs->p_format = 1; /* ... */ |
#endif |
// fall through |
case 'x': |
case 'X': |
match_len = scan_int( specs, &margs, 16, TRUE ); |
goto check_match; |
case 'e': |
case 'E': |
case 'f': |
case 'F': |
case 'g': |
case 'G': |
match_len = scan_float( specs, &margs ); |
goto check_match; |
#if !defined(__WIDECHAR__) && !defined(__NETWARE__) |
case 'S': |
specs->long_var = 1; |
/* fall through to %s handler */ |
#endif |
case 's': |
match_len = scan_string( specs, &margs ); |
goto check_match; |
case '[': |
match_len = scan_arb( specs, &margs, &format ); |
goto check_match; |
#if !defined(__WIDECHAR__) && !defined(__NETWARE__) |
case 'C': |
specs->long_var = 1; |
/* fall through to %c handler */ |
#endif |
case 'c': |
match_len = scan_char( specs, &margs ); |
check_match: |
if( match_len > 0 ) { |
char_match += match_len; |
++items_converted; |
if( specs->assign ) { |
++items_assigned; |
} |
} else { |
#ifdef SAFE_SCANF |
if( match_len < 0 ) { |
/* Matching failure caused by insufficient space in output |
* is not input failure, hence we won't return EOF regardless |
* of specs->eoinp state. |
*/ |
++items_converted; |
} |
#endif |
goto fail; |
} |
break; |
case 'n': |
report_scan( specs, &margs, char_match ); |
break; |
case '%': |
if( (c = cget( specs )) != '%' ) { |
if( !specs->eoinp ) |
uncget( c, specs ); |
goto fail; |
} else { |
char_match += 1; |
} |
break; |
} |
} |
if( specs->eoinp ) { |
while( *format == '%' ) { |
++format; |
format = get_opt( format, specs ); |
if( *format == 'n' ) { |
++format; |
#ifdef SAFE_SCANF |
if( specs->assign && null_arg( specs, &margs ) ) { |
*msg = "%ptr -> NULL"; |
return( __F_NAME(EOF,WEOF) ); |
} |
#endif |
report_scan( specs, &margs, char_match ); |
} else { |
break; |
} |
} |
break; |
} |
} |
fail: |
if( items_converted == 0 && specs->eoinp ) |
return( __F_NAME(EOF,WEOF) ); |
return( items_assigned ); |
} |
/programs/develop/open watcom/trunk/clib/src/setefg.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: Routine to bring in real floating-point formatting code. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "ftos.h" |
#include "farsupp.h" |
/* This routine will be called by cstart if "_fltused" is referenced. */ |
void __setEFGfmt( void ) |
{ |
#ifdef __SW_BR |
__EFG_printf = __get_EFG_Format(); |
__EFG_scanf = __get__cnvs2d(); /* 27-mar-90 */ |
#else |
__EFG_printf = _EFG_Format; |
__EFG_scanf = __cnvs2d; /* 27-mar-90 */ |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/seterrno.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 __set_errno(). |
* |
****************************************************************************/ |
#ifdef __WATCOMC__ |
#include "variety.h" |
#include <stdlib.h> |
#include <errno.h> |
#include "rtdata.h" |
#include "seterrno.h" |
_WCRTLINK void __set_errno( unsigned int err ) |
{ |
_RWD_errno = err; |
} |
_WCRTLINK void __set_EDOM() |
{ |
__set_errno( EDOM ); |
} |
_WCRTLINK void __set_ERANGE() |
{ |
__set_errno( ERANGE ); |
} |
_WCRTLINK int __set_EINVAL() |
{ |
__set_errno( EINVAL ); |
return( -1 ); |
} |
//#if !defined(__UNIX__) && !defined(__NETWARE__) |
//_WCRTLINK void __set_doserrno( unsigned int err ) |
//{ |
// _RWD_doserrno = err; |
//} |
//#endif |
#else |
#include <errno.h> |
void __set_errno( unsigned int err ) |
{ |
errno = err; |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/stiomode.c |
---|
0,0 → 1,175 |
/**************************************************************************** |
* |
* 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 <unistd.h> |
#include <string.h> |
#include <errno.h> |
#include "rtdata.h" |
#include "liballoc.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "iomode.h" |
#include "handleio.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_malloc dlmalloc |
#define lib_free dlfree |
#define lib_realloc dlrealloc |
#endif |
#if defined(__NETWARE__) |
#error NO IO MODE MANAGER UNDER NETWARE |
#endif |
extern unsigned _HUGEDATA __init_mode[_NFILES]; |
extern unsigned __NFiles; /* maximum # of files we can open */ |
static unsigned _init_NFiles; // original __NFiles value; |
void __grow_iomode( int num ) |
{ |
unsigned *new; |
_AccessIOB(); |
if( __io_mode == __init_mode ) |
{ |
_init_NFiles = __NFiles; |
new = (unsigned *) lib_malloc( num * sizeof( unsigned ) ); |
if( new != NULL ) { |
memcpy( new, __init_mode, __NFiles * sizeof(unsigned) ); |
} |
} |
else |
{ |
#if defined(__NETWARE__) |
#else |
new = (unsigned *) lib_realloc( __io_mode, num * sizeof( unsigned ) ); |
#endif |
} |
if( new == NULL ) |
{ |
__set_errno( ENOMEM ); |
} |
else |
{ |
memset( &new[__NFiles], 0, (num-__NFiles)*sizeof(unsigned) ); |
__io_mode = new; |
__NFiles = num; |
} |
_ReleaseIOB(); |
} |
void __shrink_iomode( void ) |
{ |
_AccessIOB(); |
// free any malloc'd iomode array |
if( __io_mode != __init_mode ) |
{ |
lib_free( __io_mode ); |
__io_mode = __init_mode; |
__NFiles = _init_NFiles; |
} |
_ReleaseIOB(); |
} |
AYI(__shrink_iomode,INIT_PRIORITY_IOSTREAM); |
#if defined(__WARP__) |
extern unsigned __NHandles; |
static void __preinit_iomode_os2(void) |
{ |
LONG req_count; |
ULONG curr_max_fh; |
APIRET rc; |
// Ensure that the clib and OS file handle limits match |
req_count = 0; |
rc = DosSetRelMaxFH( &req_count, &curr_max_fh ); |
if( rc == 0 ) { |
__grow_iomode( curr_max_fh ); |
__NHandles = curr_max_fh; // same as __set_handles |
} |
} |
AXI( __preinit_iomode_os2, INIT_PRIORITY_RUNTIME ); |
#endif |
#define _INITIALIZED _DYNAMIC |
signed __SetIOMode( int handle, unsigned value ) |
{ |
int i; |
if( handle >= __NFiles ) |
{ |
i = __NFiles; // 20 -> (20+10+1) -> 31 |
// 31 -> (31+15+1) -> 47 |
// 47 -> (47+23+1) -> 71 |
__grow_iomode( i + (i > 1) + 1 ); |
} |
if( handle >= __NFiles ) |
{ |
// return an error indication (errno should be set to ENOMEM) |
return( -1 ); |
} |
else |
{ |
if( value != 0 ) |
{ |
__ChkTTYIOMode( handle ); |
__io_mode[handle] = value | _INITIALIZED; |
} |
else |
{ |
__io_mode[handle] = value; /* we're closing it; smite _INITIALIZED */ |
} |
return( handle ); |
} |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/strcmp.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 "riscstr.h" |
#include "xstring.h" |
#undef strcmp |
/* return <0 if s<t, 0 if s==t, >0 if s>t */ |
#if defined(__RISCSTR__) && defined(__WIDECHAR__) |
_WCRTLINK int __simple_wcscmp( const CHAR_TYPE *s, const CHAR_TYPE *t ) |
#else |
_WCRTLINK int __F_NAME(strcmp,wcscmp)( const CHAR_TYPE *s, const CHAR_TYPE *t ) |
#endif |
{ |
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86) |
return( _inline_strcmp( s, t ) ); |
#else |
for( ; *s == *t; s++, t++ ) |
if( *s == NULLCHAR ) |
return( 0 ); |
return( *s - *t ); |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/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/src/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/src/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/src/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/src/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/src/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/src/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/src/tolower.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: Implementation of tolower(). |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <ctype.h> |
#ifdef __WIDECHAR__ |
#include <wchar.h> |
#endif |
_WCRTLINK INTCHAR_TYPE __F_NAME(tolower,towlower)( INTCHAR_TYPE c ) |
{ |
if( c >= 'A' && c <= 'Z' ) { |
c = c - 'A' + 'a'; |
} |
return( c ); |
} |
/programs/develop/open watcom/trunk/clib/src/toupper.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 toupper(). |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <ctype.h> |
#ifdef __WIDECHAR__ |
#include <wchar.h> |
#endif |
_WCRTLINK INTCHAR_TYPE __F_NAME(toupper,towupper)( INTCHAR_TYPE c ) |
{ |
if( c >= 'a' && c <= 'z' ) { |
c = c - 'a' + 'A'; |
} |
return( c ); |
} |
/programs/develop/open watcom/trunk/clib/src/ulltoa.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* 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 should remain an indirected file |
// it is done this way to support the reuse of the source file |
#define __WIDECHAR__ |
#undef __INLINE_FUNCTIONS__ |
#include "lltoa.c" |
/programs/develop/open watcom/trunk/clib/src/ultoa.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* 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 should remain an indirected file |
// it is done this way to support the reuse of the source file |
#define __WIDECHAR__ |
#undef __INLINE_FUNCTIONS__ |
#include "ltoa.c" |
/programs/develop/open watcom/trunk/clib/src/vsprintf.c |
---|
0,0 → 1,127 |
/**************************************************************************** |
* |
* 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" |
/* |
* mem_putc -- append a character to a string in memory |
*/ |
#ifdef __WIDECHAR__ |
struct vswprtf_buf { |
CHAR_TYPE *bufptr; |
int chars_output; |
int max_chars; |
}; |
static slib_callback_t mem_putc; // setup calling convention |
static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char ) |
{ |
struct vswprtf_buf *info; |
info = (struct vswprtf_buf*) specs->_dest; |
if( info->chars_output + 1 <= info->max_chars ) { |
*( info->bufptr++ ) = op_char; |
specs->_output_count++; |
info->chars_output++; |
} |
} |
#else |
static slib_callback_t mem_putc; // setup calling convention |
static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char ) |
{ |
*( specs->_dest++ ) = op_char; |
specs->_output_count++; |
} |
#endif |
#ifdef __WIDECHAR__ |
_WCRTLINK int vswprintf( CHAR_TYPE *dest, size_t n, const CHAR_TYPE *format, va_list arg ) |
{ |
slib_callback_t *tmp; |
auto struct vswprtf_buf info; |
#if defined( __386__ ) && defined( __QNX__ ) |
/* avoid some segment relocations for 32-bit QNX */ |
tmp = (void (*)())mem_putc; |
#else |
tmp = mem_putc; |
#endif |
if( n != 0 ) { |
info.bufptr = dest; |
info.chars_output = 0; |
info.max_chars = n - 1; |
__wprtf( &info, format, arg, tmp ); |
dest[info.chars_output] = NULLCHAR; |
} |
return( info.chars_output ); |
} |
#endif |
_WCRTLINK int __F_NAME(vsprintf,_vswprintf) ( CHAR_TYPE *dest, const CHAR_TYPE *format, va_list arg ) |
{ |
slib_callback_t *tmp; |
#ifndef __WIDECHAR__ |
register int len; |
#else |
auto struct vswprtf_buf info; |
#endif |
#if defined( __386__ ) && defined( __QNX__ ) |
/* avoid some segment relocations for 32-bit QNX */ |
tmp = (void (*)())mem_putc; |
#else |
tmp = mem_putc; |
#endif |
#ifdef __WIDECHAR__ |
info.bufptr = dest; |
info.chars_output = 0; |
info.max_chars = INT_MAX; |
__wprtf( &info, format, arg, tmp ); |
dest[info.chars_output] = NULLCHAR; |
return( info.chars_output ); |
#else |
len = __prtf( dest, format, arg, tmp ); |
dest[len] = NULLCHAR; |
return( len ); |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/wctomb.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 "variety.h" |
#include <mbstring.h> |
#include "farfunc.h" |
/**** |
***** Convert a wide character to a multibyte character. |
****/ |
_WCRTLINK int _NEARFAR(wctomb,_fwctomb)( char _FFAR *ch, wchar_t wchar ) |
{ |
/*** Catch special cases ***/ |
if( ch == 0 ) return( 0 ); |
/*** Convert the character ***/ |
if( wchar & 0xFF00 ) |
{ |
ch[0] = (wchar&0xFF00) >> 8; /* store lead byte */ |
ch[1] = wchar & 0x00FF; /* store trail byte */ |
return( 2 ); /* return size in bytes */ |
} |
else |
{ |
ch[0] = wchar & 0x00FF; /* store char byte */ |
return( 1 ); /* return size in bytes */ |
} |
} |