/programs/develop/open watcom/trunk/clib/h/clibi64.h |
---|
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: Prototypes and pragmas for handling __int64 values. |
* |
****************************************************************************/ |
#ifndef _I64_H_INCLUDED |
#define _I64_H_INCLUDED |
#include "variety.h" |
#include "widechar.h" |
#include "watcom.h" |
#define INT64_TYPE __int64 |
#define UINT64_TYPE unsigned __int64 |
#define _clib_I64Negative( a ) (((__int64)a) < 0) |
#define _clib_I64Positive( a ) (((__int64)a) > 0) |
#define _clib_I32ToI64( a, b ) b = (__int64)a |
#define _clib_U32ToU64( a, b ) b = (unsigned __int64)(unsigned_32)a |
#define _clib_I64ToInt( a, b ) b = (signed)a |
#define _clib_U64ToUInt( a, b ) b = (unsigned)a |
#define _clib_I64ToLong( a, b ) b = (signed long)a |
#define _clib_U64ToULong( a, b ) b = (unsigned long)a |
#define _clib_I64Neg( a, b ) b = -a |
#define _clib_U64Neg( a, b ) _clib_I64Neg( a, b ) |
#define _clib_U64Zero( a ) (a == 0) |
#define _clib_U64Cmp( a, b ) (a > b ? +1 : a < b ? -1 : 0) |
#define _clib_U64Mul( a, b, c ) c = a * b |
#define _clib_U64Div( a, b, c, d ) (d = a % b, c = a / b) |
#define _clib_U64Add( a, b, c ) c = a + b |
// conversion functions - use standard ulltoa()/atoll() |
#endif |
/programs/develop/open watcom/trunk/clib/h/close.h |
---|
0,0 → 1,32 |
/**************************************************************************** |
* |
* 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: prototype for __close clib internal function |
* |
****************************************************************************/ |
extern int __close( int handle ); |
/programs/develop/open watcom/trunk/clib/h/errorno.h |
---|
0,0 → 1,35 |
/**************************************************************************** |
* |
* 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! |
* |
****************************************************************************/ |
#define _ERRNO errno |
/programs/develop/open watcom/trunk/clib/h/exitwmsg.h |
---|
0,0 → 1,85 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Fatal runtime error handlers. |
* |
****************************************************************************/ |
#ifndef _EXITWMSG_H_INCLUDED |
#define _EXITWMSG_H_INCLUDED |
#include "variety.h" |
#ifdef __cplusplus |
extern "C" { |
#endif |
#undef _EWM_PARM1 |
#undef _EWM_PARM2 |
#if defined(__386__) |
#define _EWM_PARM1 eax |
#define _EWM_PARM2 edx |
#elif defined(M_I86) |
#define _EWM_PARM1 ax dx |
#define _EWM_PARM2 bx |
#else |
#define _EWM_PARM1 |
#define _EWM_PARM2 |
#endif |
// C interface |
// - tracks normal calling convention |
// - this is the funtion that is called from ASM and from C, C++ |
// - note there is no #pragma aborts so that debugger can trace out |
_WCRTLINK extern void __exit_with_msg( char _WCI86FAR *, unsigned ); |
_WCRTLINK extern void __fatal_runtime_error( char _WCI86FAR *, unsigned ); |
// ASM interface |
// - always uses register calling convention |
// - this function is only called from the C implementation |
// of __exit_with_msg |
extern void __do_exit_with_msg( char _WCI86FAR *, unsigned ); |
#ifdef _M_IX86 |
#pragma aux __do_exit_with_msg "*__" \ |
parm caller [_EWM_PARM1] [_EWM_PARM2]; |
#endif |
#undef _EWM_PARM1 |
#undef _EWM_PARM2 |
_WCRTLINKD extern char volatile __WD_Present; |
// WVIDEO interface |
// this function should be called before __exit_with_msg() |
// to allow Watcom Debugger (nee WVIDEO) to trap runtime errors. |
// this really needs to be far!!! |
_WCRTLINK extern int __EnterWVIDEO( char _WCFAR *string ); |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/exitwmsg.inc |
---|
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! |
;* |
;***************************************************************************** |
ifdef __WASM__ |
ifdef __386__ |
extrn "C",__fatal_runtime_error : near |
else |
ifdef __SMALL__ |
extrn "C",__fatal_runtime_error : near |
endif |
ifdef __COMPACT__ |
extrn "C",__fatal_runtime_error : near |
endif |
ifdef __MEDIUM__ |
extrn "C",__fatal_runtime_error : far |
endif |
ifdef __LARGE__ |
extrn "C",__fatal_runtime_error : far |
endif |
ifdef __HUGE__ |
extrn "C",__fatal_runtime_error : far |
endif |
endif |
endif |
/programs/develop/open watcom/trunk/clib/h/extfunc.h |
---|
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: Special interface for calls to non-Watcom routines from |
* inside clib (x86 specific). |
* |
****************************************************************************/ |
#ifndef EXTFUNC_H_INCLUDED |
#define EXTFUNC_H_INCLUDED |
#include "variety.h" |
#if defined(_M_IX86) |
#if !defined(__WINDOWS__) |
#if defined(__BIG_DATA__) |
#define __DS ds |
#endif |
#endif |
#if !defined(__FLAT__) |
#define __ES es |
#endif |
#if defined(__386__) |
#if defined(__WINDOWS__) || !defined(__FLAT__) |
#define __FS fs |
#endif |
#define __GS gs |
#if defined(__SW_3S) |
#define __AX eax |
#define __BX ebx |
#define __CX ecx |
#define __DX edx |
#endif |
#endif |
#ifndef __AX |
#define __AX |
#endif |
#ifndef __BX |
#define __BX |
#endif |
#ifndef __CX |
#define __CX |
#endif |
#ifndef __DX |
#define __DX |
#endif |
#ifndef __DS |
#define __DS |
#endif |
#ifndef __ES |
#define __ES |
#endif |
#ifndef __FS |
#define __FS |
#endif |
#ifndef __GS |
#define __GS |
#endif |
#pragma aux __outside_CLIB modify [__AX __BX __CX __DX __DS __ES __FS __GS]; |
/* |
use as follows: |
typedef void vfv( void ); |
#pragma aux (__outside_CLIB) __vfv; |
*/ |
#undef __AX |
#undef __BX |
#undef __CX |
#undef __DX |
#undef __DS |
#undef __ES |
#undef __FS |
#undef __GS |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/farfunc.h |
---|
0,0 → 1,43 |
/**************************************************************************** |
* |
* 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: Macros for switching between far and near function version |
* |
****************************************************************************/ |
#ifndef _FARFUNC_H_INCLUDED |
#define _FARFUNC_H_INCLUDED |
#ifdef __FARFUNC__ |
#define _FFAR _WCFAR |
#define _NEARFAR(n1,n2) n2 |
#else |
#define _FFAR |
#define _NEARFAR(n1,n2) n1 |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/farsupp.h |
---|
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: Far pointer support typedefs. |
* |
****************************************************************************/ |
#ifndef _FARSUPP_H_INCLUDED |
#define _FARSUPP_H_INCLUDED |
#include "variety.h" |
#include "widechar.h" |
#ifdef __LONG_LONG_SUPPORT__ |
#include "clibi64.h" |
#endif |
/* Only support near/far pointers on 16-bit targets, extended DOS |
* and Win386. Ideally we might want to test for non-flat memory model. |
*/ |
#if defined( _M_I86 ) || defined( __DOS__ ) || defined( __WINDOWS__ ) |
#define __FAR_SUPPORT__ |
typedef CHAR_TYPE _WCFAR *FAR_STRING; |
typedef char _WCFAR *FAR_ASCII_STRING; |
typedef wchar_t _WCFAR *FAR_UNI_STRING; |
typedef int _WCFAR *FAR_INT; |
typedef signed char _WCFAR *FAR_CHAR; |
typedef short _WCFAR *FAR_SHORT; |
typedef long _WCFAR *FAR_LONG; |
typedef float _WCFAR *FAR_FLOAT; |
typedef double _WCFAR *FAR_DOUBLE; |
#ifdef __LONG_LONG_SUPPORT__ |
typedef UINT64_TYPE _WCFAR *FAR_INT64; |
#endif |
#else |
#undef __FAR_SUPPORT__ |
typedef CHAR_TYPE *FAR_STRING; |
typedef char *FAR_ASCII_STRING; |
typedef wchar_t *FAR_UNI_STRING; |
typedef int *FAR_INT; |
typedef signed char *FAR_CHAR; |
typedef short *FAR_SHORT; |
typedef long *FAR_LONG; |
typedef float *FAR_FLOAT; |
typedef double *FAR_DOUBLE; |
#ifdef __LONG_LONG_SUPPORT__ |
typedef UINT64_TYPE *FAR_INT64; |
#endif |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/fileacc.h |
---|
0,0 → 1,81 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#define _ValidFile( fp, retval ) /* make sure fp is a valid pointer */ |
#define SetupTGCSandNCS( x ) /* initialization for Netware/386 */ |
#if defined(__SW_BM) |
#define _AccessFile( fp ) _AccessFileH( (fp)->_handle ) |
#define _ReleaseFile( fp ) _ReleaseFileH( (fp)->_handle ) |
#if defined(__386__) || defined(__AXP__) || defined(__PPC__) |
extern void (*_AccessFileH)( int ); |
extern void (*_ReleaseFileH)( int ); |
extern void (*_AccessIOB)( void ); |
extern void (*_ReleaseIOB)( void ); |
#else |
// 16bit OS/2 multi-thread is different |
extern void __AccessFileH( int ); |
extern void __ReleaseFileH( int ); |
extern void __AccessIOB( void ); |
extern void __ReleaseIOB( void ); |
// define macros to call the access routines directly for OS/2 1.x |
#define _AccessFileH( hdl ) __AccessFileH( hdl ) |
#define _ReleaseFileH( hdl ) __ReleaseFileH( hdl ) |
#define _AccessIOB() __AccessIOB() |
#define _ReleaseIOB() __ReleaseIOB() |
#endif |
#if defined(__NT__) |
extern void (*_AccessFList)( void ); |
extern void (*_ReleaseFList)( void ); |
#endif |
#else |
/* these are for multi thread support */ |
/* they are not required if not building multi-thread library */ |
/* note: 32 bit NETWARE, OS/2, NT, QNX libraries are always multi-thread */ |
#define _AccessFile( fp ) /* gain access to the FILE* pointer */ |
#define _ReleaseFile( fp ) /* release access */ |
#define _AccessFileH( hdl ) /* gain access to the file handle */ |
#define _ReleaseFileH( hdl ) /* release access */ |
#define _AccessIOB() /* gain access to array of __iob's */ |
#define _ReleaseIOB() /* release access */ |
#if defined(__NT__) |
#define _AccessFList() |
#define _ReleaseFList() |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/fixpoint.h |
---|
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: Fixed-point data type. |
* |
****************************************************************************/ |
typedef union t32 { |
unsigned long uWhole; |
signed long sWhole; |
struct { unsigned short int lo, hi; } wd; |
struct { unsigned char b1, b2, b3, b4; } bite; |
} T32; |
/programs/develop/open watcom/trunk/clib/h/flush.h |
---|
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: Prototype for __flush and __flushall internal routines. |
* |
****************************************************************************/ |
/* __flush is used by C++ run-time library */ |
_WCRTLINK extern int __flush( FILE * ); |
extern int __flushall( int ); |
/programs/develop/open watcom/trunk/clib/h/fprtf.h |
---|
0,0 → 1,32 |
/**************************************************************************** |
* |
* 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: Prototype for __fprtf() internal routine. |
* |
****************************************************************************/ |
extern int __F_NAME(__fprtf,__fwprtf)( FILE *fp, const CHAR_TYPE *format, va_list arg ); |
/programs/develop/open watcom/trunk/clib/h/ftos.h |
---|
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: Prototypes for floating-point formatting routines. |
* |
****************************************************************************/ |
#ifndef _FTOS_H_INCLUDED |
#define _FTOS_H_INCLUDED |
#include "variety.h" |
#include "farsupp.h" |
_WCRTLINK extern FAR_STRING (*__EFG_printf)(); |
_WCRTLINK extern void (*__EFG_scanf)(); |
extern FAR_STRING _EFG_Format(); |
extern void __cnvs2d(); |
_WMRTLINK extern FAR_STRING (*__get_EFG_Format())(); |
_WMRTLINK extern void (*__get__cnvs2d())(); |
#endif |
/programs/develop/open watcom/trunk/clib/h/handleio.h |
---|
0,0 → 1,41 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: prototypes for handleio internal functions |
* |
****************************************************************************/ |
/* __plusplus_fstat and __plusplus_open are used by C++ run-time library */ |
_WCRTLINK extern int __plusplus_fstat( int handle, int *pios_mode ); |
_WCRTLINK extern int __plusplus_open( const char *name, int *pios_mode, int prot ); |
extern unsigned __IOMode( int handle ); |
extern void __set_handles( int num ); |
extern void __grow_iomode( int num ); |
extern void __shrink_iomode( void ); |
extern unsigned *__io_mode; |
/programs/develop/open watcom/trunk/clib/h/heap.h |
---|
0,0 → 1,207 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Heap library configuration for various platforms. |
* |
****************************************************************************/ |
#include "variety.h" |
#if defined(_M_IX86) |
#include <i86.h> |
#endif |
#if !defined(__DOS_EXT__) |
#if defined(__386__) && \ |
!defined(__WINDOWS_386__) && \ |
!defined(__WINDOWS__) && \ |
!defined(__OS2__) && \ |
!defined(__NT__) && \ |
!defined(__OSI__) && \ |
!defined(__UNIX__) |
#define __DOS_EXT__ |
#endif |
#endif |
typedef unsigned int tag; |
typedef struct freelistp frl; |
typedef struct freelistp _WCNEAR *frlptr; |
typedef struct freelist _WCFAR *farfrlptr; |
typedef unsigned char _WCNEAR *PTR; |
typedef unsigned char _WCFAR *FARPTR; |
typedef struct miniheapblkp _WCNEAR *mheapptr; |
/* |
** NOTE: the size of these data structures is critical to the alignemnt |
** of the pointers returned by malloc(). |
*/ |
struct freelist { |
tag len; /* length of block in free list */ |
unsigned int prev; /* offset of previous block in free list */ |
unsigned int next; /* offset of next block in free list */ |
}; |
struct heapblk { |
tag heaplen; /* size of heap (0 = 64K) */ |
unsigned int prevseg; /* segment selector for previous heap */ |
unsigned int nextseg; /* segment selector for next heap */ |
unsigned int rover; /* roving pointer into free list */ |
unsigned int b4rover; /* largest block before rover */ |
unsigned int largest_blk; /* largest block in the heap */ |
unsigned int numalloc; /* number of allocated blocks in heap */ |
unsigned int numfree; /* number of free blocks in the heap */ |
struct freelist freehead; /* listhead of free blocks in heap */ |
}; |
struct freelistp { |
tag len; |
frlptr prev; |
frlptr next; |
}; |
struct heapblkp { |
tag heaplen; |
unsigned int prevseg; |
unsigned int nextseg; |
frlptr rover; |
unsigned int b4rover; |
unsigned int largest_blk; |
unsigned int numalloc; |
unsigned int numfree; |
frl freehead; |
}; |
struct miniheapblkp { |
tag len; |
mheapptr prev; |
mheapptr next; |
frlptr rover; |
unsigned int b4rover; |
unsigned int largest_blk; |
unsigned int numalloc; |
unsigned int numfree; |
frl freehead; |
}; |
struct heapstart { |
struct heapblk h; |
struct freelist first; |
}; |
struct heapend { |
tag last_tag; |
struct freelist last; |
}; |
#ifdef __DOS_EXT__ |
struct dpmi_hdr { |
unsigned long dpmi_handle; |
tag dos_seg_value; // 0 => DPMI block, else DOS segment |
}; |
#endif |
extern unsigned _curbrk; |
extern mheapptr _WCNEAR __nheapbeg; |
#if defined(_M_IX86) |
extern __segment __fheap; |
extern __segment __bheap; |
extern __segment __fheapRover; |
#endif |
extern int __heap_enabled; |
extern unsigned int __LargestSizeB4Rover; |
extern struct miniheapblkp _WCNEAR *__MiniHeapRover; |
extern unsigned int __LargestSizeB4MiniHeapRover; |
extern struct miniheapblkp _WCNEAR *__MiniHeapFreeRover; |
extern size_t __LastFree( void ); |
extern int __NHeapWalk( struct _heapinfo *entry, mheapptr heapbeg ); |
extern int __ExpandDGROUP( unsigned int __amt ); |
#if defined(_M_IX86) |
extern unsigned __AllocSeg( unsigned int __amt ); |
extern unsigned __GrowSeg( __segment __seg, unsigned int __amt ); |
extern int __FreeSeg( __segment seg ); |
extern int __HeapWalk( struct _heapinfo *entry, __segment seg, unsigned all ); |
extern int __HeapMin( __segment seg, unsigned one_seg ); |
extern int __HeapSet( __segment seg, unsigned fill ); |
#endif |
#if defined(__DOS_EXT__) |
extern void __FreeDPMIBlocks( void ); |
extern void *__ReAllocDPMIBlock( frlptr p1, unsigned req_size ); |
extern void *__ExpandDPMIBlock( frlptr, unsigned ); |
#endif |
extern int __HeapManager_expand( __segment seg, unsigned offset, |
size_t req_size, size_t *growth_size ); |
extern void _WCFAR __HeapInit( void _WCNEAR *start, unsigned int amount ); |
_WCRTLINK extern void _WCNEAR *__brk( unsigned ); |
#if defined(_M_IX86) |
#define _DGroup() FP_SEG((&__nheapbeg)) |
#else |
#define _DGroup() 0 |
#endif |
// __IsCtsNHeap() is used to determine whether the operating system provides |
// a continuous near heap block. __ExpandDGroup should slice for more near |
// heap under those operating systems with __IsCtsNHeap() == 1. |
#if defined(__WARP__) || \ |
defined(__NT__) || \ |
defined(__WINDOWS_386__) || \ |
defined(__WINDOWS_286__) |
#define __IsCtsNHeap() 0 |
#elif defined(__DOS_EXT__) |
#define __IsCtsNHeap() ((_IsRationalZeroBase() || _IsCodeBuilder()) ? 0 : 1) |
#else |
#define __IsCtsNHeap() 1 |
#endif |
extern unsigned __MemAllocator( unsigned __sz, unsigned __seg, unsigned __off ); |
extern void __MemFree( unsigned __ptr, unsigned __seg, unsigned __off ); |
#if defined(_M_IX86) |
#if defined(__386__) |
#pragma aux __MemAllocator "*" parm [eax] [edx] [ebx]; |
#pragma aux __MemFree "*" parm [eax] [edx] [ebx]; |
#else |
#pragma aux __MemAllocator "*" parm [ax] [dx] [bx]; |
#pragma aux __MemFree "*" parm [ax] [dx] [bx]; |
#endif |
#endif |
#define PARAS_IN_64K (0x1000) |
#define END_TAG (~0) |
#define TAG_SIZE (sizeof(tag)) |
#if defined(M_I86) |
#define ROUND_SIZE (TAG_SIZE-1) |
#else |
#define ROUND_SIZE (TAG_SIZE+TAG_SIZE-1) |
#endif |
#define FRL_SIZE ((sizeof(frl)+ROUND_SIZE)&~ROUND_SIZE) |
#define __HM_SUCCESS 0 |
#define __HM_FAIL 1 |
#define __HM_TRYGROW 2 |
/programs/develop/open watcom/trunk/clib/h/heapacc.h |
---|
0,0 → 1,59 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#ifndef _HEAPACC_H_INCLUDED |
#define _HEAPACC_H_INCLUDED |
/* macros for serialization of accesses to the heap */ |
#if defined(__SW_BM) |
#if defined(__386__) || defined(__AXP__) || defined(__PPC__) |
extern void (*_AccessFHeap)(); |
extern void (*_ReleaseFHeap)(); |
extern void (*_AccessNHeap)(); |
extern void (*_ReleaseNHeap)(); |
#else |
extern void __AccessFHeap(); |
extern void __ReleaseFHeap(); |
extern void __AccessNHeap(); |
extern void __ReleaseNHeap(); |
#define _AccessFHeap() __AccessFHeap() |
#define _ReleaseFHeap() __ReleaseFHeap() |
#define _AccessNHeap() __AccessNHeap() |
#define _ReleaseNHeap() __ReleaseNHeap() |
#endif |
#else |
#define _AccessFHeap() |
#define _ReleaseFHeap() |
#define _AccessNHeap() |
#define _ReleaseNHeap() |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/iomode.h |
---|
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: prototypes and definitions for iomode array manipulation |
* |
****************************************************************************/ |
#ifndef _IOMODE_H_INCLUDED |
#define _IOMODE_H_INCLUDED |
#if defined(__NT__) |
#include <windows.h> |
#define NULL_HANDLE (HANDLE)-1 |
#define DUMMY_HANDLE (HANDLE)-2 |
extern unsigned __NHandles; |
extern void __initPOSIXHandles( void ); |
extern unsigned __growPOSIXHandles( unsigned num ); |
extern int __allocPOSIXHandle( HANDLE hdl ); |
extern void __freePOSIXHandle( int hid ); |
extern HANDLE __getOSHandle( int hid ); |
extern int __setOSHandle( unsigned hid, HANDLE hdl ); |
extern HANDLE __NTGetFakeHandle( void ); |
extern HANDLE *__OSHandles; |
#define __getOSHandle( hid ) __OSHandles[ hid ] |
#define NT_STDIN_FILENO (__getOSHandle( STDIN_FILENO )) |
#define NT_STDOUT_FILENO (__getOSHandle( STDOUT_FILENO )) |
#define NT_STDERR_FILENO (__getOSHandle( STDERR_FILENO )) |
#endif |
#if !defined(__NETWARE__) |
extern unsigned __GetIOMode( int __handle ); |
extern int __SetIOMode( int __handle, unsigned __value ); |
extern void __SetIOMode_nogrow( int __handle, unsigned __value ); |
extern void __ChkTTYIOMode( int __handle ); |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/langenv.h |
---|
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: Establish common stuff for a target environment for |
* language-related processors. |
* |
****************************************************************************/ |
#ifndef __LANGENV_H__ |
#define __LANGENV_H__ |
// This file uses __TGT_SYS to figure out the required target. |
// |
// langenvd.h contains the possible values. |
// |
// __TGT_SYS_X86 is the default |
// |
#include "langenvd.h" |
#ifndef __TGT_SYS |
#define __TGT_SYS __TGT_SYS_X86 |
#endif |
#if __TGT_SYS == __TGT_SYS_X86 |
#define TS_SEG_CODE "_TEXT" |
#define TS_SEG_CONST "CONST" |
#define TS_SEG_CONST2 "CONST2" |
#define TS_SEG_DATA "_DATA" |
#define TS_SEG_TIB "TIB" |
#define TS_SEG_TI "TI" |
#define TS_SEG_TIE "TIE" |
#define TS_SEG_XIB "XIB" |
#define TS_SEG_XI "XI" |
#define TS_SEG_XIE "XIE" |
#define TS_SEG_YIB "YIB" |
#define TS_SEG_YI "YI" |
#define TS_SEG_YIE "YIE" |
#define TS_SEG_YC "YC" |
#define TS_SEG_BSS "_BSS" |
#define TS_SEG_STACK "STACK" |
#define TS_SEG_DEPENDS "not used" |
#define TS_SEG_TLSB ".tls" |
#define TS_SEG_TLS ".tls$" |
#define TS_SEG_TLSE ".tls$ZZZ" |
#define TS_SEG_TLS_CLASS "TLS" |
#define TS_MAX_OBJNAME 256 |
#define TS_DATA_MANGLE "_*" |
#define TS_CODE_MANGLE "*_" |
#elif __TGT_SYS == __TGT_SYS_AXP_NT || __TGT_SYS == __TGT_SYS_PPC_NT || __TGT_SYS == __TGT_SYS_MIPS |
#define TS_SEG_CODE ".text" |
#define TS_SEG_CONST ".const" |
#define TS_SEG_CONST2 ".const2" |
#define TS_SEG_DATA ".data" |
#define TS_SEG_TIB ".rtl$tib" |
#define TS_SEG_TI ".rtl$tid" |
#define TS_SEG_TIE ".rtl$tie" |
#define TS_SEG_XIB ".rtl$xib" |
#define TS_SEG_XI ".rtl$xid" |
#define TS_SEG_XIE ".rtl$xie" |
#define TS_SEG_YIB ".rtl$yib" |
#define TS_SEG_YI ".rtl$yid" |
#define TS_SEG_YIE ".rtl$yie" |
#define TS_SEG_YC ".rtl$yc" |
#define TS_SEG_BSS ".bss" |
#define TS_SEG_STACK ".stack" |
#define TS_SEG_DEPENDS ".depend" |
#define TS_SEG_TLSB ".tls" |
#define TS_SEG_TLS ".tls$" |
#define TS_SEG_TLSE ".tls$ZZZ" |
#define TS_SEG_TLS_CLASS NULL |
#define TS_MAX_OBJNAME 1024 |
#define TS_DATA_MANGLE "*" |
#define TS_CODE_MANGLE "*" |
#else |
#error Invalid target system |
#endif |
#undef __TGT_SYS |
#endif |
/programs/develop/open watcom/trunk/clib/h/langenvd.h |
---|
0,0 → 1,40 |
/**************************************************************************** |
* |
* 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: Define values for language targets. |
* |
****************************************************************************/ |
#ifndef __LANGENVD_H__ |
#define __LANGENVD_H__ |
#define __TGT_SYS_X86 0 // All x86 systems to date |
#define __TGT_SYS_AXP_NT 1 // Win32 on DEC Alpha AXP |
#define __TGT_SYS_PPC_NT 2 // Win32 on IBM/Motorola PowerPC |
#define __TGT_SYS_MIPS 3 // MIPS RISC Architecture |
#endif |
/programs/develop/open watcom/trunk/clib/h/liballoc.h |
---|
0,0 → 1,90 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: These are macros that define the 'real' functions that |
* the library memory allocators use. |
* |
****************************************************************************/ |
#ifndef _LIBALLOC_H_INCLUDED |
#define _LIBALLOC_H_INCLUDED |
#include "variety.h" |
#include <malloc.h> |
#ifdef __NETWARE__ |
/* |
// NetWare uses Alloc and Free because the heap will not have |
// been initialised at _Prelude time... |
*/ |
#define lib_malloc( x ) _NW_malloc( x ) |
#define lib_free( x ) _NW_free( x ) |
#if defined (_NETWARE_CLIB) |
#define lib_realloc( x, y, z) _NW_realloc( x, y, z ) |
#else |
#define lib_realloc( x, y) _NW_realloc( x, y) |
#endif |
#define lib_calloc( x, y ) _NW_calloc( x, y ) |
extern void *_NW_calloc( size_t __n,size_t __size ); |
extern void *_NW_malloc( size_t ); |
#if defined (_NETWARE_CLIB) |
extern void *_NW_realloc( void *ptr,size_t size,size_t old); |
#else |
extern void *_NW_realloc( void *ptr,size_t size); |
#endif |
extern void _NW_free( void *ptr ); |
#else |
#define lib_malloc( x ) malloc( x ) |
#define lib_free( x ) free( x ) |
#define lib_realloc( x, y ) realloc( x, y ) |
#define lib_nmalloc( x ) _nmalloc( x ) |
#define lib_nfree( x ) _nfree( x ) |
#define lib_nrealloc( x, y ) _nrealloc( x, y ) |
#define lib_fmalloc( x ) _fmalloc( x ) |
#define lib_ffree( x ) _ffree( x ) |
#define lib_frealloc( x, y ) _frealloc( x, y ) |
#define lib_calloc( x, y ) calloc( x, y ) |
#endif |
// these are used by the C++ library |
// they are real routines so that the C++ library |
// remains platform independent. |
#ifdef __cplusplus |
extern "C" { |
#endif |
_WCRTLINK extern void _plib_free( void *ptr ); |
_WCRTLINK extern void *_plib_malloc( size_t size ); |
#ifdef __cplusplus |
} |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/lseek.h |
---|
0,0 → 1,41 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: basic __lseek (without file extend) definition/prototype |
* |
****************************************************************************/ |
#ifndef _LSEEK_H_INCLUDED |
#define _LSEEK_H_INCLUDED |
#if defined(__DOS__) || defined(__OS2__) || defined(__NT__) || defined(__WINDOWS__) |
_WCRTLINK extern long __lseek( int handle, long offset, int origin ); |
#else |
#define __lseek lseek |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/mbchar.h |
---|
0,0 → 1,57 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#if !defined(MBCHARdotH) |
#define MBCHARdotH |
/* Prototype for initialization function */ |
extern int __mbinit( int codepage ); |
#define _MBINIT_CP_ANSI (-1) |
#define _MBINIT_CP_OEM (-2) |
#define _MBINIT_CP_SBCS (-3) |
#define _MBINIT_CP_932 (-4) |
/* Current code page */ |
#if !defined(__UNIX__) |
extern unsigned int __MBCodePage; |
#define _MB_CODE_PAGE_DEFINED |
#endif |
/* See if a packed DBCS char has no lead byte, i.e. is a skinny char */ |
#define SINGLE_BYTE_CHAR(__c) ( !( (__c)&0xFF00 ) ) |
#endif |
/programs/develop/open watcom/trunk/clib/h/mdef.inc |
---|
0,0 → 1,358 |
;***************************************************************************** |
;* |
;* 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: Memory model setup for interfacing with C code. |
;* |
;***************************************************************************** |
_SMALL_CODE = 00h |
_BIG_CODE = 01h |
_SMALL_DATA = 00h |
_BIG_DATA = 02h |
_HUGE_DATA = 04h |
_LONG_INTS = 08h |
_USE_32_SEGS = 10h |
_386 = 10h ; from old clib |
_DS_PEGGED = 20h ; from old clib (used for Windows) |
_TINY = 40h ; from old clib (formerly 10h) |
_FLAT = ( _SMALL_CODE or _SMALL_DATA or _USE_32_SEGS ) |
_SMALL = ( _SMALL_CODE or _SMALL_DATA ) |
_COMPACT = ( _SMALL_CODE or _BIG_DATA ) |
_MEDIUM = ( _BIG_CODE or _SMALL_DATA ) |
_LARGE = ( _BIG_CODE or _BIG_DATA ) |
_HUGE = ( _BIG_CODE or _HUGE_DATA ) |
_EMULATION = 00h |
_8087 = 01h |
ifdef __WASM__ |
ifdef __FLAT__ |
_MODEL = _FLAT |
endif |
ifdef __SMALL__ |
_MODEL = _SMALL |
endif |
ifdef __COMPACT__ |
_MODEL = _COMPACT |
endif |
ifdef __MEDIUM__ |
_MODEL = _MEDIUM |
endif |
ifdef __LARGE__ |
_MODEL = _LARGE |
endif |
ifdef __HUGE__ |
_MODEL = _HUGE |
endif |
ifdef __386__ |
_MODEL = ( _MODEL or _USE_32_SEGS ) |
endif |
ifdef __WINDOWS__ |
if _MODEL and (_BIG_DATA or _HUGE_DATA) |
_MODEL = ( _MODEL or _DS_PEGGED ) |
endif |
endif |
ifdef __FPC__ |
_MATH = _EMULATION |
endif |
ifdef __FPI__ |
_MATH = _8087 |
endif |
ifdef __FPI87__ |
_MATH = _8087 |
endif |
else |
include .\model.inc ; defines _MODEL, _MATH symbols |
endif |
if _MODEL and _BIG_CODE |
modstart macro modname,alignment |
ifdef NDEBUG |
name modname |
endif |
ifb <alignment> |
_TEXT segment word public 'CODE' |
else |
_TEXT segment alignment public 'CODE' |
endif |
assume cs:_TEXT |
endm |
calli macro regname |
call dword ptr [regname] |
endm |
codeptr macro p1,p2 |
ifb <p2> |
extrn p1 : dword |
else |
extrn "&p1",p2 : dword |
endif |
endm |
docall macro dest |
call far ptr dest |
endm |
dojmp macro dest |
jmp far ptr dest |
endm |
defp macro dsym,exp |
dsym proc far exp |
endm |
defpe macro dsym |
ifdef _EXPORT |
dsym proc far export |
else |
dsym proc far |
endif |
endm |
defn macro dsym |
dsym proc near |
endm |
endproc macro dsym |
dsym endp |
endm |
epilog macro |
if _MODEL and _USE_32_SEGS |
pop EBP |
dec EBP |
mov ESP,EBP |
else |
pop BP |
dec BP |
endif |
endm |
prolog macro |
if _MODEL and _USE_32_SEGS |
inc EBP |
push EBP |
mov EBP,ESP |
else |
inc BP |
push BP |
mov BP,SP |
endif |
endm |
xdefp macro p1,p2 |
ifb <p2> |
public p1 |
else |
public "&p1",p2 |
endif |
endm |
xref macro p1,p2 |
ifb <p2> |
extrn `p1` : far |
else |
extrn "&p1",`p2` : far |
endif |
endm |
lcall macro dest |
push cs |
call near ptr dest |
endm |
else |
modstart macro modname,alignment |
ifdef NDEBUG |
name modname |
endif |
if _MODEL and _USE_32_SEGS |
_TEXT segment use32 alignment public 'CODE' |
else |
_TEXT segment alignment public 'CODE' |
endif |
assume cs:_TEXT |
endm |
calli macro regname |
call regname |
endm |
codeptr macro p1,p2 |
if _MODEL and _USE_32_SEGS |
ifb <p2> |
extrn p1 : dword |
else |
extrn "&p1",p2 : dword |
endif |
else |
ifb <p2> |
extrn p1 : word |
else |
extrn "&p1",p2 : word |
endif |
endif |
endm |
defn macro dsym |
dsym proc near |
endm |
defp macro dsym,exp |
dsym proc near exp |
endm |
defpe macro dsym |
ifdef _EXPORT |
dsym proc near export |
else |
dsym proc near |
endif |
endm |
docall macro dest |
call dest |
endm |
dojmp macro dest |
jmp dest |
endm |
endproc macro dsym |
dsym endp |
endm |
epilog macro |
if _MODEL and _USE_32_SEGS |
pop EBP |
else |
pop BP |
endif |
endm |
prolog macro |
if _MODEL and _USE_32_SEGS |
push EBP |
mov EBP,ESP |
else |
push BP |
mov BP,SP |
endif |
endm |
xdefp macro p1,p2 |
ifb <p2> |
public p1 |
else |
public "&p1",p2 |
endif |
endm |
xref macro p1,p2 |
ifb <p2> |
extrn `p1` : near |
else |
extrn "&p1",`p2` : near |
endif |
endm |
lcall macro dest |
call dest |
endm |
endif |
endmod macro |
_TEXT ends |
endm |
dataseg macro |
DGROUP group _DATA |
assume ds:DGROUP,ss:DGROUP |
if _MODEL and _USE_32_SEGS |
_DATA segment use32 dword public 'DATA' |
else |
_DATA segment word public 'DATA' |
endif |
endm |
datasegment macro |
dataseg ; should be phased out |
endm |
enddata macro |
_DATA ends |
endm |
bss_segment macro |
if _MODEL and _USE_32_SEGS |
_BSS segment use32 dword public 'BSS' |
else |
_BSS segment word public 'BSS' |
endif |
DGROUP group _BSS |
assume ds:DGROUP |
endm |
endbss macro |
_BSS ends |
endm |
alias_function macro alias, function |
ifb <function> |
xref "C",_&alias |
else |
xref "C",function |
endif |
.code |
public "C",`alias` |
ifdef _EXPORT |
`alias` proc export |
else |
`alias` proc |
endif |
ifb <function> |
jmp _&alias |
else |
jmp `function` |
endif |
`alias` endp |
endm |
xred macro p1,p2,p3 |
ifb <p3> |
extrn p1 : p2 |
else |
extrn "&p1",p2 : p3 |
endif |
endm |
/programs/develop/open watcom/trunk/clib/h/mf.h |
---|
0,0 → 1,100 |
//#include "kolibc.h" |
#ifdef __cplusplus |
extern "C" { |
#endif /* __cplusplus */ |
typedef unsigned int dword; |
typedef unsigned int size_t; |
#define PINUSE_BIT 1 |
#define CINUSE_BIT 2 |
#define INUSE_BITS 3 |
struct m_seg |
{ |
char* base; /* base address */ |
dword size; /* allocated size */ |
struct m_seg* next; /* ptr to next segment */ |
dword flags; /* mmap and extern flag */ |
}; |
struct m_chunk |
{ |
dword prev_foot; /* Size of previous chunk (if free). */ |
dword head; /* Size and inuse bits. */ |
struct m_chunk* fd; /* double links -- used only if free. */ |
struct m_chunk* bk; |
}; |
typedef struct m_chunk* mchunkptr; |
struct t_chunk |
{ |
/* The first four fields must be compatible with malloc_chunk */ |
dword prev_foot; |
dword head; |
struct t_chunk* fd; |
struct t_chunk* bk; |
struct t_chunk* child[2]; |
struct t_chunk* parent; |
dword index; |
}; |
typedef struct t_chunk* tchunkptr; |
typedef struct t_chunk* tbinptr; |
typedef struct m_state |
{ |
dword smallmap; |
dword treemap; |
// DWORD dvsize; |
dword topsize; |
char* least_addr; |
// mchunkptr dv; |
mchunkptr top; |
dword magic; |
struct m_chunk smallbins[32]; |
tbinptr treebins[32]; |
}; |
void _cdecl init_malloc(void* p); |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void* _cdecl dlrealloc(void *,size_t); |
dword compute_tree_index(size_t s); |
static void insert_chunk(mchunkptr P, size_t S); |
static void insert_large_chunk(tchunkptr X, size_t S); |
static void unlink_large_chunk(tchunkptr X); |
//void replace_dv(mchunkptr P, size_t S); |
static void* malloc_small(size_t nb); |
static void* malloc_large(size_t nb); |
#define leftshift_for_tree_index(i) \ |
((i == 31)? 0 : (31 - (i >> 1) + 8 - 2)) |
#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) |
#define chunk2mem(p) (void*)((char*)p + 8) |
#define mem2chunk(mem) (mchunkptr)((char*)mem - 8) |
#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) |
#ifdef __cplusplus |
} |
#endif /* __cplusplus */ |
/programs/develop/open watcom/trunk/clib/h/myvalist.h |
---|
0,0 → 1,49 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Mask differences between platforms where va_list is an |
* array and platforms where it's not. |
* |
****************************************************************************/ |
#ifndef _MYVALIST_H_INCLUDED |
#include "variety.h" |
#include <stdarg.h> |
typedef struct my_va_list { |
va_list v; |
} my_va_list; |
#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) |
#define MY_VA_LIST( a ) (*(my_va_list *)&(a)) |
#else |
#define MY_VA_LIST( a ) (*(my_va_list *)(a)) |
#endif |
#define _MYVALIST_H_INCLUDED |
#endif |
/programs/develop/open watcom/trunk/clib/h/orient.h |
---|
0,0 → 1,57 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Macro to deal with stream orientation. |
* |
****************************************************************************/ |
#ifdef __NETWARE__ |
/* One less thing to worry about */ |
#define ORIENT_STREAM(stream,error_return) |
#else |
#ifdef __WIDECHAR__ |
#define ORIENT_STREAM(stream,error_return) \ |
if( _FP_ORIENTATION(stream) != _WIDE_ORIENTED ) { \ |
if( _FP_ORIENTATION(stream) == _NOT_ORIENTED ) { \ |
_FP_ORIENTATION(stream) = _WIDE_ORIENTED; \ |
} else { \ |
_ReleaseFile( stream ); \ |
return( error_return ); \ |
} \ |
} |
#else |
#define ORIENT_STREAM(stream,error_return) \ |
if( _FP_ORIENTATION(stream) != _BYTE_ORIENTED ) { \ |
if( _FP_ORIENTATION(stream) == _NOT_ORIENTED ) { \ |
_FP_ORIENTATION(stream) = _BYTE_ORIENTED; \ |
} else { \ |
_ReleaseFile( stream ); \ |
return( error_return ); \ |
} \ |
} |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/printf.h |
---|
0,0 → 1,183 |
/**************************************************************************** |
* |
* 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: Definitions needed by callers to internal string formatter |
* __prtf() for printf() style handling. |
* |
****************************************************************************/ |
#ifndef _PRINTF_H_INCLUDED |
#define _PRINTF_H_INCLUDED |
#include "variety.h" |
#include "widechar.h" |
#if defined(__QNX__) |
#if defined(__386__) |
#define __SLIB_CALLBACK _WCFAR |
#define __SLIB |
#pragma aux slib_callback_t __far parm [eax] [edx] modify [eax edx]; |
#elif defined( __SMALL_DATA__ ) |
#define __SLIB_CALLBACK _WCFAR __loadds |
#define __SLIB _WCFAR |
#else |
#define __SLIB_CALLBACK _WCFAR |
#define __SLIB _WCFAR |
#endif |
#else |
#if defined( __HUGE__ ) |
#define __SLIB _WCFAR |
#define __SLIB_CALLBACK |
#else |
#define __SLIB |
#define __SLIB_CALLBACK |
#endif |
#endif |
#define SPECS_VERSION 200 |
/* |
* This is the __prtf specs structure. NB - should be naturally aligned. |
* |
* There are both wide and MBCS versions explicitly because part of __wprtf |
* needs to access both kinds of structure. |
*/ |
typedef struct |
{ |
char __SLIB *_dest; |
short _flags; // flags (see below) |
short _version; // structure version # (2.0 --> 200) |
int _fld_width; // field width |
int _prec; // precision |
int _output_count; // # of characters outputted for %n |
int _n0; // number of chars to deliver first |
int _nz0; // number of zeros to deliver next |
int _n1; // number of chars to deliver next |
int _nz1; // number of zeros to deliver next |
int _n2; // number of chars to deliver next |
int _nz2; // number of zeros to deliver next |
char _character; // format character |
char _pad_char; |
char _padding[2]; // to keep struct aligned |
} _mbcs_SPECS; |
typedef struct |
{ |
wchar_t __SLIB *_dest; |
short _flags; // flags (see below) |
short _version; // structure version # (2.0 --> 200) |
int _fld_width; // field width |
int _prec; // precision |
int _output_count; // # of characters outputted for %n |
int _n0; // number of chars to deliver first |
int _nz0; // number of zeros to deliver next |
int _n1; // number of chars to deliver next |
int _nz1; // number of zeros to deliver next |
int _n2; // number of chars to deliver next |
int _nz2; // number of zeros to deliver next |
wchar_t _character; // format character |
wchar_t _pad_char; |
} _wide_SPECS; |
#ifdef __WIDECHAR__ |
#define SPECS _wide_SPECS |
#else |
#define SPECS _mbcs_SPECS |
#endif |
typedef void (__SLIB_CALLBACK slib_callback_t)( SPECS __SLIB *, int ); |
/* specification flags... (values for _flags field above) */ |
#define SPF_ALT 0x0001 |
#define SPF_BLANK 0x0002 |
#define SPF_FORCE_SIGN 0x0004 |
#define SPF_LEFT_ADJUST 0x0008 |
#define SPF_CHAR 0x0010 |
#define SPF_SHORT 0x0020 |
#define SPF_LONG 0x0040 |
#define SPF_LONG_LONG 0x0080 |
#define SPF_LONG_DOUBLE 0x0100 // may be also used for __int64 |
#define SPF_NEAR 0x0200 |
#define SPF_FAR 0x0400 |
#define SPF_CVT 0x0800 // __cvt function |
#ifdef __QNX__ |
#define SPF_ZERO_PAD 0x8000 |
#endif // __QNX__ |
#if defined( __STDC_WANT_LIB_EXT1__ ) && __STDC_WANT_LIB_EXT1__ == 1 |
#if !defined( __WIDECHAR__ ) |
int __prtf_s( void __SLIB *dest, /* parm for use by out_putc */ |
const char * __restrict format, /* pointer to format string */ |
va_list args, /* pointer to pointer to args*/ |
const char **errmsg, /* constraint violation msg */ |
slib_callback_t *out_putc ); /* character output routine */ |
#else |
int __wprtf_s( void __SLIB *dest, /* parm for use by out_putc */ |
const CHAR_TYPE * __restrict format,/* pointer to format string */ |
va_list args, /* pointer to pointer to args*/ |
const char **errmsg, /* constraint violation msg */ |
slib_callback_t *out_putc ); /* character output routine */ |
#endif |
#else |
#if !defined(__WIDECHAR__) |
int __prtf( void __SLIB *dest, /* parm for use by out_putc */ |
const char *format, /* pointer to format string */ |
va_list args, /* pointer to pointer to args*/ |
slib_callback_t *out_putc ); /* character output routine */ |
#else |
int __wprtf( 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*/ |
slib_callback_t *out_putc ); /* character output routine */ |
#endif |
#ifdef __QNX__ |
int __prtf_slib( void __SLIB *dest, /* parm for use by out_putc */ |
const char * format, /* pointer to format string */ |
char **args, /* pointer to pointer to args*/ |
slib_callback_t *out_putc, /* character output routine */ |
int ptr_size ); |
#if !defined(IN_SLIB) && !defined(__386__) |
extern int ( _WCFAR * ( _WCFAR *__f)) (); |
#define __prtf(a,b,c,d) __prtf_slib(a,b,c,d,sizeof(void *)) |
#define __prtf_slib(a,b,c,d,e) ((int(_WCFAR *) (void _WCFAR *,const char _WCFAR *,char * _WCFAR *args,void (_WCFAR *__out)(SPECS _WCFAR *,int),int)) __f[24])(a,b,c,d,e) |
#endif |
#endif |
#endif /* Safer C */ |
#endif |
/programs/develop/open watcom/trunk/clib/h/prtscncf.h |
---|
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: Configure 'j', 'z', and 't' modifiers for __scnf and __prtf. |
* |
****************************************************************************/ |
#ifndef PTRSCNF_H_INCLUDED |
#define PTRSCNF_H_INCLUDED |
#include <limits.h> |
#include <stdint.h> |
/* Currently size_t is always 'unsigned int', but won't be on LP64 systems */ |
#if SIZE_MAX == UINT_MAX |
#define ZSPEC_IS_INT |
#elif SIZE_MAX == ULONG_MAX |
#define ZSPEC_IS_LONG |
#else |
#error Could not configure zspec |
#endif |
/* Currently intmax_t is always 'long long int' but might be something |
* else, in theory at least |
*/ |
#if INTMAX_MAX == LLONG_MAX |
#define JSPEC_IS_LLONG |
#define JSPEC_CASE_LLONG case 'j': |
#else |
#error Could not configure jspec |
#endif |
/* Currently ptrdiff_t can be either 'long int' or 'int' */ |
#if PTRDIFF_MAX == INT_MAX |
#define TSPEC_IS_INT |
#elif PTRDIFF_MAX == LONG_MAX |
#define TSPEC_IS_LONG |
#else |
#error Could not configure tspec |
#endif |
#ifdef ZSPEC_IS_INT |
#define ZSPEC_CASE_INT case 'z': |
#else |
#define ZSPEC_CASE_INT |
#endif |
#ifdef ZSPEC_IS_LONG |
#define ZSPEC_CASE_LONG case 'z': |
#else |
#define ZSPEC_CASE_LONG |
#endif |
#ifdef TSPEC_IS_INT |
#define TSPEC_CASE_INT case 't': |
#else |
#define TSPEC_CASE_INT |
#endif |
#ifdef TSPEC_IS_LONG |
#define TSPEC_CASE_LONG case 't': |
#else |
#define TSPEC_CASE_LONG |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/qwrite.h |
---|
0,0 → 1,36 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Prototype for __qwrite() internal helper. |
* |
****************************************************************************/ |
#ifdef __NETWARE__ |
#define __qwrite( h, b, l ) write( h, (void *)b, l ) |
#else |
extern int __qwrite( int, const void *, unsigned ); |
#endif |
/programs/develop/open watcom/trunk/clib/h/riscstr.h |
---|
0,0 → 1,359 |
/**************************************************************************** |
* |
* 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: RISC oriented string functions designed to access memory |
* as aligned 32- or 64-bit words whenever possible. |
* |
****************************************************************************/ |
#ifndef _RISCSTR_H_INCLUDED |
#define _RISCSTR_H_INCLUDED |
/* |
* Determine if we're building RISC versions of string/memory routines. |
*/ |
#if defined(__AXP__) || defined(__PPC__) |
#define __RISCSTR__ |
#endif |
#ifdef __RISCSTR__ /* do nothing if not RISC target */ |
#include "variety.h" |
#include "widechar.h" |
#include <string.h> |
#include <wchar.h> |
#include "watcom.h" |
/* |
* Choose between 32- and 64-bit words. |
*/ |
#define USE_INT64 0 /* no 64-bit stuff for now */ |
#ifndef USE_INT64 |
#ifdef __AXP__ |
#define USE_INT64 1 |
#else |
#define USE_INT64 0 |
#endif |
#endif |
#if USE_INT64 |
#define INT __int64 |
#define UINT unsigned __int64 |
#else |
#define INT int |
#define UINT uint_32 |
#endif |
#define BYTES_PER_WORD ( sizeof( UINT ) ) |
#define INT_SIZE ( BYTES_PER_WORD * 8 ) |
#define CHARS_PER_WORD ( BYTES_PER_WORD / CHARSIZE ) |
#define MOD_BYTES_PER_WORD(__n) ( (__n) & (BYTES_PER_WORD-1) ) |
/* |
* Macros to mask off a single character. |
*/ |
#if USE_INT64 |
#define BYTE1 ( _riscdata->byteMasks[0].val ) |
#define BYTE2 ( _riscdata->byteMasks[1].val ) |
#define BYTE3 ( _riscdata->byteMasks[2].val ) |
#define BYTE4 ( _riscdata->byteMasks[3].val ) |
#define BYTE5 ( _riscdata->byteMasks[4].val ) |
#define BYTE6 ( _riscdata->byteMasks[5].val ) |
#define BYTE7 ( _riscdata->byteMasks[6].val ) |
#define BYTE8 ( _riscdata->byteMasks[7].val ) |
#else |
#define BYTE1 ( 0x000000FF ) |
#define BYTE2 ( 0x0000FF00 ) |
#define BYTE3 ( 0x00FF0000 ) |
#define BYTE4 ( 0xFF000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1MASK ( BYTE1 | BYTE2 ) |
#define CHR2MASK ( BYTE3 | BYTE4 ) |
#else |
#define CHR1MASK ( BYTE1 ) |
#define CHR2MASK ( BYTE2 ) |
#define CHR3MASK ( BYTE3 ) |
#define CHR4MASK ( BYTE4 ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1(__w) ( (__w) & CHR1MASK ) |
#define CHR2(__w) ( (__w) & CHR2MASK ) |
#else |
#define CHR1(__w) ( (__w) & BYTE1 ) |
#define CHR2(__w) ( (__w) & BYTE2 ) |
#define CHR3(__w) ( (__w) & BYTE3 ) |
#define CHR4(__w) ( (__w) & BYTE4 ) |
#if USE_INT64 |
#define CHR5(__w) ( (__w) & BYTE5 ) |
#define CHR6(__w) ( (__w) & BYTE6 ) |
#define CHR7(__w) ( (__w) & BYTE7 ) |
#define CHR8(__w) ( (__w) & BYTE8 ) |
#endif |
#endif |
/* |
* Macros for extracting the first characters in a word. |
*/ |
#if USE_INT64 |
#define FRONT_BYTES(__n) ( _riscdata->frontCharsMasks[(__n)].val ) |
#define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES_riscdata[(__o)].val ) |
#else |
// extern UINT __FRONT_BYTES[]; |
// #define FRONT_BYTES __FRONT_BYTES |
#define FRONT_BYTES ( _riscdata->frontCharsMasks ) |
#define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES[(__o)] ) |
#endif |
/* |
* Macros for ignoring the first characters in a word. |
*/ |
#if USE_INT64 |
#define SKIP_CHRS_MASKS(__n) ( _riscdata->skipCharsMasks[(__n)].val ) |
#define SKIP_CHRS(__w,__o) ( (__w) & SKIP_CHRS_MASKS(__o) ) |
#else |
// extern UINT __SKIP_CHRS_MASKS[]; |
// #define SKIP_CHRS_MASKS __SKIP_CHRS_MASKS |
#define SKIP_CHRS_MASKS(__n) ( _riscdata->skipCharsMasks[(__n)] ) |
#define SKIP_CHRS(__w,__o) ( (__w) & SKIP_CHRS_MASKS(__o) ) |
#endif |
/* |
* Macros for checking if a word contains a null byte. |
*/ |
#if USE_INT64 |
#define SUB_M ( _riscdata->_01Mask.val ) |
#define NIL_M ( _riscdata->_80Mask.val ) |
#define SUB_MASK(__n) ( _riscdata->subMasks[(__n)].val ) |
#else |
#ifdef __WIDECHAR__ |
#define SUB_M ( 0x00010001 ) |
#define NIL_M ( 0x80008000 ) |
#else |
#define SUB_M ( 0x01010101 ) |
#define NIL_M ( 0x80808080 ) |
#endif |
// extern UINT __SubMask[]; |
// #define SUB_MASK __SubMask |
#define SUB_MASK(__n) ( _riscdata->subMasks[(__n)] ) |
#endif |
#define GOT_NIL(__w) ( ( (~(__w)) & ((__w) - SUB_M) ) & NIL_M ) |
#ifdef __WIDECHAR__ |
#define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK((__o)/CHARSIZE)) ) & NIL_M ) |
#else |
#define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK(__o)) ) & NIL_M ) |
#endif |
/* |
* Some handy pointer manipulation macros. |
*/ |
#define ROUND(__p) ( (UINT*) ( (UINT)(__p) & (-sizeof(UINT)) ) ) |
#define OFFSET(__p) ( ((unsigned int)(__p)) & (sizeof(UINT)-1) ) |
/* |
* Macros for uppercase and lowercase stuff. |
*/ |
#ifdef __WIDECHAR__ |
#define CHR1_A ( 0x00000041 ) |
#define CHR2_A ( 0x00410000 ) |
#define CHR1_Z ( 0x0000005A ) |
#define CHR2_Z ( 0x005A0000 ) |
#define CHR1_A2a(s) ( s | 0x00000020 ) |
#define CHR2_A2a(s) ( s | 0x00200000 ) |
#else |
#define CHR1_A ( 0x00000041 ) |
#define CHR2_A ( 0x00004100 ) |
#define CHR3_A ( 0x00410000 ) |
#define CHR4_A ( 0x41000000 ) |
#define CHR1_Z ( 0x0000005A ) |
#define CHR2_Z ( 0x00005A00 ) |
#define CHR3_Z ( 0x005A0000 ) |
#define CHR4_Z ( 0x5A000000 ) |
#define CHR1_A2a(s) ( s | 0x00000020 ) |
#define CHR2_A2a(s) ( s | 0x00002000 ) |
#define CHR3_A2a(s) ( s | 0x00200000 ) |
#define CHR4_A2a(s) ( s | 0x20000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s ) |
#define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s ) |
#else |
#define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s ) |
#define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s ) |
#define TO_LOW_CHR3(s) ( ( (s>=CHR3_A) && (s<=CHR3_Z) ) ? CHR3_A2a(s) : s ) |
#define TO_LOW_CHR4(s) ( ( (s>=CHR4_A) && (s<=CHR4_Z) ) ? CHR4_A2a(s) : s ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1_a ( 0x00000061 ) |
#define CHR2_a ( 0x00610000 ) |
#define CHR1_z ( 0x0000007A ) |
#define CHR2_z ( 0x007A0000 ) |
#define CHR1_a2A(s) ( s & 0x000000DF ) |
#define CHR2_a2A(s) ( s & 0x00DF0000 ) |
#else |
#define CHR1_a ( 0x00000061 ) |
#define CHR2_a ( 0x00006100 ) |
#define CHR3_a ( 0x00610000 ) |
#define CHR4_a ( 0x61000000 ) |
#define CHR1_z ( 0x0000007A ) |
#define CHR2_z ( 0x00007A00 ) |
#define CHR3_z ( 0x007A0000 ) |
#define CHR4_z ( 0x7A000000 ) |
#define CHR1_a2A(s) ( s & 0x000000DF ) |
#define CHR2_a2A(s) ( s & 0x0000DF00 ) |
#define CHR3_a2A(s) ( s & 0x00DF0000 ) |
#define CHR4_a2A(s) ( s & 0xDF000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s ) |
#define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s ) |
#else |
#define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s ) |
#define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s ) |
#define TO_UPR_CHR3(s) ( ( (s>=CHR3_a) && (s<=CHR3_z) ) ? CHR3_a2A(s) : s ) |
#define TO_UPR_CHR4(s) ( ( (s>=CHR4_a) && (s<=CHR4_z) ) ? CHR4_a2A(s) : s ) |
#endif |
/* |
* Tweak characters within a word. |
*/ |
#ifdef __WIDECHAR__ |
#define REVERSE_CHARS(__w) ( (CHR1(__w)<<16) | (CHR2(__w)>>16) ) |
#else |
#define REVERSE_CHARS(__w) ( (CHR1(__w)<<24) | (CHR2(__w)<<8) | \ |
(CHR3(__w)>>8) | (CHR4(__w)>>24) ) |
#endif |
#define SWAP_BYTES(__w) ( (((__w)&BYTE1)<<8) | (((__w)&BYTE2)>>8) | \ |
(((__w)&BYTE3)<<8) | (((__w)&BYTE4)>>8) ) |
/* |
* Data used by the RISC string functions. |
*/ |
struct __F_NAME(__RISC_StrData,__wRISC_StrData) { |
#if USE_INT64 |
unsigned_64 byteMasks[8]; |
unsigned_64 frontCharsMasks[8]; |
unsigned_64 skipCharsMasks[8]; |
unsigned_64 _01Mask; |
unsigned_64 _80Mask; |
unsigned_64 subMasks[8]; |
#else |
#ifdef __WIDECHAR__ |
uint_32 frontCharsMasks[2]; |
uint_32 skipCharsMasks[2]; |
uint_32 subMasks[2]; |
#else |
uint_32 frontCharsMasks[4]; |
uint_32 skipCharsMasks[4]; |
uint_32 subMasks[4]; |
#endif |
#endif |
}; |
#ifdef __WIDECHAR__ |
extern struct __wRISC_StrData __wRISC_StringData; |
#define RISC_DATA_LOCALREF struct __wRISC_StrData *_riscdata = &__wRISC_StringData |
#else |
extern struct __RISC_StrData __RISC_StringData; |
#define RISC_DATA_LOCALREF struct __RISC_StrData *_riscdata = &__RISC_StringData |
#endif |
/* |
* Prototype functions called by the RISC-oriented string functions. |
*/ |
_WCRTLINK extern wchar_t * __simple_wcschr( const wchar_t *str, wint_t ch ); |
_WCRTLINK extern int __simple_wcscmp( const wchar_t *s1, const wchar_t *s2 ); |
_WCRTLINK extern wchar_t * __simple_wcscpy( wchar_t *dest, const wchar_t *src ); |
_WCRTLINK extern int __simple__wcsicmp( const wchar_t *s1, const wchar_t *s2 ); |
_WCRTLINK extern size_t __simple_wcslen( const wchar_t *str ); |
_WCRTLINK extern wchar_t * __simple__wcslwr( wchar_t *str ); |
_WCRTLINK extern int __simple_wcsncmp( const wchar_t *s1, const wchar_t *s2, size_t n ); |
_WCRTLINK extern wchar_t * __simple_wcsncpy( wchar_t *dest, const wchar_t *src, size_t n ); |
_WCRTLINK extern int __simple__wcsnicmp( const wchar_t *s1, const wchar_t *s2, size_t n ); |
_WCRTLINK extern wchar_t * __simple__wcsnset( wchar_t *str, int ch, size_t n ); |
_WCRTLINK extern wchar_t * __simple_wcsrchr( const wchar_t *str, wint_t ch ); |
_WCRTLINK extern wchar_t * __simple__wcsset( wchar_t *str, wchar_t ch ); |
_WCRTLINK extern wchar_t * __simple__wcsupr( wchar_t *str ); |
#endif /* #ifdef __RISCSTR__ */ |
#endif |
/programs/develop/open watcom/trunk/clib/h/rtcheck.h |
---|
0,0 → 1,63 |
/**************************************************************************** |
* |
* 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: Perform runtime file handle checks. |
* |
****************************************************************************/ |
#ifndef _RTCHECK_H_INCLUDED |
#define _RTCHECK_H_INCLUDED |
#include "variety.h" |
#include <errno.h> |
#include "seterrno.h" |
/*********** |
#if ( defined(__NT__) || defined(__RUNTIME_HANDLE_CHECKS__) ) \ |
&& ( !defined(__NETWARE__) && !defined(__UNIX__) \ |
&& !defined(__OSI__) ) |
extern unsigned __NFiles; |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
__set_errno( EBADF ); \ |
return( __r ); \ |
} |
#else |
#define __handle_check( __h, __r ) |
#endif |
**************/ |
#define __handle_check( __h, __r ) |
#endif |
/programs/develop/open watcom/trunk/clib/h/rtdata.h |
---|
0,0 → 1,211 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Internal CLIB structures and variables. |
* |
****************************************************************************/ |
#ifndef _RTDATA_H_INCLUDED |
#define _RTDATA_H_INCLUDED |
#include "variety.h" |
#include <stdio.h> |
#include "errorno.h" |
/* DOS based platforms have stdaux/stdprn in addition to stdin/out/err */ |
#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OSI__) |
#define NUM_STD_STREAMS 5 |
#else |
#define NUM_STD_STREAMS 3 |
#endif |
#if defined(__NT__) || defined(__OS2__) |
struct __pipe_info { |
int isPipe; /* non-zero if it's a pipe */ |
int pid; /* PID of spawned process */ |
}; |
#endif |
typedef struct __stream_link { |
struct __stream_link * next; |
struct __iobuf * stream; |
unsigned char * _base; /* location of buffer */ |
int _orientation; /* wide/byte/not oriented */ |
int _extflags; /* extended flags */ |
unsigned char _tmpfchar; /* tmpfile number */ |
unsigned char _filler[sizeof(int)-1];/* explicit padding */ |
#if defined(__NT__) || defined(__OS2__) |
struct __pipe_info pipeInfo; /* pipe-related fields */ |
#endif |
} __stream_link; |
typedef void _WCI86FAR FPEhandler( int ); |
#define _FP_BASE(__fp) ((__fp)->_link->_base) |
#ifndef __NETWARE__ |
#define _FP_ORIENTATION(__fp) ((__fp)->_link->_orientation) |
#define _FP_EXTFLAGS(__fp) ((__fp)->_link->_extflags) |
#endif |
#define _FP_TMPFCHAR(__fp) ((__fp)->_link->_tmpfchar) |
#ifndef __NETWARE__ |
#define _FP_PIPEDATA(__fp) ((__fp)->_link->pipeInfo) |
#endif |
extern __stream_link *__OpenStreams; |
extern __stream_link *__ClosedStreams; |
extern char * _WCNEAR __env_mask; /* ptr to char array of flags */ |
extern FPEhandler *__FPE_handler; |
extern void (*__FPE_handler_exit)( void ); |
#if !defined(__NETWARE__) |
extern int _cbyte; |
extern int _cbyte2; |
extern int _child; |
extern int __umaskval; |
extern unsigned _curbrk; |
extern int _commode; |
#endif |
#if !defined (_NETWARE_LIBC) |
extern unsigned _STACKTOP; |
#endif |
#if !defined(__QNX__) && !defined(__LINUX__) |
extern void (*__Save8087)();/* Ptr to FP state save rtn (spawn) */ |
extern void (*__Rest8087)();/* Ptr to FP state restore rtn (spawn) */ |
#endif |
extern unsigned short _8087cw; /* control word initializer */ |
extern unsigned char _no87; /* NO87 environment var defined */ |
extern unsigned char _8087; /* type of 8087/emulator present */ |
extern unsigned char _real87; /* 8087 coprocessor hardware present */ |
#if defined(_M_IX86) |
#pragma aux _8087cw "_*"; |
#pragma aux _no87 "_*"; |
#pragma aux _8087 "_*"; |
#pragma aux _real87 "_*"; |
#endif |
#if !defined(__SW_BM) |
extern unsigned _STACKLOW; |
#endif |
#define _RWD_ostream __OpenStreams |
#define _RWD_cstream __ClosedStreams |
#define _RWD_iob __iob |
#if !defined(__NETWARE__) |
#define _RWD_threadid _threadid |
#endif |
#define _RWD_environ environ |
#define _RWD_wenviron _wenviron |
#define _RWD_env_mask __env_mask |
#define _RWD_abort __abort |
#define _RWD_sigtab __SIGNALTABLE |
#define _RWD_FPE_handler_exit __FPE_handler_exit |
#define _RWD_FPE_handler __FPE_handler |
#define _RWD_fmode _fmode |
#if !defined(__NETWARE__) |
#define _RWD_umaskval __umaskval |
#define _RWD_cbyte _cbyte |
#define _RWD_cbyte2 _cbyte2 |
#define _RWD_child _child |
#define _RWD_amblksiz _amblksiz |
#define _RWD_curbrk _curbrk |
#define _RWD_dynend _dynend |
#define _RWD_psp _psp |
#endif |
#if !defined (_NETWARE_LIBC) |
#define _RWD_stacktop _STACKTOP |
#endif |
#if !defined(__QNX__) && !defined(__LINUX__) |
#define _RWD_Save8087 __Save8087 |
#define _RWD_Rest8087 __Rest8087 |
#endif |
#define _RWD_8087cw _8087cw |
#define _RWD_no87 _no87 |
#define _RWD_8087 _8087 |
#define _RWD_real87 _real87 |
#if !defined(__NETWARE__) |
#define _RWD_HShift _HShift |
#define _RWD_osmajor _osmajor |
#define _RWD_osminor _osminor |
#define _RWD_osmode _osmode |
#if defined(__NT__) |
#define _RWD_osbuild _osbuild |
#define _RWD_osver _osver |
#define _RWD_winmajor _winmajor |
#define _RWD_winminor _winminor |
#define _RWD_winver _winver |
#endif |
#define _RWD_doserrno _DOSERRNO |
#endif |
#define _RWD_tmpfnext __tmpfnext |
#if !defined(_RWD_errno) |
#define _RWD_errno _ERRNO |
#endif |
#define _RWD_nexttok _NEXTTOK |
#define _RWD_nextftok _NEXTFTOK |
#define _RWD_nextmbtok _NEXTMBTOK |
#define _RWD_nextmbftok _NEXTMBFTOK |
#define _RWD_nextwtok _NEXTWTOK |
#define _RWD_tzname tzname |
#define _RWD_timezone timezone |
#define _RWD_daylight daylight |
#define _RWD_dst_adjust __dst_adjust |
#define _RWD_start_dst __start_dst |
#define _RWD_end_dst __end_dst |
#define _RWD_asctime _RESULT |
#ifdef __SW_BM |
#define _RWD_cvtbuf __THREADDATAPTR->__cvt_buffer |
#else |
#define _RWD_cvtbuf cvt_buffer |
#endif |
#if defined(__NETWARE__) |
#define _RWD_ioexit __ioexit |
#define _RWD_tmpnambuf (__THREADDATAPTR->__tmpnambuf) |
#define _RWD_randnextinit (__THREADDATAPTR->__randnextinit) |
#else |
#define _RWD_tmpnambuf _tmpname |
#define _RWD_randnextinit THREAD_PTR.__randnextinit |
#endif |
#define _RWD_stacklow _STACKLOW |
#define _RWD_randnext _RANDNEXT |
#define _RWD_ThreadData _ThreadData |
#define _RWD_StaticInitSema _StaticInitSema |
#define _RWD_PureErrorFlag _PureErrorFlag |
#define _RWD_UndefVfunFlag _UndefVfunFlag |
#define _RWD_ModuleInit _ModuleInit |
/* |
For the sake of efficiency, tell the compiler |
that the __exit... routines never return. |
*/ |
_WCRTLINK extern void __exit( unsigned ); |
#if defined(_M_IX86) |
#pragma aux __exit aborts; |
#endif |
extern void (*__abort)( void ); // Defined in abort.c |
extern void __terminate( void ); // Defined in abort.c |
#endif // _RTDATA_H_INCLUDED |
/programs/develop/open watcom/trunk/clib/h/rtinit.h |
---|
0,0 → 1,131 |
/**************************************************************************** |
* |
* 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: Structures for run-time initialization/finalization. |
* |
****************************************************************************/ |
#ifndef __RTINIT_H__ |
#define __RTINIT_H__ |
#include "langenvd.h" |
#if defined( __PPC__ ) |
#define __TGT_SYS __TGT_SYS_AXP_PPC |
typedef unsigned __type_rtp; |
typedef unsigned __type_pad; |
typedef void( *__type_rtn ) ( void ); |
#elif defined( __AXP__ ) |
#define __TGT_SYS __TGT_SYS_AXP_NT |
typedef unsigned __type_rtp; |
typedef unsigned __type_pad; |
typedef void( *__type_rtn ) ( void ); |
#elif defined( __MIPS__ ) |
#define __TGT_SYS __TGT_SYS_MIPS |
typedef unsigned __type_rtp; |
typedef unsigned __type_pad; |
typedef void( *__type_rtn ) ( void ); |
#else |
#define __TGT_SYS __TGT_SYS_X86 |
typedef unsigned char __type_rtp; |
typedef unsigned short __type_pad; |
#if defined( __386__ ) |
typedef void __near( *__type_rtn ) ( void ); |
#else |
typedef void( *__type_rtn ) ( void ); |
#endif |
#endif |
#include "langenv.h" |
#if defined( __MEDIUM__ ) || defined( __LARGE__ ) || defined( __HUGE__ ) |
#define __LARGE_CODE__ |
#endif |
// initialization progresses from highest priority to lowest |
// finalization progresses from lowest to highest |
#pragma pack( 1 ) |
struct rt_init // structure placed in XI/YI segment |
{ |
__type_rtp rtn_type; // - near=0/far=1 routine indication |
// also used when walking table to flag |
// completed entries |
__type_rtp priority; // - priority (0-highest 255-lowest) |
__type_rtn rtn; // - routine |
#if !( defined( __LARGE_CODE__ ) || defined( __386__ ) ) || defined( COMP_CFG_COFF ) |
__type_pad padding; // - padding, when small code ptr |
// or when risc cpu |
#endif |
}; |
#pragma pack() |
#if defined( M_I86 ) |
#if defined( __LARGE_CODE__ ) /* segmented large code models */ |
#define YIXI( seg, label, routine, priority ) \ |
struct rt_init __based( __segname( seg ) ) label = \ |
{ 1, priority, routine }; |
#else /* other segmented models */ |
#define YIXI( seg, label, routine, priority ) \ |
struct rt_init __based( __segname( seg ) ) label = \ |
{ 0, priority, routine, 0 }; |
#endif |
#else /* non-segmented architectures */ |
#define YIXI( seg, label, routine, priority ) \ |
struct rt_init __based( __segname( seg ) ) label = \ |
{ 0, priority, routine }; |
#endif |
/* |
Use these when you want a global label for the XI/YI structure |
*/ |
#define XI( label, routine, priority ) YIXI( TS_SEG_XI, label, routine, priority ) |
#define YI( label, routine, priority ) YIXI( TS_SEG_YI, label, routine, priority ) |
/* |
Use these when you don't care about the label on the XI/YI structure |
*/ |
#define __ANON( x ) __anon ## x |
#define ANON( x ) __ANON( x ) |
#define AXI( routine, priority ) static XI( ANON( __LINE__ ), routine, priority ) |
#define AYI( routine, priority ) static YI( ANON( __LINE__ ), routine, priority ) |
enum { |
INIT_PRIORITY_THREAD = 1, // priority for thread data init |
INIT_PRIORITY_FPU = 2, // priority for FPU/EMU init |
INIT_PRIORITY_RUNTIME = 10, // priority for run/time initialization |
INIT_PRIORITY_IOSTREAM = 20, // priority for IOSTREAM |
INIT_PRIORITY_LIBRARY = 32, // default library-initialization priority |
INIT_PRIORITY_PROGRAM = 64, // default program-initialization priority |
FINI_PRIORITY_DTOR = 40, // priority for module DTOR |
DTOR_PRIORITY = 40, // priority for module DTOR |
FINI_PRIORITY_EXIT = 16 // when exit() is called, functions between |
// 255 and this are called, the rest of the |
// fini routines are called from __exit(). |
}; |
/* have to turn off, or we get unref'd warnings for AXI & AYI stuff */ |
#pragma off( unreferenced ) |
#endif |
/programs/develop/open watcom/trunk/clib/h/scanf.h |
---|
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: Format specification descriptor for scanf family. |
* |
****************************************************************************/ |
#ifndef _SCANF_H_INCLUDED |
#define _SCANF_H_INCLUDED |
#include "variety.h" |
#include "widechar.h" |
#include <stdarg.h> |
typedef struct { |
int (*cget_rtn)(); /* character get rtn */ |
void (*uncget_rtn)(); /* unget a character rtn */ |
CHAR_TYPE *ptr; /* file or string pointer */ |
int width; /* conversion field width */ |
unsigned assign : 1; /* assignment flag for current argument */ |
unsigned eoinp : 1; /* end of input reached */ |
unsigned far_ptr : 1; /* F - far pointer */ |
unsigned near_ptr : 1; /* N - near pointer */ |
unsigned char_var : 1; /* hh - char variable */ |
unsigned short_var : 1; /* h - short variable */ |
unsigned long_var : 1; /* l - long variable */ |
unsigned long_long_var : 1; /* ll - long long variable */ |
unsigned long_double_var: 1; /* L - long double variable */ |
unsigned p_format : 1; /* %p (pointer conversion) */ |
} SCNF_SPECS; |
#if defined(__HUGE__) |
#define PTR_SCNF_SPECS SCNF_SPECS _WCFAR * |
#else |
#define PTR_SCNF_SPECS SCNF_SPECS * |
#endif |
#if defined( __STDC_WANT_LIB_EXT1__ ) && __STDC_WANT_LIB_EXT1__ == 1 |
#if defined(__WIDECHAR__) |
extern int __wscnf_s( PTR_SCNF_SPECS, const CHAR_TYPE *, const char **msg, va_list ); |
#else |
extern int __scnf_s( PTR_SCNF_SPECS, const CHAR_TYPE *, const char **msg, va_list ); |
#endif |
#else |
#if defined(__WIDECHAR__) |
extern int __wscnf( PTR_SCNF_SPECS, const CHAR_TYPE *, va_list ); |
#else |
extern int __scnf( PTR_SCNF_SPECS, const CHAR_TYPE *, va_list ); |
#endif |
#endif |
//#pragma off(unreferenced); |
#endif |
/programs/develop/open watcom/trunk/clib/h/seterrno.h |
---|
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: errno related CLIB internal declarations. |
* |
****************************************************************************/ |
#ifndef _SETERNO_H_INCLUDED |
#define _SETERNO_H_INCLUDED |
#include "variety.h" |
// defined in _dos\c\dosret.c |
_WCRTLINK extern int __set_errno_dos( unsigned int ); |
#if defined(__NT__) |
_WCRTLINK extern int __set_errno_nt( void ); |
#endif |
// defined in startup\c\seterrno.c |
_WCRTLINK extern void __set_errno( unsigned int ); |
_WCRTLINK extern int __set_EINVAL( void ); |
_WCRTLINK extern void __set_EDOM( void ); |
_WCRTLINK extern void __set_ERANGE( void ); |
#if !defined(__UNIX__) |
_WCRTLINK extern void __set_doserrno( unsigned int ); |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/streamio.h |
---|
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: Prototypes for various streamio internal routines. |
* |
****************************************************************************/ |
extern FILE *__allocfp( int handle ); |
extern void __freefp( FILE * ); |
extern void __chktty( FILE *fp ); |
extern void __ioalloc( FILE * ); |
extern int __doclose( FILE *fp, int close_handle ); |
extern int __shutdown_stream( FILE *fp, int close_handle ); |
/programs/develop/open watcom/trunk/clib/h/struct.inc |
---|
0,0 → 1,220 |
;***************************************************************************** |
;* |
;* 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: Structured macros for MASM/WASM. |
;* |
;***************************************************************************** |
__label = 0 |
__depth = 0 |
__inner_loop = 0 |
_guess macro name |
__depth = __depth + 1 |
__label = __label + 1 |
_set __astk,%__depth,__label,<> |
__label = __label + 1 |
_set __estk,%__depth,__label,<> |
ifnb <name> |
name = __label |
endif |
endm |
_quif macro cc,name |
ifnb <name> |
_set __elbl,,name,<> |
_j cc,_l,%__elbl |
else |
_set __albl,,__astk,%__depth |
_j cc,_l,%__albl |
endif |
endm |
_quit macro name |
_quif ,name |
endm |
_admit macro |
_set __albl,,__astk,%__depth |
__label = __label + 1 |
_set __astk,%__depth,__label,<> |
_set __elbl,,__estk,%__depth |
_j ,_l,%__elbl |
_label _l,%__albl |
endm |
_endguess macro |
_set __albl,,__astk,%__depth |
_label _l,%__albl |
_set __elbl,,__estk,%__depth |
_label _l,%__elbl |
__depth = __depth - 1 |
endm |
_loop macro name |
_guess name |
_set __albl,,__astk,%__depth |
_label _m,%__albl |
_set __elbl,,__estk,%__depth |
_label _m,%__elbl |
_set __llbl,%__depth,%__inner_loop,<> |
_set __inner_loop,,%__depth,<> |
endm |
_loopif macro cc,name |
ifnb <name> |
_set __elbl,,name,<> |
_j cc,_m,%__elbl |
else |
_set __albl,,__astk,%__inner_loop |
_j cc,_m,%__albl |
endif |
endm |
_until macro cc |
_set __albl,,__astk,%__depth |
_jn cc,_m,%__albl |
_set __inner_loop,,__llbl,%__depth |
_endguess |
endm |
_endloop macro |
_set __albl,,__astk,%__depth |
_j ,_m,%__albl |
_set __inner_loop,,__llbl,%__depth |
_endguess |
endm |
_if macro cc |
_guess |
_set __albl,,__astk,%__depth |
_jn cc,_l,%__albl |
endm |
_else macro |
_admit |
endm |
_endif macro |
_endguess |
endm |
_set macro base1,ext1,base2,ext2 |
base1&ext1 = base2&ext2 |
endm |
_label macro base,ext |
base&ext: |
endm |
_j macro cc,base,ext |
j&cc base&ext |
endm |
_jn macro cc,base,ext |
jn&cc base&ext |
endm |
jnna macro label |
ja label |
endm |
jnnae macro label |
jae label |
endm |
jnnb macro label |
jb label |
endm |
jnnbe macro label |
jbe label |
endm |
jnnc macro label |
jc label |
endm |
jnne macro label |
je label |
endm |
jnng macro label |
jg label |
endm |
jnnge macro label |
jge label |
endm |
jnnl macro label |
jl label |
endm |
jnnle macro label |
jle label |
endm |
jnno macro label |
jo label |
endm |
jnnp macro label |
jp label |
endm |
jnns macro label |
js label |
endm |
jnnz macro label |
jz label |
endm |
jnpe macro label |
jpo label |
endm |
jnpo macro label |
jpe label |
endm |
j macro label |
jmp label |
endm |
jn macro label |
nop |
endm |
_shl macro reg,count |
add reg,reg |
endm |
_rcl macro reg,count |
adc reg,reg |
endm |
/programs/develop/open watcom/trunk/clib/h/tmpfname.h |
---|
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: Temporary file filename related definitions. |
* |
****************************************************************************/ |
#define _TMPFNAME_LENGTH 13 |
#define _TMP_INIT_CHAR 32 |
/programs/develop/open watcom/trunk/clib/h/variety.h |
---|
0,0 → 1,293 |
/**************************************************************************** |
* |
* 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: Configuration for clib builds. |
* |
****************************************************************************/ |
#ifndef _VARIETY_H_INCLUDED |
#define _VARIETY_H_INCLUDED |
// |
// Note: for the DLL versions of the runtime libraries, this file must be |
// included before any of the runtime header files. |
// |
#ifndef _COMDEF_H_INCLUDED |
#include <_comdef.h> |
#endif |
// specialized data reference macro |
#define _HUGEDATA _WCDATA |
// memory model macros |
#if defined(__SMALL__) |
#define __SMALL_DATA__ |
#define __SMALL_CODE__ |
#elif defined(__FLAT__) |
#define __SMALL_DATA__ |
#define __SMALL_CODE__ |
#elif defined(__MEDIUM__) |
#define __SMALL_DATA__ |
#define __BIG_CODE__ |
#elif defined(__COMPACT__) |
#define __BIG_DATA__ |
#define __SMALL_CODE__ |
#elif defined(__LARGE__) |
#define __BIG_DATA__ |
#define __BIG_CODE__ |
#elif defined(__HUGE__) |
#define __BIG_DATA__ |
#define __BIG_CODE__ |
#elif defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) |
// these effectively use near data references |
#define __SMALL_DATA__ |
#define __SMALL_CODE__ |
#else |
#error unable to configure memory model |
#endif |
// operating system and processor macros |
#if defined(__GENERIC__) |
#if defined(__386__) |
#define __PROTECT_MODE__ |
#define __GENERIC_386__ |
#elif defined(M_I86) |
#define __REAL_MODE__ |
#define __GENERIC_086__ |
#else |
#error unrecognized processor for GENERIC |
#endif |
#elif defined(__OS2__) |
#if defined(M_I86) |
#define __REAL_MODE__ |
#define __OS2_286__ |
#elif defined(__386__) |
#define __PROTECT_MODE__ |
#define __OS2_386__ |
#define __WARP__ |
#elif defined(__PPC__) |
#define __PROTECT_MODE__ |
#define __OS2_PPC__ |
#define __WARP__ |
#else |
#error unrecognized processor for OS2 |
#endif |
#elif defined(__NT__) |
#if !defined(WIN32_LEAN_AND_MEAN) && !defined(WIN32_NICE_AND_FAT) |
#define WIN32_LEAN_AND_MEAN |
#endif |
#define __PROTECT_MODE__ |
#if defined(__386__) |
#define __NT_386__ |
#elif defined(__AXP__) |
#define __NT_AXP__ |
#elif defined(__PPC__) |
#define __NT_PPC__ |
#else |
#error unrecognized processor for NT |
#endif |
#elif defined(__WINDOWS__) || defined(__WINDOWS_386__) |
#define __PROTECT_MODE__ |
#if defined(__386__) |
#define __WINDOWS__ |
#elif defined(M_I86) |
#define __WINDOWS_286__ |
#else |
#error unrecognized processor for WINDOWS |
#endif |
#elif defined(__DOS__) |
#if defined(__386__) |
#define __PROTECT_MODE__ |
#define __DOS_386__ |
#elif defined(M_I86) |
#define __REAL_MODE__ |
#define __DOS_086__ |
#else |
#error unrecognized processor for DOS |
#endif |
#elif defined(__OSI__) |
#if defined(__386__) |
#define __PROTECT_MODE__ |
#define __OSI_386__ |
#else |
#error unrecognized processor for OSI |
#endif |
#elif defined(__QNX__) |
#define __PROTECT_MODE__ |
#define __UNIX__ |
#if defined(__386__) |
#define __QNX_386__ |
#elif defined(M_I86) |
#define __QNX_286__ |
#else |
#error unrecognized processor for QNX |
#endif |
#elif defined(__LINUX__) |
#define __PROTECT_MODE__ |
#define __UNIX__ |
#if defined(__386__) |
#define __LINUX_386__ |
#elif defined(__PPC__) |
#define __LINUX_PPC__ |
#elif defined(__MIPS__) |
#define __LINUX_MIPS__ |
#else |
#error unrecognized processor for Linux |
#endif |
#elif defined(__NETWARE__) |
#define __PROTECT_MODE__ |
#if defined(__386__) |
#define __NETWARE_386__ |
#else |
#error unrecognized processor for NETWARE |
#endif |
#else |
#error unable to configure operating system and processor |
#endif |
// handle building dll's with appropriate linkage |
#if !defined(__SW_BR) && (defined(__WARP__) || defined(__NT__)) |
#if defined(__MAKE_DLL_CLIB) |
#undef _WCRTLINK |
#undef _WCIRTLINK |
#undef _WCRTLINKD |
#undef _WMRTLINK |
#undef _WMIRTLINK |
#undef _WMRTLINKD |
#undef _WPRTLINK |
#undef _WPIRTLINK |
#undef _WPRTLINKD |
#if defined(__NT__) |
#define _WCRTLINK __declspec(dllexport) _WRTLCALL |
#define _WCIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WCRTLINKD __declspec(dllexport) |
#define _WMRTLINK __declspec(dllimport) _WRTLCALL |
#define _WMIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WMRTLINKD __declspec(dllimport) |
#define _WPRTLINK __declspec(dllimport) _WRTLCALL |
#define _WPIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WPRTLINKD __declspec(dllimport) |
#elif defined(__WARP__) |
#define _WCRTLINK __declspec(dllexport) _WRTLCALL |
#define _WCIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WCRTLINKD __declspec(dllexport) |
#define _WMRTLINK _WRTLCALL |
#define _WMIRTLINK _WRTLCALL |
#define _WMRTLINKD |
#define _WPRTLINK _WRTLCALL |
#define _WPIRTLINK _WRTLCALL |
#define _WPRTLINKD |
#endif |
#elif defined(__MAKE_DLL_MATHLIB) |
#define _RTDLL |
#undef _WCRTLINK |
#undef _WCIRTLINK |
#undef _WCRTLINKD |
#undef _WMRTLINK |
#undef _WMIRTLINK |
#undef _WMRTLINKD |
#undef _WPRTLINK |
#undef _WPIRTLINK |
#undef _WPRTLINKD |
#if defined(__NT__) |
#define _WCRTLINK __declspec(dllimport) _WRTLCALL |
#define _WCIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WCRTLINKD __declspec(dllimport) |
#define _WMRTLINK __declspec(dllexport) _WRTLCALL |
#define _WMIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WMRTLINKD __declspec(dllexport) |
#define _WPRTLINK __declspec(dllimport) _WRTLCALL |
#define _WPIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WPRTLINKD __declspec(dllimport) |
#elif defined(__WARP__) |
#define _WCRTLINK _WRTLCALL |
#define _WCIRTLINK _WRTLCALL |
#define _WCRTLINKD |
#define _WMRTLINK __declspec(dllexport) _WRTLCALL |
#define _WMIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WMRTLINKD __declspec(dllexport) |
#define _WPRTLINK _WRTLCALL |
#define _WPIRTLINK _WRTLCALL |
#define _WPRTLINKD |
#endif |
#elif defined(__MAKE_DLL_CPPLIB) |
#define _RTDLL |
#undef _WCRTLINK |
#undef _WCIRTLINK |
#undef _WCRTLINKD |
#undef _WMRTLINK |
#undef _WMIRTLINK |
#undef _WMRTLINKD |
#undef _WPRTLINK |
#undef _WPIRTLINK |
#undef _WPRTLINKD |
#if defined(__NT__) |
#define _WCRTLINK __declspec(dllimport) _WRTLCALL |
#define _WCIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WCRTLINKD __declspec(dllimport) |
#define _WMRTLINK __declspec(dllimport) _WRTLCALL |
#define _WMIRTLINK __declspec(dllimport) _WRTLCALL |
#define _WMRTLINKD __declspec(dllimport) |
#define _WPRTLINK __declspec(dllexport) _WRTLCALL |
#define _WPIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WPRTLINKD __declspec(dllexport) |
#elif defined(__WARP__) |
#define _WCRTLINK _WRTLCALL |
#define _WCIRTLINK _WRTLCALL |
#define _WCRTLINKD |
#define _WMRTLINK _WRTLCALL |
#define _WMIRTLINK _WRTLCALL |
#define _WMRTLINKD |
#define _WPRTLINK __declspec(dllexport) _WRTLCALL |
#define _WPIRTLINK __declspec(dllexport) _WRTLCALL |
#define _WPRTLINKD __declspec(dllexport) |
#endif |
#endif |
#endif |
#define __ptr_check( p, a ) |
#define __null_check( p, a ) |
#define __stream_check( s, a ) |
#define __ROUND_UP_SIZE( __x, __amt ) (((__x)+((__amt)-1))&(~((__amt)-1))) |
/// |
/// This doesn't work for far pointer's |
/// |
///#define __ROUND_UP_PTR( __x, __amt ) ((void *)__ROUND_UP_SIZE((unsigned)(__x),__amt)) |
#if defined(M_I86) |
#define __ALIGN_SIZE( __x ) __ROUND_UP_SIZE( __x, 2 ) |
// #define __ALIGN_PTR( __x ) __ROUND_UP_PTR( __x, 2 ) |
#elif defined(__386__) |
#define __ALIGN_SIZE( __x ) __ROUND_UP_SIZE( __x, 4 ) |
/// #define __ALIGN_PTR( __x ) __ROUND_UP_PTR( __x, 4 ) |
#else |
#define __ALIGN_SIZE( __x ) __ROUND_UP_SIZE( __x, 8 ) |
// #define __ALIGN_PTR( __x ) __ROUND_UP_PTR( __x, 8 ) |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/watcom.h |
---|
0,0 → 1,206 |
/**************************************************************************** |
* |
* 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: Common type definitions and macros widely used by Open |
* Watcom tools. |
* |
****************************************************************************/ |
#ifndef _WATCOM_H_INCLUDED_ |
#define _WATCOM_H_INCLUDED_ |
#include <errno.h> |
#ifndef __WATCOMC__ |
#include "clibext.h" |
#endif |
#if !defined(__sun__) && !defined(sun) && !defined(__sgi) && !defined(__hppa) && !defined(_AIX) && !defined(__alpha) && !defined(_TYPES_H_) && !defined(_SYS_TYPES_H) |
typedef unsigned uint; |
#endif |
typedef unsigned char uint_8; |
typedef unsigned short uint_16; |
#if defined (LONG_IS_64BITS) |
typedef unsigned int uint_32; |
#else |
typedef unsigned long uint_32; |
#endif |
typedef unsigned char unsigned_8; |
typedef unsigned short unsigned_16; |
#if defined (LONG_IS_64BITS) |
typedef unsigned int unsigned_32; |
#else |
typedef unsigned long unsigned_32; |
#endif |
typedef signed char int_8; |
typedef signed short int_16; |
#if defined (LONG_IS_64BITS) |
typedef signed int int_32; |
#else |
typedef signed long int_32; |
#endif |
typedef signed char signed_8; |
typedef signed short signed_16; |
#if defined (LONG_IS_64BITS) |
typedef signed int signed_32; |
#else |
typedef signed long signed_32; |
#endif |
typedef struct { |
union { |
unsigned_32 _32[2]; |
unsigned_16 _16[4]; |
unsigned_8 _8[8]; |
struct { |
#if defined( __BIG_ENDIAN__ ) |
unsigned v : 1; |
unsigned : 15; |
unsigned : 16; |
unsigned : 16; |
unsigned : 16; |
#else |
unsigned : 16; |
unsigned : 16; |
unsigned : 16; |
unsigned : 15; |
unsigned v : 1; |
#endif |
} sign; |
#if defined(__WATCOM_INT64__) || defined(__GNUC__) |
unsigned long long _64[1]; |
#endif |
} u; |
} unsigned_64; |
typedef unsigned_64 signed_64; |
/* Macros for low/high end access on little and big endian machines */ |
#if defined( __BIG_ENDIAN__ ) |
#define I64LO32 1 |
#define I64HI32 0 |
#define I64LO16 3 |
#define I64HI16 0 |
#define I64LO8 7 |
#define I64HI8 0 |
#else |
#define I64LO32 0 |
#define I64HI32 1 |
#define I64LO16 0 |
#define I64HI16 3 |
#define I64LO8 0 |
#define I64HI8 7 |
#endif |
/* Define _crtn for prototypes for external C routines called from C++. |
* Eg. extern _crtn void Foo(); |
*/ |
#if !defined( _crtn ) |
#if defined( __cplusplus ) |
#define _crtn "C" |
#else |
#define _crtn |
#endif |
#endif |
/* Macros for little/big endian conversion; These exist to simplify writing |
* code that handles both little and big endian data on either little or big |
* endian host platforms. Some of these macros could be implemented as inline |
* assembler where instructions to byte swap data in registers or read/write |
* memory access with byte swapping is available. |
* |
* NOTE: The SWAP_XX macros will swap data in place. If you only want to take a |
* a copy of the data and leave the original intact, then use the SWAPNC_XX |
* macros. |
*/ |
#define SWAPNC_16(w) (\ |
(((w) & 0x000000FFUL) << 8) |\ |
(((w) & 0x0000FF00UL) >> 8)\ |
) |
#define SWAPNC_32(w) (\ |
(((w) & 0x000000FFUL) << 24) |\ |
(((w) & 0x0000FF00UL) << 8) |\ |
(((w) & 0x00FF0000UL) >> 8) |\ |
(((w) & 0xFF000000UL) >> 24)\ |
) |
#define SWAPNC_64(w) (\ |
(((w) & 0x00000000000000FFULL) << 56) |\ |
(((w) & 0x000000000000FF00ULL) << 40) |\ |
(((w) & 0x0000000000FF0000ULL) << 24) |\ |
(((w) & 0x00000000FF000000ULL) << 8) |\ |
(((w) & 0x000000FF00000000ULL) >> 8) |\ |
(((w) & 0x0000FF0000000000ULL) >> 24) |\ |
(((w) & 0x00FF000000000000ULL) >> 40) |\ |
(((w) & 0xFF00000000000000ULL) >> 56)\ |
) |
#if defined( __BIG_ENDIAN__ ) |
/* Macros to get little endian data */ |
#define GET_LE_16(w) SWAPNC_16(w) |
#define GET_LE_32(w) SWAPNC_32(w) |
#define GET_LE_64(w) SWAPNC_64(w) |
/* Macros to get big endian data */ |
#define GET_BE_16(w) (w) |
#define GET_BE_32(w) (w) |
#define GET_BE_64(w) (w) |
/* Macros to convert little endian data in place */ |
#define CONV_LE_16(w) (w) = SWAPNC_16(w) |
#define CONV_LE_32(w) (w) = SWAPNC_32(w) |
#define CONV_LE_64(w) (w) = SWAPNC_64(w) |
/* Macros to convert big endian data in place */ |
#define CONV_BE_16(w) |
#define CONV_BE_32(w) |
#define CONV_BE_64(w) |
/* Macros to swap byte order */ |
#define SWAP_16 CONV_LE_16 |
#define SWAP_32 CONV_LE_32 |
#define SWAP_64 CONV_LE_64 |
#else |
/* Macros to get little endian data */ |
#define GET_LE_16(w) (w) |
#define GET_LE_32(w) (w) |
#define GET_LE_64(w) (w) |
/* Macros to get big endian data */ |
#define GET_BE_16(w) SWAPNC_16(w) |
#define GET_BE_32(w) SWAPNC_32(w) |
#define GET_BE_64(w) SWAPNC_64(w) |
/* Macros to convert little endian data in place */ |
#define CONV_LE_16(w) |
#define CONV_LE_32(w) |
#define CONV_LE_64(w) |
/* Macros to convert big endian data in place */ |
#define CONV_BE_16(w) (w) = SWAPNC_16(w) |
#define CONV_BE_32(w) (w) = SWAPNC_32(w) |
#define CONV_BE_64(w) (w) = SWAPNC_64(w) |
/* Macros to swap byte order */ |
#define SWAP_16 CONV_BE_16 |
#define SWAP_32 CONV_BE_32 |
#define SWAP_64 CONV_BE_64 |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/h/widechar.h |
---|
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: Macros for single source wide/narrow character code. |
* |
****************************************************************************/ |
#ifndef _WIDECHAR_H_INCLUDED |
#define _WIDECHAR_H_INCLUDED |
#include "variety.h" |
#include <stdlib.h> /* for wchar_t and _atouni */ |
/*** Define some handy macros ***/ |
#ifdef __WIDECHAR__ |
#define DIR_TYPE struct _wdirent |
#define CHAR_TYPE wchar_t |
#define UCHAR_TYPE wchar_t |
#define INTCHAR_TYPE wint_t |
#define INT_WC_TYPE wchar_t |
#define VOID_WC_TYPE wchar_t |
#define NULLCHAR 0 |
#define STRING(a) L##a |
#define _AToUni(p1,p2) _atouni(p1,p2) |
#define IS_ASCII(c) ( (c & 0xff00) == 0 ) |
#define TO_ASCII(c) ( c ) |
#define __F_NAME(n1,n2) n2 |
#define UNICODE |
#define _UNICODE |
#define __UNICODE__ |
#else |
#define DIR_TYPE struct dirent |
#define CHAR_TYPE char |
#define UCHAR_TYPE unsigned char |
#define INTCHAR_TYPE int |
#define INT_WC_TYPE int |
#define VOID_WC_TYPE void |
#define NULLCHAR '\0' |
#define STRING(a) a |
#define _AToUni(p1,p2) (p2) |
#define IS_ASCII(c) ( 1 ) |
#define TO_ASCII(c) ( (unsigned char)c ) |
#define __F_NAME(n1,n2) n1 |
#endif |
#define CHARSIZE (sizeof( CHAR_TYPE )) |
/* must be the larger of char and wchar_t */ |
#define MAX_CHAR_TYPE wchar_t |
#endif |
/programs/develop/open watcom/trunk/clib/h/xstring.h |
---|
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: Prototypes for direct 'calls' to inline functions. |
* |
****************************************************************************/ |
#ifndef _XSTRING_H_INCLUDED |
#include "variety.h" |
#include <string.h> |
#ifdef __cplusplus |
extern "C" { |
#endif |
#ifdef __INLINE_FUNCTIONS__ |
void *_inline_memchr( const void *__s, int __c, size_t __n ); |
int _inline_memcmp( const void *__s1, const void *__s2, size_t __n ); |
void *_inline_memcpy( void *__s1, const void *__s2, size_t __n ); |
void *_inline_memmove( void *__s1, const void *__s2, size_t __n ); |
void *_inline_memset( void *__s, int __c, size_t __n ); |
char *_inline_strcat( char *__s1, const char *__s2 ); |
char *_inline_strchr( const char *__s, int __c ); |
int _inline_strcmp( const char *__s1, const char *__s2 ); |
char *_inline_strcpy( char *__s1, const char *__s2 ); |
size_t _inline_strlen( const char *__s ); |
void _WCFAR *_inline__fmemchr( const void _WCFAR *__s, int __c, size_t __n ); |
void _WCFAR *_inline__fmemcpy( void _WCFAR *__s1, const void _WCFAR *__s2, size_t __n ); |
void _WCFAR *_inline__fmemset( void _WCFAR *__s, int __c, size_t __n ); |
int _inline__fmemcmp( const void _WCFAR *__s1, const void _WCFAR *__s2, size_t __n ); |
char _WCFAR *_inline__fstrcat( char _WCFAR *__s1, const char _WCFAR *__s2 ); |
char _WCFAR *_inline__fstrchr( const char _WCFAR *__s, int __c ); |
int _inline__fstrcmp( const char _WCFAR *__s1, const char _WCFAR *__s2 ); |
char _WCFAR *_inline__fstrcpy( char _WCFAR *__s1, const char _WCFAR *__s2 ); |
size_t _inline__fstrlen( const char _WCFAR *__s ); |
void _inline_movedata( unsigned __srcseg, unsigned __srcoff, |
unsigned __tgtseg, unsigned __tgtoff, unsigned __len ); |
#endif /* __INLINE_FUNCTIONS__ */ |
#define _XSTRING_H_INCLUDED |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/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 */ |
} |
} |
/programs/develop/sdk/trunk/sound/include/sound.h |
---|
0,0 → 1,84 |
#ifndef _SOUND_H_ |
#define _SOUND_H_ |
#ifdef __cplusplus |
extern "C" |
{ |
#endif |
#define SOUND_VERSION 5 |
#define PCM_ALL 0 |
#define PCM_STATIC 0x80000000 |
#define PCM_2_16_48 1 |
#define PCM_1_16_48 2 |
#define PCM_2_16_44 3 |
#define PCM_1_16_44 4 |
#define PCM_2_16_32 5 |
#define PCM_1_16_32 6 |
#define PCM_2_16_24 7 |
#define PCM_1_16_24 8 |
#define PCM_2_16_22 9 |
#define PCM_1_16_22 10 |
#define PCM_2_16_16 11 |
#define PCM_1_16_16 12 |
#define PCM_2_16_12 13 |
#define PCM_1_16_12 14 |
#define PCM_2_16_11 15 |
#define PCM_1_16_11 16 |
#define PCM_2_16_8 17 |
#define PCM_1_16_8 18 |
#define PCM_2_8_48 19 |
#define PCM_1_8_48 20 |
#define PCM_2_8_44 21 |
#define PCM_1_8_44 22 |
#define PCM_2_8_32 23 |
#define PCM_1_8_32 24 |
#define PCM_2_8_24 25 |
#define PCM_1_8_24 26 |
#define PCM_2_8_22 27 |
#define PCM_1_8_22 28 |
#define PCM_2_8_16 29 |
#define PCM_1_8_16 30 |
#define PCM_2_8_12 31 |
#define PCM_1_8_12 32 |
#define PCM_2_8_11 33 |
#define PCM_1_8_11 34 |
#define PCM_2_8_8 35 |
#define PCM_1_8_8 36 |
#define SRV_GETVERSION 0 |
#define SND_CREATE_BUFF 1 |
#define SND_DESTROY_BUFF 2 |
#define SND_SETFORMAT 3 |
#define SND_RESET 4 |
#define SND_SETPOS 5 |
#define SND_SETBUFF 6 |
#define SND_SETVOLUME 7 |
#define SND_GETVOLUME 8 |
#define SND_OUT 9 |
#define SND_PLAY 10 |
#define SND_STOP 11 |
typedef unsigned int SNDBUF; |
int _stdcall InitSound(); |
SNDBUF _stdcall CreateBuffer(unsigned int format,int size); |
int _stdcall DestroyBuffer(SNDBUF hBuff); |
int _stdcall SetBuffer(SNDBUF hBuff,void* buff, |
int offs, int size); |
int _stdcall WaveOut(SNDBUF hBuff,void *buff, int size); |
int _stdcall PlayBuffer(SNDBUF hBuff); |
int _stdcall StopBuffer(SNDBUF hBuff); |
int _stdcall GetMasterVol(int* vol); |
int _stdcall SetMasterVol(int vol); |
#ifdef __cplusplus |
extern "C" |
} |
#endif |
#endif //_SOUND_H_ |
/programs/develop/sdk/trunk/sound/src/init.asm |
---|
0,0 → 1,137 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
public _InitSound@0 |
public _CreateBuffer@8 |
public _DestroyBuffer@4 |
align 4 |
proc _InitSound@0 |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, 68 |
mov ebx, 16 |
mov ecx, szInfinity |
int 0x40 |
test eax, eax |
jz .fail |
mov [hSound], eax |
mov eax, 68 |
mov ebx, 16 |
mov ecx, szSound |
int 0x40 |
mov [hrdwSound], eax |
mov eax, [hSound] |
xor ebx, ebx |
mov [handle], eax |
mov [io_code], SRV_GETVERSION |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ebx |
mov [out_size], ebx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
.fail: |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _CreateBuffer@8 stdcall, format:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [format] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_CREATE_BUFF |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _DestroyBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_DESTROY_BUFF |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
section '.data' align 16 data readable writable |
szInfinity db 'INFINITY',0 |
szSound db 'SOUND',0 |
public hSound |
public hrdwSound |
align 4 |
hSound dd ? |
hrdwSound dd ? |
/programs/develop/sdk/trunk/sound/src/proc32.inc |
---|
0,0 → 1,268 |
; Macroinstructions for defining and calling procedures |
macro stdcall proc,[arg] ; directly call STDCALL procedure |
{ common |
if ~ arg eq |
reverse |
pushd arg |
common |
end if |
call proc } |
macro invoke proc,[arg] ; indirectly call STDCALL procedure |
{ common |
if ~ arg eq |
reverse |
pushd arg |
common |
end if |
call [proc] } |
macro ccall proc,[arg] ; directly call CDECL procedure |
{ common |
size@ccall = 0 |
if ~ arg eq |
reverse |
pushd arg |
size@ccall = size@ccall+4 |
common |
end if |
call proc |
if size@ccall |
add esp,size@ccall |
end if } |
macro cinvoke proc,[arg] ; indirectly call CDECL procedure |
{ common |
size@ccall = 0 |
if ~ arg eq |
reverse |
pushd arg |
size@ccall = size@ccall+4 |
common |
end if |
call [proc] |
if size@ccall |
add esp,size@ccall |
end if } |
macro proc [args] ; define procedure |
{ common |
match name params, args> |
\{ define@proc name,<params \} } |
prologue@proc equ prologuedef |
macro prologuedef procname,flag,parmbytes,localbytes,reglist |
{ if parmbytes | localbytes |
push ebp |
mov ebp,esp |
if localbytes |
sub esp,localbytes |
end if |
end if |
irps reg, reglist \{ push reg \} } |
epilogue@proc equ epiloguedef |
macro epiloguedef procname,flag,parmbytes,localbytes,reglist |
{ irps reg, reglist \{ reverse pop reg \} |
if parmbytes | localbytes |
leave |
end if |
if flag and 10000b |
retn |
else |
retn parmbytes |
end if } |
macro define@proc name,statement |
{ local params,flag,regs,parmbytes,localbytes,current |
if used name |
name: |
match =stdcall args, statement \{ params equ args |
flag = 11b \} |
match =stdcall, statement \{ params equ |
flag = 11b \} |
match =c args, statement \{ params equ args |
flag = 10001b \} |
match =c, statement \{ params equ |
flag = 10001b \} |
match =params, params \{ params equ statement |
flag = 0 \} |
virtual at ebp+8 |
match =uses reglist=,args, params \{ regs equ reglist |
params equ args \} |
match =regs =uses reglist, regs params \{ regs equ reglist |
params equ \} |
match =regs, regs \{ regs equ \} |
match =,args, params \{ defargs@proc args \} |
match =args@proc args, args@proc params \{ defargs@proc args \} |
parmbytes = $ - (ebp+8) |
end virtual |
name # % = parmbytes/4 |
all@vars equ |
current = 0 |
match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \} |
macro locals |
\{ virtual at ebp-localbytes+current |
macro label . \\{ deflocal@proc .,:, \\} |
struc db [val] \\{ \common deflocal@proc .,db,val \\} |
struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
macro endl |
\{ purge label |
restruc db,dw,dp,dd,dt,dq |
restruc rb,rw,rp,rd,rt,rq |
restruc byte,word,dword,pword,tword,qword |
current = $-(ebp-localbytes) |
end virtual \} |
macro ret operand |
\{ match any, operand \\{ retn operand \\} |
match , operand \\{ match epilogue:reglist, epilogue@proc:<regs> |
\\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} |
macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 |
end if \} } |
macro defargs@proc [arg] |
{ common |
if ~ arg eq |
forward |
local ..arg,current@arg |
match argname:type, arg |
\{ current@arg equ argname |
label ..arg type |
argname equ ..arg |
if dqword eq type |
dd ?,?,?,? |
else if tbyte eq type |
dd ?,?,? |
else if qword eq type | pword eq type |
dd ?,? |
else |
dd ? |
end if \} |
match =current@arg,current@arg |
\{ current@arg equ arg |
arg equ ..arg |
..arg dd ? \} |
common |
args@proc equ current@arg |
forward |
restore current@arg |
common |
end if } |
macro deflocal@proc name,def,[val] |
{ common |
match vars, all@vars \{ all@vars equ all@vars, \} |
all@vars equ all@vars name |
forward |
local ..var,..tmp |
..var def val |
match =?, val \{ ..tmp equ \} |
match any =dup (=?), val \{ ..tmp equ \} |
match tmp : value, ..tmp : val |
\{ tmp: end virtual |
initlocal@proc ..var,def value |
virtual at tmp\} |
common |
match first rest, ..var, \{ name equ first \} } |
macro initlocal@proc name,def |
{ virtual at name |
def |
size@initlocal = $ - name |
end virtual |
position@initlocal = 0 |
while size@initlocal > position@initlocal |
virtual at name |
def |
if size@initlocal - position@initlocal < 2 |
current@initlocal = 1 |
load byte@initlocal byte from name+position@initlocal |
else if size@initlocal - position@initlocal < 4 |
current@initlocal = 2 |
load word@initlocal word from name+position@initlocal |
else |
current@initlocal = 4 |
load dword@initlocal dword from name+position@initlocal |
end if |
end virtual |
if current@initlocal = 1 |
mov byte [name+position@initlocal],byte@initlocal |
else if current@initlocal = 2 |
mov word [name+position@initlocal],word@initlocal |
else |
mov dword [name+position@initlocal],dword@initlocal |
end if |
position@initlocal = position@initlocal + current@initlocal |
end while } |
macro endp |
{ purge ret,locals,endl |
finish@proc |
purge finish@proc |
restore regs@proc |
match all,args@proc \{ restore all \} |
restore args@proc |
match all,all@vars \{ restore all \} } |
macro local [var] |
{ common |
locals |
forward done@local equ |
match varname[count]:vartype, var |
\{ match =BYTE, vartype \\{ varname rb count |
restore done@local \\} |
match =WORD, vartype \\{ varname rw count |
restore done@local \\} |
match =DWORD, vartype \\{ varname rd count |
restore done@local \\} |
match =PWORD, vartype \\{ varname rp count |
restore done@local \\} |
match =QWORD, vartype \\{ varname rq count |
restore done@local \\} |
match =TBYTE, vartype \\{ varname rt count |
restore done@local \\} |
match =DQWORD, vartype \\{ label varname dqword |
rq count+count |
restore done@local \\} |
match , done@local \\{ virtual |
varname vartype |
end virtual |
rb count*sizeof.\#vartype |
restore done@local \\} \} |
match :varname:vartype, done@local:var |
\{ match =BYTE, vartype \\{ varname db ? |
restore done@local \\} |
match =WORD, vartype \\{ varname dw ? |
restore done@local \\} |
match =DWORD, vartype \\{ varname dd ? |
restore done@local \\} |
match =PWORD, vartype \\{ varname dp ? |
restore done@local \\} |
match =QWORD, vartype \\{ varname dq ? |
restore done@local \\} |
match =TBYTE, vartype \\{ varname dt ? |
restore done@local \\} |
match =DQWORD, vartype \\{ label varname dqword |
dq ?,? |
restore done@local \\} |
match , done@local \\{ varname vartype |
restore done@local \\} \} |
match ,done@local |
\{ var |
restore done@local \} |
common |
endl } |
/programs/develop/sdk/trunk/sound/src/setbuf.asm |
---|
0,0 → 1,77 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
extrn hSound |
public _SetBuffer@16 |
public _PlayBuffer@4 |
align 4 |
proc _SetBuffer@16 stdcall,str:dword, src:dword, offs:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_SETBUFF |
mov [input], ebx |
mov [inp_size], 16 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _PlayBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_PLAY |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
/programs/develop/sdk/trunk/sound/src/snd.inc |
---|
0,0 → 1,34 |
struc CTRL_INFO |
{ .pci_cmd dd ? |
.irq dd ? |
.glob_cntrl dd ? |
.glob_sta dd ? |
.codec_io_base dd ? |
.ctrl_io_base dd ? |
.codec_mem_base dd ? |
.ctrl_mem_base dd ? |
.codec_id dd ? |
} |
CTRL_INFO_SIZE equ 9*4 |
SRV_GETVERSION equ 0 |
SND_CREATE_BUFF equ 1 |
SND_DESTROY_BUFF equ 2 |
SND_SETFORMAT equ 3 |
SND_RESET equ 4 |
SND_SETPOS equ 5 |
SND_SETBUFF equ 6 |
SND_SETVOLUME equ 7 |
SND_GETVOLUME equ 8 |
SND_OUT equ 9 |
SND_PLAY equ 10 |
SND_STOP equ 11 |
SND_GETFREESIZE equ 12 |
DEV_SET_BUFF equ 4 |
DEV_NOTIFY equ 5 |
DEV_SET_MASTERVOL equ 6 |
DEV_GET_MASTERVOL equ 7 |
DEV_GET_INFO equ 8 |
/programs/develop/sdk/trunk/sound/src/sndout.asm |
---|
0,0 → 1,43 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
extrn hSound |
public _WaveOut@12 |
align 4 |
proc _WaveOut@12 stdcall,str:dword, src:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_OUT |
mov [input], ebx |
mov [inp_size], 12 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
/programs/develop/sdk/trunk/sound/src/sndvol.asm |
---|
0,0 → 1,108 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
public _GetMasterVol@4 |
public _SetMasterVol@4 |
extrn hrdwSound |
align 4 |
proc _GetMasterVol@4 stdcall, pvol:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hrdwSound] |
mov ecx, [pvol] |
xor ebx, ebx |
mov [handle], eax |
mov [io_code], DEV_GET_MASTERVOL |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ecx |
mov [out_size], 4 |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _SetMasterVol@4 stdcall,vol:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hrdwSound] |
lea ebx, [vol] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], DEV_SET_MASTERVOL |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
if 0 |
align 4 |
proc _GetDevInfo@8 stdcall, hSrv:dword, p_info:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
mov eax, [hSrv] |
xor ebx, ebx |
mov ecx, [p_info] |
mov [handle], eax |
mov [io_code], DEV_GET_INFO |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ecx |
mov [out_size], CTRL_INFO_SIZE |
lea eax, [handle] |
stdcall CallServiceEx, eax |
pop ebx |
ret |
endp |
end if |
/programs/develop/sdk/trunk/sound/src/sound.asm |
---|
0,0 → 1,372 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
public _InitSound@0 |
public _CreateBuffer@8 |
public _DestroyBuffer@4 |
public _SetBuffer@16 |
public _WaveOut@12 |
public _PlayBuffer@4 |
public _StopBuffer@4 |
public _GetMasterVol@4 |
public _SetMasterVol@4 |
align 4 |
proc _InitSound@0 |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, 68 |
mov ebx, 16 |
mov ecx, szInfinity |
int 0x40 |
test eax, eax |
jz .fail |
mov [hSound], eax |
mov eax, 68 |
mov ebx, 16 |
mov ecx, szSound |
int 0x40 |
mov [hrdwSound], eax |
mov eax, [hSound] |
xor ebx, ebx |
mov [handle], eax |
mov [io_code], SRV_GETVERSION |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ebx |
mov [out_size], ebx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
.fail: |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _CreateBuffer@8 stdcall, format:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [format] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_CREATE_BUFF |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _DestroyBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_DESTROY_BUFF |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _SetBuffer@16 stdcall,str:dword, src:dword, offs:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_SETBUFF |
mov [input], ebx |
mov [inp_size], 16 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _WaveOut@12 stdcall,str:dword, src:dword, size:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_OUT |
mov [input], ebx |
mov [inp_size], 12 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _PlayBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_PLAY |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _StopBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_STOP |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _GetMasterVol@4 stdcall, pvol:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hrdwSound] |
mov ecx, [pvol] |
xor ebx, ebx |
mov [handle], eax |
mov [io_code], DEV_GET_MASTERVOL |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ecx |
mov [out_size], 4 |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
align 4 |
proc _SetMasterVol@4 stdcall,vol:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hrdwSound] |
lea ebx, [vol] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], DEV_SET_MASTERVOL |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |
if 0 |
align 4 |
proc _GetDevInfo@8 stdcall, hSrv:dword, p_info:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
mov eax, [hSrv] |
xor ebx, ebx |
mov ecx, [p_info] |
mov [handle], eax |
mov [io_code], DEV_GET_INFO |
mov [input], ebx |
mov [inp_size], ebx |
mov [output], ecx |
mov [out_size], CTRL_INFO_SIZE |
lea eax, [handle] |
stdcall CallServiceEx, eax |
pop ebx |
ret |
endp |
end if |
section '.data' align 16 data readable writable |
szInfinity db 'INFINITY',0 |
szSound db 'SOUND',0 |
align 4 |
hSound dd ? |
hrdwSound dd ? |
/programs/develop/sdk/trunk/sound/src/stopbuf.asm |
---|
0,0 → 1,43 |
format MS COFF |
include "snd.inc" |
include "proc32.inc" |
section '.text' align 16 code readable executable |
extrn hSound |
public _StopBuffer@4 |
align 4 |
proc _StopBuffer@4 stdcall, str:dword |
locals |
handle dd ? |
io_code dd ? |
input dd ? |
inp_size dd ? |
output dd ? |
out_size dd ? |
endl |
push ebx |
push ecx |
mov eax, [hSound] |
lea ebx, [str] |
xor ecx, ecx |
mov [handle], eax |
mov [io_code], SND_STOP |
mov [input], ebx |
mov [inp_size], 4 |
mov [output], ecx |
mov [out_size], ecx |
mov eax, 68 |
mov ebx, 17 |
lea ecx, [handle] |
int 0x40 |
pop ecx |
pop ebx |
ret |
endp |