diff --git a/programs/develop/open watcom/trunk/clib/crt/8087cw.c b/programs/develop/open watcom/trunk/clib/crt/8087cw.c new file mode 100644 index 0000000000..a57e801980 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/8087cw.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: Default 80x87 control word. +* +****************************************************************************/ + + +#include + +/* This is the default value loaded into the 80x87 control word. + If you want higher precision, then change PC_53 to PC_64. The + reason we have the default set to PC_53 is generate reproducible + floating-point results regardless of the level of optimization + chosen for the compiler. + This value is loaded when the 80x87 is initialized by the startup + code, and also when _fpreset is called. +*/ +#pragma aux __8087cw "*"; + +/* 0x1000 | 0x0000 | 0x0200 | 0x007F */ +unsigned short __8087cw = IC_AFFINE | RC_NEAR | PC_53 | 0x007F; diff --git a/programs/develop/open watcom/trunk/clib/crt/87state.h b/programs/develop/open watcom/trunk/clib/crt/87state.h new file mode 100644 index 0000000000..b164a5e695 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/87state.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: prototype for 8087 save/restore state functions and data +* +****************************************************************************/ + + +#if defined(_M_IX86) + +typedef struct _87state { /* 80x87 save area */ +#if defined( __386__ ) + char data[108]; /* 32-bit save area size */ +#else + char data[94]; /* 16-bit save area size */ +#endif +} _87state; + +extern void (*__Save8087)(_87state *); +extern void (*__Rest8087)(_87state *); + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/_8087386.asm b/programs/develop/open watcom/trunk/clib/crt/_8087386.asm new file mode 100644 index 0000000000..de2d47d6e7 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/_8087386.asm @@ -0,0 +1,52 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc + + modstart _8087 + + xref "C",__chk8087 + +datasegment + public __8087 + public __real87 + extrn __no87 :word +__8087 db 0 ; 0 => no 8087 and no EMU, otherwise 8087 or EMU present +__real87 db 0 ; 0 => no real 8087 is used, otherwise real 8087 is used +enddata + +include xinit.inc + + xinit __chk8087,INIT_PRIORITY_FPU + 3 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/crt/_8087osi.c b/programs/develop/open watcom/trunk/clib/crt/_8087osi.c new file mode 100644 index 0000000000..f0dabc9959 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/_8087osi.c @@ -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: 80x87 related globals for OSI. +* +****************************************************************************/ + + +#include "variety.h" + +unsigned char _8087; +unsigned char _real87; diff --git a/programs/develop/open watcom/trunk/clib/crt/___argc.c b/programs/develop/open watcom/trunk/clib/crt/___argc.c new file mode 100644 index 0000000000..bff5899c8c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/___argc.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: Argument vector and count. +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include "initarg.h" + +_WCRTLINKD int __F_NAME(___Argc,___wArgc); /* argument count */ +_WCRTLINKD CHAR_TYPE** __F_NAME(___Argv,___wArgv); /* argument vector */ diff --git a/programs/develop/open watcom/trunk/clib/crt/_exit.c b/programs/develop/open watcom/trunk/clib/crt/_exit.c new file mode 100644 index 0000000000..f91c1e2250 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/_exit.c @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation _Exit(). +* +****************************************************************************/ + + +#include + + +/* POSIX says _exit() and _Exit() "shall be functionally equivalent" */ + +_WCRTLINK void _Exit( int status ) +/********************************/ +{ + _exit( status ); +} diff --git a/programs/develop/open watcom/trunk/clib/crt/abort.c b/programs/develop/open watcom/trunk/clib/crt/abort.c new file mode 100644 index 0000000000..2a571cb2c9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/abort.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: Platform independent abort() implementation. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "rtdata.h" +#include "exitwmsg.h" +#include +#include + + +void (*_RWD_abort)( void ) = __terminate; + +_WCRTLINK void abort( void ) +{ + if( _RWD_abort != __terminate ) { + (*_RWD_abort)(); + } + __terminate(); /* 23-may-90 */ +} + +void __terminate( void ) +{ + __fatal_runtime_error( "ABNORMAL TERMINATION\r\n", EXIT_FAILURE ); +} diff --git a/programs/develop/open watcom/trunk/clib/crt/argcv.c b/programs/develop/open watcom/trunk/clib/crt/argcv.c new file mode 100644 index 0000000000..82e76e6a8c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/argcv.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Argument vector definition and startup. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtinit.h" +#include "widechar.h" +#include +#include "initarg.h" + +int __F_NAME(_argc,_wargc); +CHAR_TYPE** __F_NAME(_argv,_wargv); +int __F_NAME(__argc,__wargc); +CHAR_TYPE** __F_NAME(__argv,__wargv); + +#if defined(__386__) || defined(__AXP__) || defined(__PPC__) +AXI( __F_NAME(__Init_Argv,__wInit_Argv), INIT_PRIORITY_RUNTIME ) +AYI( __F_NAME(__Fini_Argv,__wFini_Argv), INIT_PRIORITY_LIBRARY ) +#else +AXI( __F_NAME(__Init_Argv,__wInit_Argv), 1 ) +AYI( __F_NAME(__Fini_Argv,__wFini_Argv), 1 ) +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/binmode.c b/programs/develop/open watcom/trunk/clib/crt/binmode.c new file mode 100644 index 0000000000..19d0119bf3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/binmode.c @@ -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: Special object file to force binary mode when linked in. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "rtdata.h" +#include "rtinit.h" + +static void do_it( void ) +{ + _RWD_fmode = O_BINARY; +} + +AXI( do_it, INIT_PRIORITY_LIBRARY ) diff --git a/programs/develop/open watcom/trunk/clib/crt/chk.asm b/programs/develop/open watcom/trunk/clib/crt/chk.asm new file mode 100644 index 0000000000..b3fcf326b3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/chk.asm @@ -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 mdef.inc +include struct.inc + + xref __STK + + modstart chk + + xdefp __CHK + xdefp __GRO + + + defp __CHK + xchg eax,4[esp] + call __STK + mov eax,4[esp] + ret 4 + endproc __CHK + + + defp __GRO + ret 4 + endproc __GRO + + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/crt/chk8087.c b/programs/develop/open watcom/trunk/clib/crt/chk8087.c new file mode 100644 index 0000000000..4176f4e0bd --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/chk8087.c @@ -0,0 +1,344 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: __chk8087 and other FPU related functions. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#if defined( __OS2__ ) +#endif +#if defined( __WINDOWS__ ) + #include +#endif + +#include "rtdata.h" +#include "exitwmsg.h" +#include "87state.h" + +extern void __GrabFP87( void ); + +extern unsigned short __8087cw; +#pragma aux __8087cw "*"; + +#if defined( __DOS_086__ ) +extern unsigned char __dos87real; +#pragma aux __dos87real "*"; + +extern unsigned short __dos87emucall; +#pragma aux __dos87emucall "*"; +#endif + +extern void __init_80x87( void ); +#if defined( __DOS_086__ ) +#pragma aux __init_80x87 "*" = \ + ".8087" \ + "cmp __dos87real,0" \ + "jz l1" \ + "finit" \ + "fldcw __8087cw" \ +"l1: cmp __dos87emucall,0" \ + "jz l2" \ + "mov ax,1" \ + "call __dos87emucall" \ +"l2:" ; +#else +#pragma aux __init_80x87 "*" = \ + ".8087" \ + "finit" \ + "fldcw __8087cw" ; +#endif + +/* 0 => no 8087; 2 => 8087,287; 3=>387 */ +extern unsigned char _WCI86NEAR __x87id( void ); +#pragma aux __x87id "*"; + +#if !defined( __UNIX__ ) && !defined( __OS2_386__ ) + +extern void __fsave( _87state * ); +extern void __frstor( _87state * ); + +#if defined( __386__ ) + + #pragma aux __fsave = \ + 0x9b 0xdd 0x30 /* fsave [eax] ; save the 8087 state */ \ + 0x9b /* wait */ \ + parm routine [eax]; + + #pragma aux __frstor = \ + 0xdd 0x20 /* frstor [eax] ; restore the 8087 */ \ + 0x9b /* wait ; wait */ \ + parm routine [eax]; + +#else /* __286__ */ + + #if defined( __BIG_DATA__ ) + #pragma aux __fsave = \ + 0x53 /* push bx */ \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0x8b 0xd8 /* mov bx,ax */ \ + 0x9b 0xdd 0x37 /* fsave [bx] */ \ + 0x90 0x9b /* fwait */ \ + 0x1f /* pop ds */ \ + 0x5b /* pop bx */ \ + parm routine [dx ax]; + #else + #pragma aux __fsave = \ + 0x53 /* push bx */ \ + 0x8b 0xd8 /* mov bx,ax */ \ + 0x9b 0xdd 0x37 /* fsave [bx] */ \ + 0x90 0x9b /* fwait */ \ + 0x5b /* pop bx */ \ + parm routine [ax]; + #endif + + #if defined( __BIG_DATA__ ) + #pragma aux __frstor = \ + 0x53 /* push bx */ \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0x8b 0xd8 /* mov bx,ax */ \ + 0x9b 0xdd 0x27 /* frstor [bx] */ \ + 0x90 0x9b /* fwait */ \ + 0x1f /* pop ds */ \ + 0x5b /* pop bx */ \ + parm routine [dx ax]; + #else + #pragma aux __frstor = \ + 0x53 /* push bx */ \ + 0x8b 0xd8 /* mov bx,ax */ \ + 0x9b 0xdd 0x27 /* frstor [bx] */ \ + 0x90 0x9b /* fwait */ \ + 0x5b /* pop bx */ \ + parm routine [ax]; + #endif + +#endif + +static void __save_8087( _87state * __fs ) +{ + __fsave( __fs ); +} + +static void __rest_8087( _87state * __fs ) +{ + __frstor( __fs ); +} +#endif /* !__UNIX__ && && !__OS2__ */ + +_WCRTLINK void _fpreset( void ) +{ + if( _RWD_8087 != 0 ) { + __init_80x87(); + } +} + +void __init_8087( void ) +{ +#if !defined( __UNIX__ ) && !defined( __OS2_386__ ) + if( _RWD_real87 != 0 ) + { /* if our emulator, don't worry */ + _RWD_Save8087 = __save_8087; /* point to real save 8087 routine */ + _RWD_Rest8087 = __rest_8087; /* point to real restore 8087 routine */ + } +#endif + _fpreset(); +} + +#if defined( __DOS__ ) || defined( __OS2_286__ ) + +void _WCI86FAR __default_sigfpe_handler( int fpe_sig ) +{ + __fatal_runtime_error( "Floating point exception\r\n", EXIT_FAILURE ); +} +#endif + +#if defined( __OS2__ ) + +void __chk8087( void ) +/********************/ +{ + char devinfo; + +#if defined( __386__ ) + DosDevConfig( &devinfo, DEVINFO_COPROCESSOR ); + if( devinfo == 0 ) { + _RWD_real87 = 0; + } else { + _RWD_real87 = __x87id(); + } + _RWD_8087 = _RWD_real87; +#else + if( _RWD_8087 == 0 ) { + DosDevConfig( &devinfo, 3, 0 ); + if( devinfo == 0 ) { + _RWD_real87 = 0; + } else { + _RWD_real87 = __x87id(); + } + _RWD_8087 = _RWD_real87; + } + if( _RWD_real87 ) { + __GrabFP87(); + } + if( _RWD_8087 ) { + _RWD_FPE_handler = __default_sigfpe_handler; + } +#endif + _fpreset(); +} + +#elif defined( __QNX__ ) + +void __chk8087( void ) +/********************/ +{ + extern char __87; + extern char __r87; + + _RWD_real87 = __r87; + _RWD_8087 = __87; + _fpreset(); +} + +#elif defined( __LINUX__ ) + +void __chk8087( void ) +/********************/ +{ + // TODO: We really need to call Linux and determine if the machine + // has a real FPU or not, so we can properly work with an FPU + // emulator. + _RWD_real87 = __x87id(); + _RWD_8087 = _RWD_real87; + _fpreset(); +} + +#elif defined( __NETWARE__ ) + +extern short __87present( void ); +#pragma aux __87present = \ + "smsw ax ", \ + "test ax, 4 ", \ + "jne no_emu ", \ + "xor ax, ax ", \ + "no_emu: ", \ + "mov ax, 1 " \ +value [ ax ]; + +extern void __chk8087( void ) +/*****************************/ +{ + if( _RWD_8087 == 0 ) { + if( __87present() ) { + _RWD_8087 = 3; /* 387 */ + _RWD_real87 = 3; + } + __init_80x87(); + } +} + +#elif defined( __NT__ ) + +void __chk8087( void ) +/********************/ +{ + _RWD_real87 = 3; //387+ ; //__x87id(); + _RWD_8087 = _RWD_real87; + __init_8087(); +} + +#elif defined( __DOS__ ) + +void __chk8087( void ) +/********************/ +{ + if( _RWD_8087 != 0 ) { /* if we already know we have an 80x87 */ +#if !defined( __386__ ) + if( __dos87real ) + __GrabFP87(); +#endif + _RWD_FPE_handler = __default_sigfpe_handler; + return; /* this prevents real87 from being set */ + } /* when we have an emulator */ + _RWD_real87 = __x87id(); /* if a coprocessor is present then we */ + _RWD_8087 = _RWD_real87; /* initialize even when NO87 is defined */ +#if !defined( __386__ ) + __dos87real = _RWD_real87; +#endif + __init_8087(); /* this handles the fpi87 and NO87 case */ + if( _RWD_no87 != 0 ) { /* if NO87 environment var is defined */ + _RWD_8087 = 0; /* then we want to pretend that the */ + _RWD_real87 = 0; /* coprocessor doesn't exist */ + } + if( _RWD_real87 ) { + __GrabFP87(); + } + if( _RWD_8087 ) { + _RWD_FPE_handler = __default_sigfpe_handler; + } +} + +#elif defined( __WINDOWS__ ) + +void __chk8087( void ) +/********************/ +{ + if( _RWD_8087 != 0 ) /* if we already know we have an 80x87 */ + return; /* this prevents real87 from being set */ + /* when we have an emulator */ + if( GetWinFlags() & WF_80x87 ) { /* if a coprocessor is present then we */ + #if defined( __386__ ) + extern void pascal _FloatingPoint( void ); + _FloatingPoint(); + #endif + _RWD_real87 = __x87id(); /* initialize even when NO87 is defined */ + _RWD_8087 = _RWD_real87; /* this handles the fpi87 and NO87 case */ + __init_8087(); + } else { + #if defined( __386__ ) + // check to see if emulator is loaded + union REGS regs; + regs.w.ax = 0xfa00; + int86( 0x2f, ®s, ®s ); + if( regs.w.ax == 0x0666 ) { /* check for emulator present */ + _RWD_real87 = __x87id(); /* initialize even when NO87 is defined */ + _RWD_8087 = _RWD_real87; /* this handles the fpi87 and NO87 case */ + __init_8087(); + } + #endif + } + if( _RWD_no87 != 0 ) { /* if NO87 environment var is defined */ + _RWD_8087 = 0; /* then we want to pretend that the */ + _RWD_real87 = 0; /* coprocessor doesn't exist */ + } +} + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/cinit.c b/programs/develop/open watcom/trunk/clib/crt/cinit.c new file mode 100644 index 0000000000..f333efccd3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/cinit.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: Common clib initialization code. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include +#if defined(__DOS_386__) && !defined(__OSI__) +#elif defined(__OS2__) +#elif defined(__WINDOWS_386__) || defined(__NT__) +#endif + +#if defined(__OS2__) +#endif + +#if defined(__DOS_386__) && !defined(__OSI__) +#endif + +void __CommonInit( void ) +/**************************/ +{ +#if !defined(__NETWARE__) && !defined(__NT__) + _amblksiz = 32 * 1024; /* set minimum memory block allocation */ +#endif + +#if defined(__DOS_386__) && !defined(__OSI__) + /* + * If we are running under DOS/4G then we need to page lock interrupt + * handlers (since we could be running under VMM). + */ + if (!_IsPharLap() && (__DPMI_hosted() == 1)) + { + DPMILockLinearRegion((long)&__GETDSStart_, + ((long)&__GETDSEnd_ - (long)&__GETDSStart_)); + } +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/crt/commode.c b/programs/develop/open watcom/trunk/clib/crt/commode.c new file mode 100644 index 0000000000..08a71c9bd9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/commode.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: set commit mode initialization function +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" +#include "rtinit.h" +#include "commode.h" + +/* + * __set_commode function is actually a _WCRTLINK function. It's prototyped + * incorrectly so that this module will work correctly with both dynamic + * and static versions of the C library. + * + * The pragma is there so that this module will work with both stack and + * register calling conventions, eliminating the need to have a separate + * object file for each. + * + * Similarly, __set_commode is declared _WCI86FAR so that the same object + * file will work in any 16-bit memory model. + */ + +static void do_it( void ) +{ + __set_commode(); +} + + +AXI( do_it, INIT_PRIORITY_LIBRARY ) diff --git a/programs/develop/open watcom/trunk/clib/crt/commode.h b/programs/develop/open watcom/trunk/clib/crt/commode.h new file mode 100644 index 0000000000..76af4ba5d6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/commode.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: declaration for set commit mode function +* +****************************************************************************/ + + +/* see note in commode.c */ +_WCRTLINK extern void _WCI86FAR __set_commode( void ); +#pragma aux __set_commode "*_"; diff --git a/programs/develop/open watcom/trunk/clib/crt/crwd386.asm b/programs/develop/open watcom/trunk/clib/crt/crwd386.asm new file mode 100644 index 0000000000..c5ea7c2c1a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/crwd386.asm @@ -0,0 +1,179 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: C runtime read/write data (386 version). +;* +;***************************************************************************** + + + name crwdata + +.387 +.386p + + assume nothing + +DGROUP group _DATA + +_TEXT segment byte public 'CODE' + assume cs:_TEXT +__null_FPE_rtn proc near + ret +__null_FPE_rtn endp +_TEXT ends + +_DATA segment dword public 'DATA' + + assume DS:DGROUP + +ifndef __NETWARE__ +_dynend dd 0 ; top of dynamic data area +_curbrk dd 0 ; top of usable memory +endif +ifndef __QNX__ +ifndef __LINUX__ +ifndef _NETWARE_LIBC +_LpCmdLine dd 0 ; pointer to raw command line +_LpPgmName dd 0 ; pointer to program name (for argv[0]) +endif +ifdef __NT__ +_LpDllName dd 0 ; pointer to dll name (for OS/2,WIN32) +_LpwCmdLine dd 0 ; pointer to widechar raw command line +_LpwPgmName dd 0 ; pointer to widechar program name (for argv[0]) +_LpwDllName dd 0 ; pointer to widechar dll name (for OS/2,WIN32) +endif +ifdef __OS2__ +_LpDllName dd 0 ; pointer to dll name (for OS/2,WIN32) +_LpwCmdLine dd 0 ; pointer to widechar raw command line +_LpwPgmName dd 0 ; pointer to widechar program name (for argv[0]) +_LpwDllName dd 0 ; pointer to widechar dll name (for OS/2,WIN32) +endif +ifdef __DOS__ +_psp dw 0,0 ; segment addr of program segment prefix +__x386_stacklow label dword +endif +endif +endif +_STACKLOW dd 0 ; lowest address in stack +_STACKTOP dd 0 ; highest address in stack +__EFG_printf dd 0 +__EFG_scanf dd 0 +__ASTACKSIZ dd 0 ; alternate stack size +__ASTACKPTR dd 0 ; alternate stack pointer +ifndef __NETWARE__ +_cbyte dd 0 ; used by getch, getche +_cbyte2 dd 0 ; used by getch, getche +_child dd 0 ; non-zero => a spawned process is running +endif +__no87 dw 0 ; non-zero => "NO87" environment var present +ifndef __NETWARE__ +ifdef __DOS__ +_Extender db 0 ; see clib\h\extender.inc for values +_ExtenderSubtype db 0 ; non-zero -> variant of extender +__X32VM db 0 ; non-zero => X-32VM DOS Extender +endif +_Envptr dd 0 ; offset part of environment pointer +_Envseg dw 0 ; segment containing environment strings +ifndef __QNX__ +ifndef __LINUX__ +_osmajor db 0 ; major DOS version number +_osminor db 0 ; minor DOS version number +ifdef __NT__ +_osbuild dw 0 ; operating system build number +_osver dd 0 ; operating system build number +_winmajor dd 0 ; operating system major version number +_winminor dd 0 ; operating system minor version number +_winver dd 0 ; operating system version number +endif +endif +endif +endif +__FPE_handler dd __null_FPE_rtn ; FPE handler + + +ifndef __QNX__ +ifndef __LINUX__ +ifndef __NETWARE__ + public "C",_osmajor + public "C",_osminor +ifdef __NT__ + public "C",_osbuild + public "C",_osver + public "C",_winmajor + public "C",_winminor + public "C",_winver + public "C",__EFG_printf + public "C",__EFG_scanf +endif +endif +ifdef __DOS__ + public "C",_psp + public "C",_Extender + public "C",_ExtenderSubtype + public __X32VM + public __x386_stacklow +endif +ifndef _NETWARE_LIBC + public "C",_LpCmdLine + public "C",_LpPgmName +endif +ifdef __NT__ + public "C",_LpDllName + public "C",_LpwCmdLine + public "C",_LpwPgmName + public "C",_LpwDllName + public "C",_LpCmdLine + public "C",_LpPgmName +endif +ifdef __OS2__ + public "C",_LpDllName + public "C",_LpwCmdLine + public "C",_LpwPgmName + public "C",_LpwDllName +endif +endif +endif +ifndef __NETWARE__ + public "C",_dynend + public "C",_curbrk +endif + public "C",_STACKLOW + public "C",_STACKTOP + public __ASTACKSIZ + public __ASTACKPTR +ifndef __NETWARE__ + public "C",_cbyte + public "C",_cbyte2 + public "C",_child + public "C",_Envptr + public "C",_Envseg +endif + public __no87 + public "C",__FPE_handler + +_DATA ends + + end diff --git a/programs/develop/open watcom/trunk/clib/crt/cstrklbi.asm b/programs/develop/open watcom/trunk/clib/crt/cstrklbi.asm new file mode 100644 index 0000000000..5f38d74722 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/cstrklbi.asm @@ -0,0 +1,70 @@ + + name cstrklbri +.386p + assume nothing + + extrn __KolibriMain : near + extrn ___begtext : near + extrn __STACKTOP : near + extrn __STACKLOW : near + extrn __FiniRtns : near + extrn _LpCmdLine : near + extrn _LpPgmName : near + +_TEXT segment use32 dword public 'CODE' + + public _cstart_ + public mainCRTStartup + public __exit_ + + assume cs:_TEXT + +_cstart_ proc near +mainCRTStartup: + + mov edx, 0x400 + mov eax, 0xff + out dx, al + + mov eax, esp + sub eax, 8192 + mov dword ptr [__STACKTOP],esp ; set stack top + mov dword ptr [__STACKLOW],eax + mov eax, dword ptr [ds:0x001c] + mov ebx, dword ptr [ds:0x0020] + mov dword ptr [_LpCmdLine], eax + mov dword ptr [_LpPgmName], ebx + jmp __KolibriMain + dd ___begtext ; reference module with segment definitions +; +; copyright message +; + db "Open Watcom C/C++32 Run-Time system. " + db "Portions Copyright (c) Sybase, Inc. 1988-2002." +_cstart_ endp + + +__exit_ proc near + mov eax,00h ; run finalizers + mov edx,0fh ; less than exit + call __FiniRtns ; call finalizer routines + mov eax, -1 + int 0x40 + ret +__exit_ endp + +public _scalbn +_scalbn proc + fild dword ptr [esp+12] + fld qword ptr [esp+4] + fscale + fstp st[1] + ret +_scalbn endp + + +_TEXT ends + + + + end _cstart_ ;programm entry point diff --git a/programs/develop/open watcom/trunk/clib/crt/cstrtwnt.asm b/programs/develop/open watcom/trunk/clib/crt/cstrtwnt.asm new file mode 100644 index 0000000000..8a3ae5feb9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/cstrtwnt.asm @@ -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: C/C++ Windows NT 32-bit console startup code. +;* +;***************************************************************************** + + +; This must be assembled using one of the following commands: +; wasm cstrtwnt -bt=NT -ms -3r +; wasm cstrtwnt -bt=NT -ms -3s +; + name cstrtwnt +.386p + assume nothing + + extrn __NTMain : near + extrn ___begtext : near + extrn __LpCmdLine : near + extrn __LpPgmName : near + extrn __STACKLOW : near + extrn __STACKTOP : near + +_TEXT segment use32 word public 'CODE' + + public _cstart_ + public mainCRTStartup + + assume cs:_TEXT + +_cstart_ proc near +mainCRTStartup: + + mov dword ptr [__STACKTOP], esp + lea eax, [esp-40000h] + mov dword ptr[__STACKLOW], eax + + mov eax, dword ptr [ds:0x1c] + mov dword ptr [__LpCmdLine], eax + mov eax, dword ptr [ds:0x20] + mov dword ptr [__LpPgmName], eax + + jmp __NTMain + dd ___begtext ; reference module with segment definitions +; +; copyright message +; + db "Open Watcom C/C++32 Run-Time system. " + db "Portions Copyright (c) Sybase, Inc. 1988-2002." +_cstart_ endp + +_TEXT ends + + end _cstart_ diff --git a/programs/develop/open watcom/trunk/clib/crt/cvtbuf.c b/programs/develop/open watcom/trunk/clib/crt/cvtbuf.c new file mode 100644 index 0000000000..0d9bd74fa3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/cvtbuf.c @@ -0,0 +1,50 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: __CVTBuffer() implementation. +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +//#include "liballoc.h" +#include "rtdata.h" +#include "exitwmsg.h" +#include "xfloat.h" +#if defined(__SW_BM) +#include "thread.h" +#endif + +#if !defined(__SW_BM) + static MAX_CHAR_TYPE cvt_buffer[ __FPCVT_BUFFERLEN + 1 ]; +#endif + +_WCRTLINK CHAR_TYPE *__CVTBuffer( void ) +{ + return( (CHAR_TYPE *)_RWD_cvtbuf ); +} diff --git a/programs/develop/open watcom/trunk/clib/crt/errno.c b/programs/develop/open watcom/trunk/clib/crt/errno.c new file mode 100644 index 0000000000..df5e80c0c9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/errno.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: errno related functions. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" + +#if defined(__QNX__) + +#include +#include + +_WCRTLINK int *__get_errno_ptr( void ) +{ +#if defined(__386__) + void *err_ptr; + + __getmagicvar( &err_ptr, _m_errno_ptr ); + return( err_ptr ); +#else + return( (int *)&__MAGIC.Errno ); +#endif +} + +#elif defined(__LINUX__) + +#include "errorno.h" + +#if !defined( __SW_BM ) + _WCRTLINKD int errno; +#endif + +_WCRTLINK int *__get_errno_ptr( void ) +{ + return( &_RWD_errno ); +} + +#else + +#include "errorno.h" + +#if !defined( __SW_BM ) + _WCRTLINKD int errno; + _WCRTLINKD int _doserrno; +#endif + +_WCRTLINK int *__get_errno_ptr( void ) +{ + return( &_RWD_errno ); +} + +_WCRTLINK int *__get_doserrno_ptr( void ) +{ + return( &_RWD_doserrno ); +} + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/errnovar.c b/programs/develop/open watcom/trunk/clib/crt/errnovar.c new file mode 100644 index 0000000000..d6c19e206b --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/errnovar.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: Module to initialize errno access. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtinit.h" + +extern void __initerrno( void ); + +_WCRTLINKD unsigned errno; + +AXI( __initerrno, INIT_PRIORITY_LIBRARY ) diff --git a/programs/develop/open watcom/trunk/clib/crt/errorno.h b/programs/develop/open watcom/trunk/clib/crt/errorno.h new file mode 100644 index 0000000000..554358bc5e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/errorno.h @@ -0,0 +1,60 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR 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(__OS2__) || defined(__NT__) + #if defined(__SW_BM) + + #include "thread.h" + + #define _ERRNO (__THREADDATAPTR->__errnoP) + #define _DOSERRNO (__THREADDATAPTR->__doserrnoP) + + #else + + #define _ERRNO errno + #define _DOSERRNO _doserrno + + #endif +#else + // QNX errno is magically multithread aware + // What does NETWARE do? + #if !defined (_NETWARE_LIBC) + #define _ERRNO errno + #else + extern int * ___errno(void); + #define _ERRNO *___errno() /* get LibC errno */ + #endif + + #ifndef __NETWARE__ + #define _DOSERRNO _doserrno + #endif +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/exit.c b/programs/develop/open watcom/trunk/clib/crt/exit.c new file mode 100644 index 0000000000..28296fed49 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/exit.c @@ -0,0 +1,84 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of exit() and associated functions. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" +#include "exitwmsg.h" +#include "initfini.h" +#include "rtinit.h" +#include +#include +//#include "defwin.h" +#include "widechar.h" +#include "initarg.h" + +/* + __int23_exit is used by OS/2 as a general termination routine which unhooks + exception handlers. A better name for this variable is __sig_exit. + __sig_exit should be the system dependent signal termination routine and + should replace the calls to __int23_exit and __FPE_handler_exit. + Each OS should define its own __sig_exit and do the appropriate thing (for + example, DOS version would call __int23_exit and __FPE_handler_exit) +*/ + + +#if defined(__NT__) || defined(__WARP__) +_WCRTLINK extern void (*__process_fini)( unsigned, unsigned ); +#endif + + +#if !defined(__UNIX__) && !defined(__WINDOWS_386__) +static void _null_exit_rtn() {} +void (*__FPE_handler_exit)() = _null_exit_rtn; +#endif + +_WCRTLINK void exit( int status ) +{ + +#if defined(__UNIX__) +#elif defined(__WINDOWS_386__) +#elif defined(__NT__) || defined(__WARP__) + __FiniRtns( FINI_PRIORITY_EXIT, 255 ); +#else + __FiniRtns( FINI_PRIORITY_EXIT, 255 ); +#endif + _exit( status ); +} + + +#ifndef __NETWARE__ + +_WCRTLINK void _exit( int status ) +{ + __exit( status ); +} + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/exitwmsg.h b/programs/develop/open watcom/trunk/clib/crt/exitwmsg.h new file mode 100644 index 0000000000..38e47c36ac --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/exitwmsg.inc b/programs/develop/open watcom/trunk/clib/crt/exitwmsg.inc new file mode 100644 index 0000000000..e849921e90 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/farsupp.h b/programs/develop/open watcom/trunk/clib/crt/farsupp.h new file mode 100644 index 0000000000..ab9c4973d0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/fltused.c b/programs/develop/open watcom/trunk/clib/crt/fltused.c new file mode 100644 index 0000000000..3c95144bdb --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/fltused.c @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Module to invoke floating-point support initialiation. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtinit.h" + +#if defined(__AXP__) || defined(__386__) || defined(__PPC__) +unsigned _fltused_ = 0; +#else +unsigned _fltused_ = 1; +#endif + +#if defined(_M_IX86) + #pragma aux _fltused_ "*"; +#endif + +extern void __setEFGfmt( void ); + +AXI( __setEFGfmt, INIT_PRIORITY_LIBRARY ) diff --git a/programs/develop/open watcom/trunk/clib/crt/fpexcept.c b/programs/develop/open watcom/trunk/clib/crt/fpexcept.c new file mode 100644 index 0000000000..de9edfb1d9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/fpexcept.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: Floating-point exception handler wrapper. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" + +/* + __FPE_exception is called from machine language with parm in EAX/AX + (see "fstatus" module in CGSUPP) +*/ + +#if defined(__386__) + #define parmreg eax +#else + #define parmreg ax +#endif + +void __FPE_exception( int fpe_type ); +#pragma aux __FPE_exception "*_" parm caller [parmreg]; + +void __FPE_exception( int fpe_type ) +{ + _RWD_FPE_handler( fpe_type ); +} diff --git a/programs/develop/open watcom/trunk/clib/crt/ftos.h b/programs/develop/open watcom/trunk/clib/crt/ftos.h new file mode 100644 index 0000000000..7d07bf3594 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/initarg.h b/programs/develop/open watcom/trunk/clib/crt/initarg.h new file mode 100644 index 0000000000..c7648e6ad6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/initarg.h @@ -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: prototypes for arguments processing variables +* +****************************************************************************/ + + +#ifndef _INITARG_H_INCLUDED +#define _INITARG_H_INCLUDED + +extern int __F_NAME(_argc,_wargc); /* argument count */ +extern CHAR_TYPE **__F_NAME(_argv,_wargv); /* argument vector */ + +extern void __F_NAME(__Init_Argv,__wInit_Argv)( void ); +extern void __F_NAME(__Fini_Argv,__wFini_Argv)( void ); + +_WCRTLINKD extern int __F_NAME(___Argc,___wArgc); /* argument count */ +_WCRTLINKD extern CHAR_TYPE**__F_NAME(___Argv,___wArgv); /* argument vector */ + +_WCRTLINKD extern char *_LpCmdLine; /* pointer to command line */ +_WCRTLINKD extern char *_LpPgmName; /* pointer to program name */ + extern char *_LpDllName; /* pointer to dll name */ + +_WCRTLINKD extern wchar_t *_LpwCmdLine; /* pointer to wide command line */ +_WCRTLINKD extern wchar_t *_LpwPgmName; /* pointer to wide program name */ + extern wchar_t *_LpwDllName; /* pointer to wide dll name */ + +#if defined(__WINDOWS_386__) +extern char __Is_DLL; +#else +extern int __Is_DLL; +#endif + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/initargv.c b/programs/develop/open watcom/trunk/clib/crt/initargv.c new file mode 100644 index 0000000000..79526b7fb5 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/initargv.c @@ -0,0 +1,222 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Functions to set up argc and argv parameters of main(), etc. +* +****************************************************************************/ +#define __NETWARE__ + +#ifdef __NETWARE__ + void __Init_Argv( void ) { } + void __Fini_Argv( void ) { } +#else +//#include "dll.h" // needs to be first +#include "variety.h" +#include "widechar.h" +#include +#include +#include +#include +//#include "liballoc.h" +#include "initarg.h" + +extern int __historical_splitparms; +extern void _Not_Enough_Memory( void ); /* 25-jul-89 */ +static unsigned _SplitParms(int, CHAR_TYPE *, CHAR_TYPE **, CHAR_TYPE ** ); +_WCRTLINKD static CHAR_TYPE *__F_NAME(__CmdLine,__wCmdLine); /* cmdline buffer */ + +_WCRTLINK void *__F_NAME( _getargv, _wgetargv )( + int historical, CHAR_TYPE *exe, CHAR_TYPE *cmd, + int *pargc, CHAR_TYPE ***pargv ); + +void __F_NAME(__Init_Argv,__wInit_Argv)( void ) +{ + __F_NAME( __CmdLine, __wCmdLine ) = __F_NAME( _getargv, _wgetargv )( + __historical_splitparms, + __F_NAME( _LpPgmName, _LpwPgmName ), __F_NAME( _LpCmdLine, _LpwCmdLine ), + &__F_NAME( _argc, _wargc ), &__F_NAME( _argv, _wargv ) ); + + __F_NAME( __argc, __wargc ) = __F_NAME( _argc, _wargc ); + __F_NAME( ___Argc, ___wArgc ) = __F_NAME( _argc, _wargc ); + __F_NAME( __argv, __wargv ) = __F_NAME( _argv, _wargv ); + __F_NAME( ___Argv, ___wArgv ) = __F_NAME( _argv, _wargv ); +} + +_WCRTLINK void *__F_NAME( _getargv, _wgetargv )( + int historical, CHAR_TYPE *exe, CHAR_TYPE *cmd, + int *pargc, CHAR_TYPE ***pargv ) +{ + unsigned argc; /* argument count */ + CHAR_TYPE **argv; /* Actual arguments */ + CHAR_TYPE *endptr; /* ptr to end of command line */ + unsigned len; /* length of command line */ + CHAR_TYPE *cmdline; /* copy of command line */ + unsigned size; /* amount to allocate */ + unsigned argv_offset; /* offset of argv in storage */ + + argc = _SplitParms( historical, cmd, NULL, &endptr ) + 1; + len = (unsigned) ( endptr - cmd ) + 1; + argv_offset = __ALIGN_SIZE(len * sizeof(CHAR_TYPE)); + size = argv_offset + (argc+1) * sizeof(CHAR_TYPE *); + // round up size for alignment of argv pointer + size = __ALIGN_SIZE( size ); + + #if defined(__REAL_MODE__) && defined(__BIG_DATA__) + #if defined(__OS2_286__) + if( _osmode == DOS_MODE ) { + cmdline = lib_nmalloc( size ); + if( (void _WCI86NEAR *) cmdline == NULL ) { + cmdline = lib_malloc( size ); + } + } else { + cmdline = lib_malloc( size ); + } + #else + cmdline = lib_nmalloc( size ); + if( (void _WCI86NEAR *) cmdline == NULL ) { + cmdline = lib_malloc( size ); + } + #endif + #else + cmdline = lib_malloc( size ); + #endif + argv = NULL; + argc = 0; + if( cmdline ) { + memcpy( cmdline, cmd, len * sizeof(CHAR_TYPE) ); + argv = (void *) ( ( ( char*) cmdline ) + argv_offset ); + argv[0] = exe; + argc = _SplitParms( historical, cmdline, argv + 1, &endptr ) + 1; + argv[argc] = NULL; + } + *pargc = argc; + *pargv = argv; + return( cmdline ); +} + + +static unsigned _SplitParms( int historical, CHAR_TYPE *p, CHAR_TYPE **argv, CHAR_TYPE **endptr ) +{ + register unsigned argc; + register CHAR_TYPE *start; + register CHAR_TYPE *new; + enum QUOTE_STATE { + QUOTE_NONE, /* no " active in current parm */ + QUOTE_DELIMITER, /* " was first char and must be last */ + QUOTE_STARTED /* " was seen, look for a match */ + }; + register enum QUOTE_STATE state; + + argc = 0; + for(;;) { + while( *p == ' ' || *p == '\t' ) { + ++p; /* skip over blanks or tabs */ + } + if( *p == '\0' ) break; + /* we are at the start of a parm */ + state = QUOTE_NONE; + if( *p == '\"' ) { + p++; + state = QUOTE_DELIMITER; + } + new = start = p; + for(;;) { + if( *p == '\"' ) { + if( !historical ) { + p++; + if( state == QUOTE_NONE ) { + state = QUOTE_STARTED; + } else { + state = QUOTE_NONE; + } + continue; + } else { + if( state == QUOTE_DELIMITER ) { + break; + } + } + } + if( *p == ' ' || *p == '\t' ) { + if( state == QUOTE_NONE ) { + break; + } + } + if( *p == '\0' ) break; + if( *p == '\\' ) { + if( !historical ) { + if( p[1] == '\"' ) { + ++p; + if( p[-2] == '\\' ) { + continue; + } + } + } else { + if( p[1] == '\"' || p[1] == '\\' && state == QUOTE_DELIMITER ) { + ++p; + } + } + } + if( argv ) { + *(new++) = *p; + } + ++p; + } + if( argv ) { + argv[ argc ] = start; + ++argc; + + /* + The *new = '\0' is req'd in case there was a \" to " + translation. It must be after the *p check against + '\0' because new and p could point to the same char + in which case the scan would be terminated too soon. + */ + + if( *p == '\0' ) { + *new = '\0'; + break; + } + *new = '\0'; + ++p; + } else { + ++argc; + if( *p == '\0' ) { + break; + } + ++p; + } + } + *endptr = p; + return( argc ); +} + +void __F_NAME(__Fini_Argv,__wFini_Argv)( void ) +{ + if( __F_NAME(__CmdLine,__wCmdLine) != NULL ) { + lib_free( __F_NAME(__CmdLine,__wCmdLine) ); + } +} +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/initfini.h b/programs/develop/open watcom/trunk/clib/crt/initfini.h new file mode 100644 index 0000000000..e566c6ba66 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/initfini.h @@ -0,0 +1,86 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Init/Fini routines delcarations. +* +****************************************************************************/ + + +#ifndef _INITFINI_H_INCLUDED +#define _INITFINI_H_INCLUDED + +#include "variety.h" +#include "rtinit.h" + +#if defined(__386__) + #define __PARMREG1 eax + #define __PARMREG2 edx +#elif defined(M_I86) + #define __PARMREG1 ax + #define __PARMREG2 dx +#else + #define __PARMREG1 + #define __PARMREG2 +#endif + +extern void __InitRtns( unsigned ); +// - takes priority limit parm in __PARMREG1 +// code will run init routines whose +// priority is <= __PARMREG1 (really [0-255]) +// __PARMREG1==255 -> run all init routines +// __PARMREG1==15 -> run init routines whose priority is <= 15 +#if defined(_M_IX86) + #pragma aux __InitRtns "*" parm [__PARMREG1] + #if !defined(__386__) + extern void _WCI86FAR __FInitRtns(unsigned); + #pragma aux __FInitRtns "*" parm [__PARMREG1] + #endif +#endif + +extern void __FiniRtns(unsigned,unsigned); +// - takes priority limit range in __PARMREG1, __PARMREG2 +// code will run fini routines whose +// priority is >= __PARMREG1 (really [0-255]) and +// <= __PARMREG2 (really [0-255]) +// __PARMREG1==0 ,__PARMREG2==255 -> run all fini routines +// __PARMREG1==16,__PARMREG2==255 -> run fini routines in range 16...255 +// __PARMREG1==16,__PARMREG2==40 -> run fini routines in range 16...40 +#if defined(_M_IX86) + #pragma aux __FiniRtns "*" parm [__PARMREG1] [__PARMREG2] + #if !defined(__386__) + extern void _WCI86FAR __FFiniRtns( unsigned, unsigned ); + #pragma aux __FFiniRtns "*" parm [__PARMREG1] [__PARMREG2] + #endif +#endif + +#if defined(__OS2__) && defined(__386__) + #define EXIT_PRIORITY_CLIB 0x00009F00 +#endif + +#undef __PARMREG1 +#undef __PARMREG2 + +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/initrtns.c b/programs/develop/open watcom/trunk/clib/crt/initrtns.c new file mode 100644 index 0000000000..6ba81587fa --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/initrtns.c @@ -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: Initialization and termination of clib. +* +****************************************************************************/ + + +#include "variety.h" +#include "initfini.h" +#include "rtinit.h" + +#define PNEAR ((__type_rtp)0) +#define PFAR ((__type_rtp)1) +#define PDONE ((__type_rtp)2) + +#if ( COMP_CFG_COFF == 1 ) || defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) + // following is an attempt to drop the need for an assembler + // segment definitions file + // unfortunately, the use of XIB,XIE,YIB,YIE doesn't get the + // right sort of segments by default + #pragma data_seg( ".rtl$xib", "DATA" ); + YIXI( TS_SEG_XIB, _Start_XI, 0, 0 ) + #pragma data_seg( ".rtl$xie", "DATA" ); + YIXI( TS_SEG_XIE, _End_XI, 0, 0 ) + #pragma data_seg( ".rtl$yib", "DATA" ); + YIXI( TS_SEG_YIB, _Start_YI, 0, 0 ) + #pragma data_seg( ".rtl$yie", "DATA" ); + YIXI( TS_SEG_YIE, _End_YI, 0, 0 ) + #pragma data_seg( ".data", "DATA" ); +#elif defined(_M_IX86) + extern struct rt_init _Start_XI; + extern struct rt_init _End_XI; + + extern struct rt_init _Start_YI; + extern struct rt_init _End_YI; +#else + #error unsupported platform +#endif + +typedef void (*pfn)(void); +typedef void (_WCI86FAR * _WCI86FAR fpfn)(void); +typedef void (_WCI86NEAR * _WCI86NEAR npfn)(void); + +#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) + #define __GETDS() + #define save_ds() + #define restore_ds() + #define save_es() + #define restore_es() + #define setup_es() +#elif defined(__WINDOWS_386__) + #define __GETDS() + #define save_ds() + #define restore_ds() + #define save_es() + #define restore_es() + #define setup_es() +#elif defined(__386__) + #define __GETDS() + #define save_ds() + #define restore_ds() +#if defined(__FLAT__) + #define save_es() + #define restore_es() + #define setup_es() +#else + extern void save_es( void ); + #pragma aux save_es = modify exact [es]; + extern void restore_es( void ); + #pragma aux restore_es = modify exact [es]; + extern void setup_es( void ); + #pragma aux setup_es = \ + "push ds" \ + "pop es" \ + modify exact [es]; +#endif +#elif defined(M_I86) + extern void save_dx( void ); + #pragma aux save_dx = modify exact [dx]; + extern void _WCI86NEAR __GETDS( void ); + #pragma aux __GETDS "__GETDS"; + extern void save_ds( void ); + #pragma aux save_ds = "push ds" modify exact [sp]; + extern void restore_ds( void ); + #pragma aux restore_ds = "pop ds" modify exact [sp]; + #define save_es() + #define restore_es() +#else + #error unsupported platform +#endif + +#if defined(M_I86) +static void callit_near( npfn *f ) { + // don't call a null pointer + if( *f ) { + save_dx(); + save_ds(); + // call function + (void)(**f)(); + restore_ds(); + } +} + +static void callit_far( fpfn _WCI86NEAR *f ) { + // don't call a null pointer + if( *f ) { + save_ds(); + // call function + (void)(**f)(); + restore_ds(); + } +} +#else +static void callit( pfn *f ) { + // don't call a null pointer + if( *f ) { + // QNX needs es==ds + setup_es(); + // call function + (void)(**f)(); + } +} +#endif + +/* +; - takes priority limit parm in eax, code will run init routines whose +; priority is < eax (really al [0-255]) +; eax==255 -> run all init routines +; eax==15 -> run init routines whose priority is <= 15 +; +*/ + +void __InitRtns( unsigned limit ) { + __type_rtp local_limit; + struct rt_init _WCI86NEAR *pnext; + save_ds(); + save_es(); + __GETDS(); + + local_limit = (__type_rtp)limit; + for(;;) { + { + __type_rtp working_limit; + struct rt_init _WCI86NEAR *pcur; + + pcur = (struct rt_init _WCI86NEAR*)&_Start_XI; + #if defined(COMP_CFG_COFF) + pcur++; + #endif + pnext = (struct rt_init _WCI86NEAR*)&_End_XI; + working_limit = local_limit; + + // walk list of routines + while( pcur < (struct rt_init _WCI86NEAR*)&_End_XI ) + { + // if this one hasn't been called + if( pcur->rtn_type != PDONE ) { + // if the priority is better than best so far + if( pcur->priority <= working_limit ) + { + // remember this one + pnext = pcur; + working_limit = pcur->priority; + } + } + // advance to next entry + pcur++; + } + // check to see if all done, if we didn't find any + // candidates then we can return + if( pnext == (struct rt_init _WCI86NEAR*)&_End_XI ) { + break; + } + } +#if defined(M_I86) + if( pnext->rtn_type == PNEAR ) { + callit_near( (npfn *)&pnext->rtn ); + } else { + callit_far( (fpfn _WCI86NEAR *)&pnext->rtn ); + } +#else + callit( &pnext->rtn ); +#endif + // mark entry as invoked + pnext->rtn_type = PDONE; + } + restore_es(); + restore_ds(); +} + +/* +; - takes priority range parms in eax, edx, code will run fini routines whose +; priority is >= eax (really al [0-255]) and <= edx (really dl [0-255]) +; eax==0, edx=255 -> run all fini routines +; eax==16, edx=255 -> run fini routines in range 16..255 +; eax==16, edx=40 -> run fini routines in range 16..40 +*/ +#if defined(M_I86) +void _WCI86FAR __FFiniRtns( unsigned min_limit, unsigned max_limit ) { + __FiniRtns( min_limit, max_limit ); +} +#endif + +void __FiniRtns( unsigned min_limit, unsigned max_limit ) +{ + __type_rtp local_min_limit; + __type_rtp local_max_limit; + struct rt_init _WCI86NEAR *pnext; + save_ds(); + save_es(); + __GETDS(); + + local_min_limit = (__type_rtp)min_limit; + local_max_limit = (__type_rtp)max_limit; + for(;;) { + { + __type_rtp working_limit; + struct rt_init _WCI86NEAR *pcur; + + pcur = (struct rt_init _WCI86NEAR*)&_Start_YI; + #if defined(COMP_CFG_COFF) + pcur++; + #endif + pnext = (struct rt_init _WCI86NEAR*)&_End_YI; + working_limit = local_min_limit; + + // walk list of routines + while( pcur < (struct rt_init _WCI86NEAR*)&_End_YI ) + { + // if this one hasn't been called + if( pcur->rtn_type != PDONE ) { + // if the priority is better than best so far + if( pcur->priority >= working_limit ) + { + // remember this one + pnext = pcur; + working_limit = pcur->priority; + } + } + // advance to next entry + pcur++; + } + // check to see if all done, if we didn't find any + // candidates then we can return + if( pnext == (struct rt_init _WCI86NEAR*)&_End_YI ) { + break; + } + } + if( pnext->priority <= local_max_limit ) { +#if defined(M_I86) + if( pnext->rtn_type == PNEAR ) { + callit_near( (npfn *)&pnext->rtn ); + } else { + callit_far( (fpfn _WCI86NEAR *)&pnext->rtn ); + } +#else + callit( &pnext->rtn ); +#endif + } + // mark entry as invoked even if we don't call it + // if we didn't call it, it is because we don't want to + // call finirtns with priority > max_limit, in that case + // marking the function as called, won't hurt anything + pnext->rtn_type = PDONE; + } + restore_es(); + restore_ds(); +} + diff --git a/programs/develop/open watcom/trunk/clib/crt/kmain.c b/programs/develop/open watcom/trunk/clib/crt/kmain.c new file mode 100644 index 0000000000..03fca65270 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/kmain.c @@ -0,0 +1,33 @@ + +#include "variety.h" +#include "initfini.h" + +_WCRTLINKD extern char *LpCmdLine; /* pointer to command line */ +_WCRTLINKD extern char *LpPgmName; /* pointer to program name */ +_WCRTLINKD int ___Argc; /* argument count */ +_WCRTLINKD char * ___Argv[2]; /* argument vector */ +_WCRTLINK void exit( int status ); + +_WCRTLINK extern void (*__process_fini)( unsigned, unsigned ); + +extern int main( int, char ** ); + +#pragma aux __KolibriMain "*"; + +void __KolibriMain(void ) +/***************************************/ +{ ___Argc = 2; + ___Argv[0] = LpPgmName; + ___Argv[1] = LpCmdLine; + +// __process_fini = &__FiniRtns; + __InitRtns( 255 ); +// __CommonInit(); + exit( main( ___Argc, ___Argv ) ); + +} + + + + + diff --git a/programs/develop/open watcom/trunk/clib/crt/langenv.h b/programs/develop/open watcom/trunk/clib/crt/langenv.h new file mode 100644 index 0000000000..fb4a7a7bfc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/langenv.inc b/programs/develop/open watcom/trunk/clib/crt/langenv.inc new file mode 100644 index 0000000000..a4445b693e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/langenv.inc @@ -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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +COMP_CFG_COFF equ 0 diff --git a/programs/develop/open watcom/trunk/clib/crt/langenvd.h b/programs/develop/open watcom/trunk/clib/crt/langenvd.h new file mode 100644 index 0000000000..b9d2ebcea1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/main2wnt.c b/programs/develop/open watcom/trunk/clib/crt/main2wnt.c new file mode 100644 index 0000000000..b757973c46 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/main2wnt.c @@ -0,0 +1,105 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR 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 __NTMain(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include +#include +#include +//#include "ntex.h" +//#include "sigtab.h" +#include "initfini.h" +#include "initarg.h" + +void _cdecl mf_init(); +void _stdcall InitHeap(int heap_size); +int __appcwdlen; +char* __appcwd; + +_WCRTLINK void (*__process_fini)(unsigned,unsigned) = 0; + +extern void __CommonInit( void ); +extern int wmain( int, wchar_t ** ); +extern int main( int, char ** ); +extern char *LpCmdLine; +extern char *LpPgmName; + +void __F_NAME(__NTMain,__wNTMain)( void ) +/***************************************/ +{ + + InitHeap(32*1024*1024); + //mf_init(); + + + __process_fini = &__FiniRtns; + __InitRtns( 255 ); + __CommonInit(); + + __appcwdlen = strrchr(_LpPgmName, '/') - _LpPgmName + 1; + __appcwdlen = __appcwdlen > 512 ? 512 : __appcwdlen; + __appcwd= (char*)malloc(__appcwdlen); + strncpy(__appcwd, _LpPgmName, __appcwdlen); + __appcwd[__appcwdlen] = 0; + ___Argc = 2; + ___Argv[0] = _LpPgmName; + ___Argv[1] = _LpCmdLine; + + #ifdef __WIDECHAR__ + exit( wmain( ___wArgc, ___wArgv ) ); + #else + exit( main( ___Argc, ___Argv ) ); + #endif +} + +#ifdef __WIDECHAR__ + #if defined(_M_IX86) + #pragma aux __wNTMain "*" + #endif +#else + #if defined(_M_IX86) + #pragma aux __NTMain "*" + #endif +#endif + +_WCRTLINK void __exit( unsigned ret_code ) +{ + __FiniRtns( 0, FINI_PRIORITY_EXIT-1 ); + _asm + { + mov eax, -1 + int 0x40 + } +} + + diff --git a/programs/develop/open watcom/trunk/clib/crt/mdef.inc b/programs/develop/open watcom/trunk/clib/crt/mdef.inc new file mode 100644 index 0000000000..ddd5ecf644 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 +_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 + 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 + public p1 + else + public "&p1",p2 + endif + endm + +xref macro p1,p2 + ifb + 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 + extrn p1 : dword + else + extrn "&p1",p2 : dword + endif + else + ifb + 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 + public p1 + else + public "&p1",p2 + endif + endm + +xref macro p1,p2 + ifb + 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 + xref "C",_&alias + else + xref "C",function + endif + .code + public "C",`alias` + ifdef _EXPORT + `alias` proc export + else + `alias` proc + endif + ifb + jmp _&alias + else + jmp `function` + endif + `alias` endp + endm + +xred macro p1,p2,p3 + ifb + extrn p1 : p2 + else + extrn "&p1",p2 : p3 + endif + endm + diff --git a/programs/develop/open watcom/trunk/clib/crt/rtdata.h b/programs/develop/open watcom/trunk/clib/crt/rtdata.h new file mode 100644 index 0000000000..f218987f46 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 +#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 diff --git a/programs/develop/open watcom/trunk/clib/crt/rtinit.h b/programs/develop/open watcom/trunk/clib/crt/rtinit.h new file mode 100644 index 0000000000..73d2f48644 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/save8087.c b/programs/develop/open watcom/trunk/clib/crt/save8087.c new file mode 100644 index 0000000000..f68f51be14 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/save8087.c @@ -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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "87state.h" +#include "rtdata.h" + +static void _do_nothing( _87state *st ) {} + +void (*_RWD_Save8087)(_87state *) = _do_nothing; +void (*_RWD_Rest8087)(_87state *) = _do_nothing; diff --git a/programs/develop/open watcom/trunk/clib/crt/segdefns.asm b/programs/develop/open watcom/trunk/clib/crt/segdefns.asm new file mode 100644 index 0000000000..af0b96e9cc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/segdefns.asm @@ -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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +; segment definitions for WATCOM C/C++32 +; +include langenv.inc + + name segdefns +.386p + + assume nothing + + +if COMP_CFG_COFF +DGROUP group _NULL,_AFTERNULL,CONST,_DATA,DATA,_BSS,STACK +else +ifdef __LINUX__ +DGROUP group _NULL,_AFTERNULL,CONST,_DATA,DATA,TIB,TI,TIE,XIB,XI,XIE,YIB,YI,YIE,_BSS +else +DGROUP group _NULL,_AFTERNULL,CONST,_DATA,DATA,_BSS,STACK,TIB,TI,TIE,XIB,XI,XIE,YIB,YI,YIE +endif +endif + +; this guarantees that no function pointer will equal NULL +; (WLINK will keep segment 'BEGTEXT' in front) +; This segment must be at least 4 bytes in size to avoid confusing the +; signal function. + +BEGTEXT segment use32 word public 'CODE' + assume cs:BEGTEXT +forever label near + int 3h + jmp short forever + ; NOTE that __begtext needs to be at offset 3 + ; don't move it. i.e. don't change any code before here. +___begtext label byte + nop + nop + nop + nop + public ___begtext + assume cs:nothing +BEGTEXT ends + + assume ds:DGROUP + +_NULL segment para public 'BEGDATA' +__nullarea label word + db 01h,01h,01h,00h + public __nullarea +_NULL ends + +_AFTERNULL segment word public 'BEGDATA' +_AFTERNULL ends + +CONST segment word public 'DATA' +CONST ends + +if COMP_CFG_COFF eq 0 +TIB segment byte public 'DATA' +TIB ends +TI segment byte public 'DATA' +TI ends +TIE segment byte public 'DATA' +TIE ends + +XIB segment word public 'DATA' +_Start_XI label byte + public "C",_Start_XI +XIB ends +XI segment word public 'DATA' +XI ends +XIE segment word public 'DATA' +_End_XI label byte + public "C",_End_XI +XIE ends + +YIB segment word public 'DATA' +_Start_YI label byte + public "C",_Start_YI +YIB ends +YI segment word public 'DATA' +YI ends +YIE segment word public 'DATA' +_End_YI label byte + public "C",_End_YI +YIE ends +endif + +_DATA segment word public 'DATA' +_DATA ends + +DATA segment word public 'DATA' +DATA ends + +_BSS segment word public 'BSS' +_BSS ends + +ifndef __LINUX__ +STACK_SIZE equ 4096h + +STACK segment para stack 'STACK' + db (STACK_SIZE) dup(?) +STACK ends +endif + +_TEXT segment use32 word public 'CODE' +_TEXT ends + + end diff --git a/programs/develop/open watcom/trunk/clib/crt/setefg.c b/programs/develop/open watcom/trunk/clib/crt/setefg.c new file mode 100644 index 0000000000..3788fffcba --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 +#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 +} diff --git a/programs/develop/open watcom/trunk/clib/crt/stacklow.h b/programs/develop/open watcom/trunk/clib/crt/stacklow.h new file mode 100644 index 0000000000..67110767a5 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/stacklow.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 _STACKLOW_H_INCLUDED +#define _STACKLOW_H_INCLUDED + +#define __Align4K( x ) (((x)+0xfffL) & ~0xfffL ) + +#if defined(_M_IX86) + extern unsigned _SP(); + #if defined(__386__) + #pragma aux _SP = "mov eax,esp" value [eax]; + #else + #pragma aux _SP = "mov ax,sp" value [ax]; + #endif +#endif + +#if defined(__NT__) + void __init_stack_limits( unsigned *stacklow, unsigned *stacktop ); +#endif + +#if defined(__SW_BM) + #include "thread.h" + #define _STACKLOW (__THREADDATAPTR->__stklowP) +#else + extern unsigned _STACKLOW; +#endif + +#endif + diff --git a/programs/develop/open watcom/trunk/clib/crt/stackwnt.c b/programs/develop/open watcom/trunk/clib/crt/stackwnt.c new file mode 100644 index 0000000000..c279749613 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/stackwnt.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: Dummy stack check routines for non-x86 Win32 platforms. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" +#include "stacklow.h" +#include "exitwmsg.h" + +#if defined(__AXP__) || defined(__PPC__) +void _init_stk( void ) +{ +} + +_WCRTLINK unsigned __CHK( unsigned i ) +{ + return( i ); +} + +_WCRTLINK void __GRO( unsigned i ) +{ + i = i; +} + +_WCRTLINK void __STKOVERFLOW( void ) +{ + __fatal_runtime_error( "stack overflow", -1 ); +} +#endif + +_WCRTLINK unsigned stackavail() +{ +#if defined(__AXP__) || defined(__PPC__) + unsigned _SP; + + _SP = (unsigned)&_SP; + return( _SP - _RWD_stacklow ); +#else + return( _SP() - _RWD_stacklow ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/crt/stkwnt.asm b/programs/develop/open watcom/trunk/clib/crt/stkwnt.asm new file mode 100644 index 0000000000..079908b81e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/stkwnt.asm @@ -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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc +include xinit.inc +include exitwmsg.inc + + modstart stk + + datasegment + extrn "C",_STACKLOW : dword +msg db "Stack Overflow!", 0dh, 0ah, 0 + enddata + + xinit _init_stk,DEF_PRIORITY + + assume ds:DGROUP + + + defp _init_stk + ret ; return + endproc _init_stk + + + xdefp __CHK + defpe __CHK ; new style stack check + xchg eax,4[esp] ; get parm in eax + call __STK ; call stack checker + mov eax,4[esp] ; restore eax + ret 4 + endproc __CHK + + xdefp __STK + defpe __STK + push eax ; save parm for __GRO routine + _guess ; guess: no overflow + cmp eax,esp ; - quit if user asking for too much + _quif ae ; - ... + sub eax,esp ; - calculate new low point + neg eax ; - calc what new SP would be + cmp eax,_STACKLOW ; - quit if too much + _quif be ; - ... + call __GRO ; - return + ret + _endguess ; endguess + +__STKOVERFLOW: + xdefp "C",__STKOVERFLOW + pop eax ; pop the stack +ifdef __STACK__ + push 1 ; ... + push offset msg ; print the error message +else + mov eax,offset msg ; print the error message + mov edx,1 ; ... +endif + call __fatal_runtime_error ; ... + endproc __STK + + xdefp __GRO + defpe __GRO ; dummy function to resolve symbol + push eax ; save regs + push ebx ; ... + mov eax,12[esp] ; get size to grow by + mov ebx,-4 ; initialiaze index +lup: ; do { + mov [esp+ebx],ebx ; - touch that stack page + sub ebx,1000H ; - decrement by 4k + sub eax,1000H ; - decrement by 4k + jg lup ; } while stack left to go + pop ebx ; restore regs + pop eax ; ... + ret 4 ; return to caller + endproc __GRO + + xdefp __alloca_probe + ; on entry eax is size of stack to grow + ; on exit esp has been advanced to new size + defpe __alloca_probe ; ms compatible function + push eax ; size parm to __GRO + call __GRO + push eax ; save size + lea eax,8[esp] ; get esp value to adjust + sub eax,[esp] ; carve off piece of stack + xchg eax,esp ; set new esp + mov eax,4[eax] ; snag return address + jmp eax ; return to caller + endproc __alloca_probe + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/crt/struct.inc b/programs/develop/open watcom/trunk/clib/crt/struct.inc new file mode 100644 index 0000000000..2d88e461ef --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 = __label + endif + endm + +_quif macro cc,name + ifnb + _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 + _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 diff --git a/programs/develop/open watcom/trunk/clib/crt/variety.h b/programs/develop/open watcom/trunk/clib/crt/variety.h new file mode 100644 index 0000000000..fecec0e16c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 diff --git a/programs/develop/open watcom/trunk/clib/crt/widechar.h b/programs/develop/open watcom/trunk/clib/crt/widechar.h new file mode 100644 index 0000000000..7e99f9c3ca --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 /* 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 diff --git a/programs/develop/open watcom/trunk/clib/crt/xfloat.h b/programs/develop/open watcom/trunk/clib/crt/xfloat.h new file mode 100644 index 0000000000..558b99c42a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/xfloat.h @@ -0,0 +1,479 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: C/C++ run-time library floating-point definitions. +* +****************************************************************************/ + + +#ifndef _XFLOAT_H_INCLUDED +#define _XFLOAT_H_INCLUDED + +#include // for wchar_t +#include // for LDBL_DIG + +#ifdef __cplusplus +extern "C" { +#endif + +#if (defined(__386__) || defined(M_I86)) && defined(__WATCOMC__) + #define _LONG_DOUBLE_ +#endif + +typedef struct { // This layout matches Intel 8087 + #ifdef _LONG_DOUBLE_ + unsigned long low_word; // - low word of fraction + unsigned long high_word; // - high word of fraction + unsigned short exponent; // - exponent and sign + #else // use this for all other 32-bit RISC + union { + double value; // - double value + unsigned long word[2];// - so we can access bits + }; + #endif +} long_double; + +typedef struct { // Layout of IEEE 754 double (FD) + union { + double value; // - double value + unsigned long word[2];// - so we can access bits + }; +} float_double; + +typedef struct { // Layout of IEEE 754 single (FS) + union { + float value; // - double value + unsigned long word; // - so we can access bits + }; +} float_single; + +/* NB: The following values *must* match FP_ macros in math.h! */ +enum ld_classification { + __ZERO = 0, + __DENORMAL = 1, + __NONZERO = 2, + __NAN = 3, + __INFINITY = 4 +}; + +enum ldcvt_flags { + E_FMT = 0x0001, // 'E' format + F_FMT = 0x0002, // 'F' format + G_FMT = 0x0004, // 'G' format + F_CVT = 0x0008, // __cvt routine format rules + F_DOT = 0x0010, // always put '.' in result + LONG_DOUBLE = 0x0020, // number is true long double + NO_TRUNC = 0x0040, // always provide ndigits in buffer + IN_CAPS = 0x0080, // 'inf'/'nan' is uppercased +}; + +typedef struct cvt_info { + int ndigits; // INPUT: number of digits + int scale; // INPUT: FORTRAN scale factor + int flags; // INPUT: flags (see ldcvt_flags) + int expchar; // INPUT: exponent character to use + int expwidth; // INPUT/OUTPUT: number of exponent digits + int sign; // OUTPUT: 0 => +ve; otherwise -ve + int decimal_place; // OUTPUT: position of '.' + int n1; // OUTPUT: number of leading characters + int nz1; // OUTPUT: followed by this many '0's + int n2; // OUTPUT: followed by these characters + int nz2; // OUTPUT: followed by this many '0's +} CVT_INFO; + +_WMRTLINK extern void __LDcvt( + long_double *pld, // pointer to long_double + CVT_INFO *cvt, // conversion info + char *buf ); // buffer +#if defined( __WATCOMC__ ) +_WMRTLINK extern int __Strtold( + const char *bufptr, + long_double *pld, + char **endptr ); +#endif +extern int __LDClass( long_double * ); +extern void __ZBuf2LD(char _WCNEAR *, long_double _WCNEAR *); +extern void _LDScale10x(long_double _WCNEAR *,int); +_WMRTLINK extern void __cnvd2ld( double _WCNEAR *src, long_double _WCNEAR *dst ); +_WMRTLINK extern void __cnvs2d( char *buf, double *value ); +_WMRTLINK extern int __cnvd2f( double *src, float *tgt ); +#ifdef _LONG_DOUBLE_ +extern void __iLDFD(long_double _WCNEAR *, double _WCNEAR *); +extern void __iLDFS(long_double _WCNEAR *, float _WCNEAR *); +extern void __iFDLD(double _WCNEAR *,long_double _WCNEAR *); +extern void __iFSLD(float _WCNEAR *,long_double _WCNEAR *); +extern long __LDI4(long_double _WCNEAR *); +extern void __I4LD(long,long_double _WCNEAR *); +extern void __U4LD(unsigned long,long_double _WCNEAR *); +extern void __FLDA(long_double _WCNEAR *,long_double _WCNEAR *,long_double _WCNEAR *); +extern void __FLDS(long_double _WCNEAR *,long_double _WCNEAR *,long_double _WCNEAR *); +extern void __FLDM(long_double _WCNEAR *,long_double _WCNEAR *,long_double _WCNEAR *); +extern void __FLDD(long_double _WCNEAR *,long_double _WCNEAR *,long_double _WCNEAR *); +extern int __FLDC(long_double _WCNEAR *,long_double _WCNEAR *); +#endif + +#ifdef __WATCOMC__ +#if defined(__386__) + #pragma aux __ZBuf2LD "*" parm caller [eax] [edx]; + #if defined(__FPI__) + extern unsigned __Get87CW(void); + extern void __Set87CW(unsigned short); + #pragma aux __Get87CW = \ + "push 0"\ + float "fstcw [esp]"\ + float "fwait"\ + "pop eax"\ + value [eax]; + #pragma aux __Set87CW = \ + "push eax"\ + float "fldcw [esp]"\ + "pop eax"\ + parm caller [eax]; + #pragma aux __FLDA = \ + float "fld tbyte ptr [eax]"\ + float "fld tbyte ptr [edx]"\ + float "fadd"\ + float "fstp tbyte ptr [ebx]"\ + parm caller [eax] [edx] [ebx]; + #pragma aux __FLDS = \ + float "fld tbyte ptr [eax]"\ + float "fld tbyte ptr [edx]"\ + float "fsub"\ + float "fstp tbyte ptr [ebx]"\ + parm caller [eax] [edx] [ebx]; + #pragma aux __FLDM = \ + float "fld tbyte ptr [eax]"\ + float "fld tbyte ptr [edx]"\ + float "fmul"\ + float "fstp tbyte ptr [ebx]"\ + parm caller [eax] [edx] [ebx]; + #pragma aux __FLDD = \ + float "fld tbyte ptr [eax]"\ + float "fld tbyte ptr [edx]"\ + float "fdiv"\ + float "fstp tbyte ptr [ebx]"\ + parm caller [eax] [edx] [ebx]; + #pragma aux __FLDC = \ + /* ST(1) */\ + float "fld tbyte ptr [edx]"\ + /* ST(0) */\ + float "fld tbyte ptr [eax]"\ + /* compare ST(0) with ST(1) */\ + float "fcompp"\ + float "fstsw ax"\ + "sahf"\ + "sbb edx,edx"\ + "shl edx,1"\ + "shl ah,2"\ + "cmc"\ + "adc edx,0"\ + /* edx will be -1,0,+1 if [eax] <, ==, > [edx] */\ + parm caller [eax] [edx] value [edx]; + #pragma aux __LDI4 = \ + float "fld tbyte ptr [eax]"\ + "push eax"\ + "push eax"\ + float "fstcw [esp]"\ + float "fwait"\ + "pop eax"\ + "push eax"\ + "or ah,0x0c"\ + "push eax"\ + float "fldcw [esp]"\ + "pop eax"\ + float "fistp dword ptr 4[esp]"\ + float "fldcw [esp]"\ + "pop eax"\ + "pop eax"\ + parm caller [eax] value [eax]; + #pragma aux __I4LD = \ + "push eax"\ + float "fild dword ptr [esp]"\ + "pop eax"\ + float "fstp tbyte ptr [edx]"\ + parm caller [eax] [edx]; + #pragma aux __U4LD = \ + "push 0"\ + "push eax"\ + float "fild qword ptr [esp]"\ + "pop eax"\ + "pop eax"\ + float "fstp tbyte ptr [edx]"\ + parm caller [eax] [edx]; + #pragma aux __iFDLD = \ + float "fld qword ptr [eax]"\ + float "fstp tbyte ptr [edx]"\ + parm caller [eax] [edx]; + #pragma aux __iFSLD = \ + float "fld dword ptr [eax]"\ + float "fstp tbyte ptr [edx]"\ + parm caller [eax] [edx]; + #pragma aux __iLDFD = \ + float "fld tbyte ptr [eax]"\ + float "fstp qword ptr [edx]"\ + parm caller [eax] [edx]; + #pragma aux __iLDFS = \ + float "fld tbyte ptr [eax]"\ + float "fstp dword ptr [edx]"\ + parm caller [eax] [edx]; + #else // floating-point calls + #pragma aux __FLDA "*" parm caller [eax] [edx] [ebx]; + #pragma aux __FLDS "*" parm caller [eax] [edx] [ebx]; + #pragma aux __FLDM "*" parm caller [eax] [edx] [ebx]; + #pragma aux __FLDD "*" parm caller [eax] [edx] [ebx]; + #pragma aux __LDI4 "*" parm caller [eax] value [eax]; + #pragma aux __I4LD "*" parm caller [eax] [edx]; + #pragma aux __U4LD "*" parm caller [eax] [edx]; + #pragma aux __iFDLD "*" parm caller [eax] [edx]; + #pragma aux __iFSLD "*" parm caller [eax] [edx]; + #pragma aux __iLDFD "*" parm caller [eax] [edx]; + #pragma aux __iLDFS "*" parm caller [eax] [edx]; + #pragma aux __FLDC "*" parm caller [eax] [edx] value [eax]; + #endif +#elif defined(M_I86) // 16-bit pragmas + #pragma aux __ZBuf2LD "*" parm caller [ax] [dx]; + #if defined(__FPI__) + extern unsigned __Get87CW(void); + extern void __Set87CW(unsigned short); + #pragma aux __Get87CW = \ + "push ax"\ + "push bp"\ + "mov bp,sp"\ + float "fstcw 2[bp]"\ + float "fwait"\ + "pop bp"\ + "pop ax"\ + value [ax]; + #pragma aux __Set87CW = \ + "push ax"\ + "push bp"\ + "mov bp,sp"\ + float "fldcw 2[bp]"\ + "pop bp"\ + "pop ax"\ + parm caller [ax]; + #pragma aux __FLDA = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fld tbyte ptr [bp]"\ + float "fadd"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx] [bx]; + #pragma aux __FLDS = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fld tbyte ptr [bp]"\ + float "fsub"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx] [bx]; + #pragma aux __FLDM = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fld tbyte ptr [bp]"\ + float "fmul"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx] [bx]; + #pragma aux __FLDD = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fld tbyte ptr [bp]"\ + float "fdiv"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx] [bx]; + #pragma aux __FLDC = \ + "push bp"\ + "mov bp,dx"\ + /* ST(1) */\ + float "fld tbyte ptr [bp]"\ + "mov bp,ax"\ + /* ST(0) */\ + float "fld tbyte ptr [bp]"\ + /* compare ST(0) with ST(1) */\ + float "fcompp"\ + "push ax"\ + "mov bp,sp"\ + float "fstsw 0[bp]"\ + float "fwait"\ + "pop ax"\ + "sahf"\ + "sbb dx,dx"\ + "shl dx,1"\ + "shl ah,1"\ + "shl ah,1"\ + "cmc"\ + "adc dx,0"\ + "pop bp"\ + parm caller [ax] [dx] value [dx]; + #pragma aux __LDI4 = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "push dx"\ + "push ax"\ + "push ax"\ + "mov bp,sp"\ + float "fstcw [bp]"\ + float "fwait"\ + "pop ax"\ + "push ax"\ + "or ah,0x0c"\ + "mov 2[bp],ax"\ + float "fldcw 2[bp]"\ + float "fistp dword ptr 2[bp]"\ + float "fldcw [bp]"\ + "pop ax"\ + "pop ax"\ + "pop dx"\ + "pop bp"\ + parm caller [ax] value [dx ax]; + #pragma aux __I4LD = \ + "push bp"\ + "push dx"\ + "push ax"\ + "mov bp,sp"\ + float "fild dword ptr [bp]"\ + "pop ax"\ + "pop dx"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [dx ax] [bx]; + #pragma aux __U4LD = \ + "push bp"\ + "push ax"\ + "push ax"\ + "push dx"\ + "push ax"\ + "mov bp,sp"\ + "sub ax,ax"\ + "mov 4[bp],ax"\ + "mov 6[bp],ax"\ + float "fild qword ptr 2[bp]"\ + "pop ax"\ + "pop dx"\ + "pop ax"\ + "pop ax"\ + "mov bp,bx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [dx ax] [bx]; + #pragma aux __iFDLD = \ + "push bp"\ + "mov bp,ax"\ + float "fld qword ptr [bp]"\ + "mov bp,dx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx]; + #pragma aux __iFSLD = \ + "push bp"\ + "mov bp,ax"\ + float "fld dword ptr [bp]"\ + "mov bp,dx"\ + float "fstp tbyte ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx]; + #pragma aux __iLDFD = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fstp qword ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx]; + #pragma aux __iLDFS = \ + "push bp"\ + "mov bp,ax"\ + float "fld tbyte ptr [bp]"\ + "mov bp,dx"\ + float "fstp dword ptr [bp]"\ + "pop bp"\ + parm caller [ax] [dx]; + #else // floating-point calls + #pragma aux __FLDA "*" parm caller [ax] [dx] [bx]; + #pragma aux __FLDS "*" parm caller [ax] [dx] [bx]; + #pragma aux __FLDM "*" parm caller [ax] [dx] [bx]; + #pragma aux __FLDD "*" parm caller [ax] [dx] [bx]; + #pragma aux __LDI4 "*" parm caller [ax] value [dx ax]; + #pragma aux __I4LD "*" parm caller [dx ax] [bx]; + #pragma aux __U4LD "*" parm caller [dx ax] [bx]; + #pragma aux __iFDLD "*" parm caller [ax] [dx]; + #pragma aux __iFSLD "*" parm caller [ax] [dx]; + #pragma aux __iLDFD "*" parm caller [ax] [dx]; + #pragma aux __iLDFS "*" parm caller [ax] [dx]; + #pragma aux __FLDC "*" parm caller [ax] [dx] value [ax]; + #endif +#endif +#endif + +#ifdef _LONG_DOUBLE_ + // macros to allow old source code names to still work + #define __FDLD __iFDLD + #define __FSLD __iFSLD + #define __LDFD __iLDFD + #define __LDFS __iLDFS +#endif + +// define number of significant digits for long double numbers (80-bit) +// it will be defined in float.h as soon as OW support long double +// used in mathlib/c/ldcvt.c + +#ifdef _LONG_DOUBLE_ +#if LDBL_DIG == 15 +#undef LDBL_DIG +#define LDBL_DIG 19 +#else +#error LDBL_DIG has changed from 15 +#endif +#endif + +// floating point conversion buffer length definition +// used by various floating point conversion routines +// used in clib/startup/c/cvtbuf.c and lib_misc/h/thread.h +// it must be equal maximum FP precision ( LDBL_DIG ) + +#define __FPCVT_BUFFERLEN 19 + +#ifdef __cplusplus +}; +#endif +#endif diff --git a/programs/develop/open watcom/trunk/clib/crt/xinit.inc b/programs/develop/open watcom/trunk/clib/crt/xinit.inc new file mode 100644 index 0000000000..141f0846a0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/xinit.inc @@ -0,0 +1,109 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR 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 langenv.inc + +PNEAR equ 0 +PFAR equ 1 + +xinit macro rtn,priority +XI segment word public 'DATA' +if _MODEL and _BIG_CODE + db PFAR + db priority + dd rtn +else +if _MODEL and _USE_32_SEGS + db PNEAR + db priority + dd rtn +if COMP_CFG_COFF EQ 1 + dw 0 +endif +else + db PNEAR + db priority + dw rtn + dw 0 +endif +endif +XI ends + endm + +xfini macro rtn,priority +YI segment word public 'DATA' +if _MODEL and _BIG_CODE + db PFAR + db priority + dd rtn +else +if _MODEL and _USE_32_SEGS + db PNEAR + db priority + dd rtn +if COMP_CFG_COFF EQ 1 + dw 0 +endif +else + db PNEAR + db priority + dw rtn + dw 0 +endif +endif +YI ends + endm + +INIT_PRIORITY_THREAD equ 1 ; priority for thread data init +INIT_PRIORITY_FPU equ 2 ; priority for FPU/EMU init +INIT_PRIORITY_RUNTIME equ 10 ; priority for run-time initialization +INIT_PRIORITY_IOSTREAM equ 20 ; priority for IOSTREAM +INIT_PRIORITY_LIBRARY equ 32 ; default library-initialization priority +DEF_PRIORITY equ 32 ; ... +INIT_PRIORITY_PROGRAM equ 64 ; default program-initialization priority +DTOR_PRIORITY equ 40 ; priority for module DTOR + +DGROUP group XIB,XI,XIE,YIB,YI,YIE + +XIB segment word public 'DATA' +XIB ends +XI segment word public 'DATA' +XI ends +XIE segment word public 'DATA' +XIE ends + +YIB segment word public 'DATA' +YIB ends +YI segment word public 'DATA' +YI ends +YIE segment word public 'DATA' +YIE ends diff --git a/programs/develop/open watcom/trunk/clib/crt/xmsgwnt.c b/programs/develop/open watcom/trunk/clib/crt/xmsgwnt.c new file mode 100644 index 0000000000..a2e64e7cbb --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/xmsgwnt.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: Fatal runtime error handler for Win32. +* +****************************************************************************/ + + +#include "variety.h" +#include "rtdata.h" +#include "exitwmsg.h" + +void debug_out_str(const char* str); + + +_WCRTLINK void __exit_with_msg( char *msg, unsigned retcode ) +{ + + unsigned len; + char *end; + + end = msg; + for( len = 0; *end++ != '\0'; len++ ) + ; + debug_out_str(msg); + __exit( retcode ); +} + +_WCRTLINK void __fatal_runtime_error( char *msg, unsigned retcode ) +{ + __exit_with_msg( msg, retcode ); + +} diff --git a/programs/develop/open watcom/trunk/clib/crt/xstring.h b/programs/develop/open watcom/trunk/clib/crt/xstring.h new file mode 100644 index 0000000000..7dc834a919 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/crt/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 + +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/allocfp.c b/programs/develop/open watcom/trunk/clib/src/allocfp.c new file mode 100644 index 0000000000..14fa1cc2dc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/allocfp.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 +#include +#include +#include "liballoc.h" +#include "fileacc.h" +#include "rtdata.h" +#include "seterrno.h" +#include "streamio.h" + + +#define KEEP_FLAGS (_READ | _WRITE | _DYNAMIC) + +FILE *__allocfp( int handle ) +{ + FILE *end; + FILE *fp; + __stream_link *link; + unsigned flags; + + handle = handle; + _AccessIOB(); + /* Try and take one off the recently closed list */ + link = _RWD_cstream; + if( link != NULL ) { + _RWD_cstream = link->next; + fp = link->stream; + flags = (fp->_flag & KEEP_FLAGS) | (_READ | _WRITE); + goto got_one; + } + /* See if there is a static FILE structure available. */ + end = &_RWD_iob[_NFILES]; + for( fp = _RWD_iob; fp < end; ++fp ) { + if( (fp->_flag & (_READ | _WRITE)) == 0 ) { + link = lib_malloc( sizeof( __stream_link ) ); + if( link == NULL ) + goto no_mem; + flags = _READ | _WRITE; + goto got_one; + } + } + /* Allocate a new dynamic structure */ + flags = _DYNAMIC | _READ | _WRITE; + link = lib_malloc( sizeof( __stream_link ) + sizeof( FILE ) ); + if( link == NULL ) + goto no_mem; + fp = (FILE *)(link + 1); +got_one: + memset( fp, 0, sizeof( *fp ) ); + fp->_flag = flags; + link->stream = fp; + link->stream->_link = link; /* point back to link structure */ + link->next = _RWD_ostream; + _RWD_ostream = link; + _ReleaseIOB(); + return( fp ); +no_mem: + __set_errno( ENOMEM ); + _ReleaseIOB(); + return( NULL ); /* no free slots */ +} diff --git a/programs/develop/open watcom/trunk/clib/src/clibi64.h b/programs/develop/open watcom/trunk/clib/src/clibi64.h new file mode 100644 index 0000000000..c9fb8c7ea3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/close.h b/programs/develop/open watcom/trunk/clib/src/close.h new file mode 100644 index 0000000000..2494fca9e4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 ); diff --git a/programs/develop/open watcom/trunk/clib/src/commode.h b/programs/develop/open watcom/trunk/clib/src/commode.h new file mode 100644 index 0000000000..76af4ba5d6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/commode.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: declaration for set commit mode function +* +****************************************************************************/ + + +/* see note in commode.c */ +_WCRTLINK extern void _WCI86FAR __set_commode( void ); +#pragma aux __set_commode "*_"; diff --git a/programs/develop/open watcom/trunk/clib/src/comtflag.c b/programs/develop/open watcom/trunk/clib/src/comtflag.c new file mode 100644 index 0000000000..d32fc28537 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/comtflag.c @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Commit mode state variable and accessor. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "commode.h" + + +int _commode = 0; + + +/* + * Before changing any of this, check startup/c/commode.c! + */ + +_WCRTLINK void _WCI86FAR __set_commode( void ) +{ + _commode = _COMMIT; +} diff --git a/programs/develop/open watcom/trunk/clib/src/errorno.h b/programs/develop/open watcom/trunk/clib/src/errorno.h new file mode 100644 index 0000000000..f256c6cb49 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + + diff --git a/programs/develop/open watcom/trunk/clib/src/exitwmsg.h b/programs/develop/open watcom/trunk/clib/src/exitwmsg.h new file mode 100644 index 0000000000..38e47c36ac --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/exitwmsg.inc b/programs/develop/open watcom/trunk/clib/src/exitwmsg.inc new file mode 100644 index 0000000000..e849921e90 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/extfunc.h b/programs/develop/open watcom/trunk/clib/src/extfunc.h new file mode 100644 index 0000000000..a7e11fd93e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/farfunc.h b/programs/develop/open watcom/trunk/clib/src/farfunc.h new file mode 100644 index 0000000000..63c876c9f3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/farsupp.h b/programs/develop/open watcom/trunk/clib/src/farsupp.h new file mode 100644 index 0000000000..ab9c4973d0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/fgetc.c b/programs/develop/open watcom/trunk/clib/src/fgetc.c new file mode 100644 index 0000000000..0c0c86aaa4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fgetc.c @@ -0,0 +1,227 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR 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 fgetc() implementation. +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#ifndef __UNIX__ + #include +#endif +#include "fileacc.h" +#include +#include "rtdata.h" +#include "seterrno.h" +#ifdef __WIDECHAR__ + #include + #include +#endif +#include "qread.h" +#include "orient.h" +#include "flush.h" +#include "streamio.h" + + +#define DOS_EOF_CHAR 0x1a + +#ifdef __WIDECHAR__ + #define CHARMASK 0xffff +#else + #define CHARMASK 0xff +#endif + +int __F_NAME(__fill_buffer,__wfill_buffer)( FILE *fp ) +{ + if( _FP_BASE(fp) == NULL ) { + __ioalloc( fp ); + } + if( fp->_flag & _ISTTY ) { /* 20-aug-90 */ + if( fp->_flag & (_IONBF | _IOLBF) ) { + __flushall( _ISTTY ); /* flush all TTY output */ + } + } + fp->_flag &= ~_UNGET; /* 10-mar-90 */ + fp->_ptr = _FP_BASE(fp); +#ifdef __UNIX__ + fp->_cnt = __qread( fileno( fp ), fp->_ptr, + (fp->_flag & _IONBF) ? CHARSIZE : fp->_bufsize ); +#else + if(( fp->_flag & (_IONBF | _ISTTY)) == (_IONBF | _ISTTY) && + ( fileno( fp ) == STDIN_FILENO )) + { + int c; /* JBS 31-may-91 */ + + fp->_cnt = 0; + // c = getche(); + if( c != EOF ) { + *(CHAR_TYPE *)fp->_ptr = c; + fp->_cnt = CHARSIZE; + } + } else { + fp->_cnt = __qread( fileno( fp ), fp->_ptr, + (fp->_flag & _IONBF) ? CHARSIZE : fp->_bufsize ); + } +#endif + if( fp->_cnt <= 0 ) { + if( fp->_cnt == 0 ) { + fp->_flag |= _EOF; + } else { + fp->_flag |= _SFERR; + fp->_cnt = 0; + } + } + return( fp->_cnt ); +} + +int __F_NAME(__filbuf,__wfilbuf)( FILE *fp ) +{ + if( __F_NAME(__fill_buffer,__wfill_buffer)( fp ) == 0 ) { + return( EOF ); + } + else { + fp->_cnt -= CHARSIZE; + fp->_ptr += CHARSIZE; + return( *(CHAR_TYPE *)(fp->_ptr - CHARSIZE) & CHARMASK ); + } +} + + +#ifndef __WIDECHAR__ + +_WCRTLINK int fgetc( FILE *fp ) +{ + int c; + + _ValidFile( fp, EOF ); + _AccessFile( fp ); + + /*** Deal with stream orientation ***/ + ORIENT_STREAM(fp,EOF); + + if( (fp->_flag & _READ) == 0 ) { + __set_errno( EBADF ); + fp->_flag |= _SFERR; + c = EOF; + } else { + fp->_cnt--; + // it is important that this remain a relative comparison + // to ensure that the getc() macro works properly + if( fp->_cnt < 0 ) { + c = __F_NAME(__filbuf,__wfilbuf)( fp ); + } else { + c = *(char *)fp->_ptr; + fp->_ptr++; + } + } +#ifndef __UNIX__ + if( !(fp->_flag & _BINARY) ) { + if( c == '\r' ) { + fp->_cnt--; + // it is important that this remain a relative comparison + // to ensure that the getc() macro works properly + if( fp->_cnt < 0 ) { + c = __F_NAME(__filbuf,__wfilbuf)( fp ); + } else { + c = *(CHAR_TYPE*)fp->_ptr & CHARMASK; + fp->_ptr += CHARSIZE; + } + } + if( c == DOS_EOF_CHAR ) { + fp->_flag |= _EOF; + c = EOF; + } + } +#endif + _ReleaseFile( fp ); + return( c ); +} + +#else + +static int __read_wide_char( FILE *fp, wchar_t *wc ) +/**************************************************/ +{ + if( fp->_flag & _BINARY ) { + /*** Read a wide character ***/ + return( fread( wc, sizeof( wchar_t ), 1, fp ) ); + } else { + char mbc[MB_CUR_MAX]; + wchar_t wcTemp; + int rc; + + /*** Read the multibyte character ***/ + if( !fread( &mbc[0], 1, 1, fp ) ) + return( 0 ); + + if( _ismbblead( mbc[0] ) ) { + if( !fread( &mbc[1], 1, 1, fp ) ) + return( 0 ); + } + + /*** Convert it to wide form ***/ + rc = mbtowc( &wcTemp, mbc, MB_CUR_MAX ); + if( rc >= 0 ) { + *wc = wcTemp; + return( 1 ); + } else { + __set_errno( EILSEQ ); + return( 0 ); + } + } +} + +_WCRTLINK wint_t fgetwc( FILE *fp ) +{ + wchar_t c; + + _ValidFile( fp, WEOF ); + _AccessFile( fp ); + + /*** Deal with stream orientation ***/ + ORIENT_STREAM(fp,WEOF); + + /*** Read the character ***/ + if( !__read_wide_char( fp, &c ) ) { + _ReleaseFile( fp ); + return( WEOF ); + } + if( !(fp->_flag & _BINARY) && (c == L'\r') ) { + if( !__read_wide_char( fp, &c ) ) { + _ReleaseFile( fp ); + return( WEOF ); + } + } + + _ReleaseFile( fp ); + return( (wint_t)c ); +} + +#endif diff --git a/programs/develop/open watcom/trunk/clib/src/fileacc.h b/programs/develop/open watcom/trunk/clib/src/fileacc.h new file mode 100644 index 0000000000..386be424cf --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/fixpoint.h b/programs/develop/open watcom/trunk/clib/src/fixpoint.h new file mode 100644 index 0000000000..a09cb3ab07 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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; diff --git a/programs/develop/open watcom/trunk/clib/src/flush.h b/programs/develop/open watcom/trunk/clib/src/flush.h new file mode 100644 index 0000000000..484457d080 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 ); diff --git a/programs/develop/open watcom/trunk/clib/src/flushall.c b/programs/develop/open watcom/trunk/clib/src/flushall.c new file mode 100644 index 0000000000..8fffa7c179 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/flushall.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: Implementation of flushall() - flush all streams. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "rtdata.h" +#include "fileacc.h" +#include "flush.h" + + +/* __fill_buffer calls this routine with _ISTTY mask */ + +int __flushall( int mask ) +{ + __stream_link *link; + FILE *fp; + int number_of_open_files; + + _AccessIOB(); + number_of_open_files = 0; + for( link = _RWD_ostream; link != NULL; link = link->next ) { + fp = link->stream; + if( fp->_flag & mask ) { /* if file is a candidate */ + ++number_of_open_files; + if( fp->_flag & _DIRTY ) { + __flush( fp ); + } + } + } + _ReleaseIOB(); + return( number_of_open_files ); +} + +_WCRTLINK int flushall( void ) +{ + return( __flushall( ~0 ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/fmode.h b/programs/develop/open watcom/trunk/clib/src/fmode.h new file mode 100644 index 0000000000..386ac1af38 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fmode.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +/* define _fmode to be _fmode */ diff --git a/programs/develop/open watcom/trunk/clib/src/fopen.c b/programs/develop/open watcom/trunk/clib/src/fopen.c new file mode 100644 index 0000000000..e91ce17b24 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fopen.c @@ -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: Platform independent fopen() implementation. +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#ifdef __WIDECHAR__ + #include +#endif +#include +#include +#include +#include "fileacc.h" +#include "fmode.h" +#include "openmode.h" +#include "rtdata.h" +#include "seterrno.h" +//#include "defwin.h" +#include "streamio.h" + +#ifdef __UNIX__ + #define PMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) +#else + #define PMODE (S_IREAD | S_IWRITE) +#endif + + +int __F_NAME(__open_flags,__wopen_flags)( const CHAR_TYPE *modestr, int *extflags ) +{ + int flags; + int alive = 1; + int gotplus = 0; + int gottextbin = 0; +#ifndef __NETWARE__ + int gotcommit = 0; +#endif + + flags = 0; + if( extflags != NULL ) { +#ifdef __NETWARE__ + *extflags = 0; +#else + if( _commode == _COMMIT ) { + *extflags = _COMMIT; + } else { + *extflags = 0; + } +#endif + } + + /* + * The first character in modestr must be 'r', 'w', or 'a'. + */ + switch( *modestr ) { + case 'r': + flags |= _READ; + break; + case 'w': + flags |= _WRITE; + break; + case 'a': + flags |= _WRITE | _APPEND; + break; + default: + __set_errno( EINVAL ); + return( 0 ); + } + modestr++; + + /* + * Next we might have, in any order, some additional mode modifier + * characters: + * 1. A '+' character. + * 2. Either a 't' or a 'b'. + * 3. Either a 'c' or a 'n'. (Not available for Netware.) + * For MS compatability, scanning stops when any of the three groups + * is encountered twice; e.g., "wct+b$&!" is valid and will result in + * a text, not binary, stream. Also for MS compatability, scanning + * stops at any unrecognized character, without causing failure. + */ + while( (*modestr != NULLCHAR) && alive ) { + switch( *modestr ) { + case '+': + if( gotplus ) { + alive = 0; + } else { + flags |= _READ | _WRITE; + gotplus = 1; + } + break; + case 't': + if( gottextbin ) { + alive = 0; + } else { + gottextbin = 1; + } + break; + case 'b': + if( gottextbin ) { + alive = 0; + } else { +#ifndef __UNIX__ + flags |= _BINARY; +#endif + gottextbin = 1; + } + break; +#ifndef __NETWARE__ + case 'c': + if( gotcommit ) { + alive = 0; + } else { + *extflags |= _COMMIT; + gotcommit = 1; + } + break; + case 'n': + if( gotcommit ) { + alive = 0; + } else { + *extflags &= ~_COMMIT; + gotcommit = 1; + } + break; +#endif + default: + break; + } + modestr++; + } + + /* + * Handle defaults for any unspecified options. + */ +#ifndef __UNIX__ + if( !gottextbin ) { + if( _RWD_fmode == O_BINARY ) flags |= _BINARY; + } +#endif + + return( flags ); +} + + +static FILE *__F_NAME(__doopen,__wdoopen)( const CHAR_TYPE *name, + CHAR_TYPE mode, + int file_flags, + int extflags, + int shflag, /* sharing flag */ + FILE * fp ) +{ + int open_mode; + int p_mode; + + SetupTGCSandNCS( RETURN_ARG( FILE *, 0 ) ); /* for NW386 */ + fp->_flag &= ~(_READ | _WRITE); + fp->_flag |= file_flags; + + /* we need the mode character to indicate if the original */ + /* intention is to open for read or for write */ + mode = __F_NAME(tolower,towlower)( mode ); + if( mode == 'r' ) { + open_mode = O_RDONLY; + if( file_flags & _WRITE ) { /* if "r+" mode */ + open_mode = O_RDWR; + } +#if defined( __NETWARE__ ) + open_mode |= O_BINARY; +#elif defined( __UNIX__ ) +#else + if( file_flags & _BINARY ) { + open_mode |= O_BINARY; + } else { + open_mode |= O_TEXT; + } +#endif + p_mode = 0; + } else { /* mode == 'w' || mode == 'a' */ + if( file_flags & _READ ) { /* if "a+" or "w+" mode */ + open_mode = O_RDWR | O_CREAT; + } else { + open_mode = O_WRONLY | O_CREAT; + } + if( file_flags & _APPEND ) { + open_mode |= O_APPEND; + } else { /* mode == 'w' */ + open_mode |= O_TRUNC; + } +#if defined( __NETWARE__ ) + open_mode |= O_BINARY; +#elif defined( __UNIX__ ) +#else + if( file_flags & _BINARY ) { + open_mode |= O_BINARY; + } else { + open_mode |= O_TEXT; + } +#endif + p_mode = PMODE; + } + fp->_handle = __F_NAME(sopen,_wsopen)( name, open_mode, shflag, p_mode ); + if( fp->_handle == -1 ) { + // since we couldn't open the file, release the FILE struct + __freefp( fp ); + return( NULL ); + } + fp->_cnt = 0; + fp->_bufsize = 0; /* was BUFSIZ JBS 31-may-91 */ +#ifndef __NETWARE__ + _FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */ + _FP_EXTFLAGS(fp) = extflags; +#endif +#if defined( __NT__ ) || defined( __OS2__ ) + _FP_PIPEDATA(fp).isPipe = 0; /* not a pipe */ +#endif + _FP_BASE(fp) = NULL; + if( file_flags & _APPEND ) { + fseek( fp, 0L, SEEK_END ); + } + __chktty( fp ); /* JBS 28-aug-90 */ + return( fp ); +} + + +_WCRTLINK FILE *__F_NAME(_fsopen,_wfsopen)( const CHAR_TYPE *name, + const CHAR_TYPE *access_mode, int shflag ) +{ + FILE * fp; + int file_flags; + int extflags; + + /* validate access_mode */ + file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags ); + if( file_flags == 0 ) { + return( NULL ); + } + + /* specify dummy handle 0 */ + fp = __allocfp( 0 ); /* JBS 30-aug-91 */ + if( fp != NULL ) { + fp = __F_NAME(__doopen,__wdoopen)( name, *access_mode, + file_flags, extflags, + shflag, fp ); + } + return( fp ); +} + + +_WCRTLINK FILE *__F_NAME(fopen,_wfopen)( const CHAR_TYPE *name, const CHAR_TYPE *access_mode ) +{ + return( __F_NAME(_fsopen,_wfsopen)( name, access_mode, OPENMODE_DENY_COMPAT ) ); +} + +static FILE *close_file( FILE *fp ) +{ + __stream_link * link; + __stream_link **owner; + + _AccessIOB(); + /* See if the file pointer is a currently open file. */ + link = _RWD_ostream; + for( ;; ) { + if( link == NULL ) break; + if( link->stream == fp ) { + if( fp->_flag & (_READ|_WRITE) ) { + __doclose( fp, 1 ); + } + _ReleaseIOB(); + return( fp ); + } + link = link->next; + } + /* + It's not on the list of open files, so check the list of + recently closed ones. + */ + owner = &_RWD_cstream; + for( ;; ) { + link = *owner; + if( link == NULL ) break; + if( link->stream == fp ) { + /* remove from closed list and put on open */ + *owner = link->next; + link->next = _RWD_ostream; + _RWD_ostream = link; + _ReleaseIOB(); + return( fp ); + } + owner = &link->next; + } + /* We ain't seen that file pointer ever. Leave things be. */ + __set_errno( EBADF ); + _ReleaseIOB(); + return( NULL ); +} + + +_WCRTLINK FILE *__F_NAME(freopen,_wfreopen)( const CHAR_TYPE *name, + const CHAR_TYPE *access_mode, FILE *fp ) +{ + int hdl; + int file_flags; + int extflags; + + _ValidFile( fp, 0 ); + + /* validate access_mode */ + file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags ); + if( file_flags == 0 ) { + return( NULL ); + } + + hdl = fileno( fp ); + _AccessFileH( hdl ); + +#ifdef DEFAULT_WINDOWING + if( _WindowsRemoveWindowedHandle != 0 ) { + _WindowsRemoveWindowedHandle( hdl ); + } +#endif + fp = close_file( fp ); + if( fp != NULL ) { + fp->_flag &= _DYNAMIC; /* 24-jul-92 */ + fp = __F_NAME(__doopen,__wdoopen)( name, *access_mode, + file_flags, extflags, + 0, fp ); + } + _ReleaseFileH( hdl ); + return( fp ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/fprtf.h b/programs/develop/open watcom/trunk/clib/src/fprtf.h new file mode 100644 index 0000000000..7a9f510210 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 ); diff --git a/programs/develop/open watcom/trunk/clib/src/fread.c b/programs/develop/open watcom/trunk/clib/src/fread.c new file mode 100644 index 0000000000..657366d424 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fread.c @@ -0,0 +1,165 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR 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 fread() - read data from stream. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "fileacc.h" +#include +#include +#include "rtdata.h" +#include "seterrno.h" +#include "qread.h" +#include "streamio.h" + + +#define DOS_EOF_CHAR 0x1a + +extern int __fill_buffer( FILE * ); /* located in fgetc */ + + +_WCRTLINK size_t fread( void *_buf, size_t size, size_t n, FILE *fp ) +{ + char *buf = _buf; + size_t len_read; + + _ValidFile( fp, 0 ); + _AccessFile( fp ); + if( (fp->_flag & _READ) == 0 ) { + __set_errno( EBADF ); + fp->_flag |= _SFERR; + _ReleaseFile( fp ); + return( 0 ); + } + +#if 0 + /*** If the buffer is _DIRTY, resync it before reading ***/ + if( fp->_flag & (_WRITE | _UNGET) ) { + if( fp->_flag & _DIRTY ) { + fseek( fp, 0, SEEK_CUR ); + } + } +#endif + + n *= size; + if( n == 0 ) { + _ReleaseFile( fp ); + return( n ); + } + if( _FP_BASE(fp) == NULL ) { + __ioalloc( fp ); /* allocate buffer */ + } + len_read = 0; +#if !defined( __UNIX__ ) + if( fp->_flag & _BINARY ) +#endif + { + size_t bytes_left = n, bytes; + for( ;; ) { + if( fp->_cnt != 0 ) { + bytes = fp->_cnt; + if( bytes > bytes_left ) { + bytes = bytes_left; + } + memcpy( buf, fp->_ptr, bytes ); + fp->_ptr += bytes; + buf += bytes; + fp->_cnt -= bytes; + bytes_left -= bytes; + len_read += bytes; + } + if( bytes_left == 0 ) break; + + /* if user's buffer is larger than our buffer, OR + _IONBF is set, then read directly into user's buffer. */ + + if( (bytes_left >= fp->_bufsize) || (fp->_flag & _IONBF) ) { + bytes = bytes_left; + fp->_ptr = _FP_BASE(fp); + fp->_cnt = 0; + if( !(fp->_flag & _IONBF) ) { + /* if more than a sector, set to multiple of sector size*/ + if( bytes > 512 ) { + bytes &= -512; + } + } + n = __qread( fileno(fp), buf, bytes ); + if( n == -1 ) { + fp->_flag |= _SFERR; + break; + } else if( n == 0 ) { + fp->_flag |= _EOF; + break; + } + buf += n; + bytes_left -= n; + len_read += n; + } else { + if( __fill_buffer( fp ) == 0 ) break; + } + } /* end for */ +#if !defined(__UNIX__) + } else { + for( ;; ) { + int c; + + // ensure non-empty buffer + if( fp->_cnt == 0 ) { + if( __fill_buffer( fp ) == 0 ) break; + } + // get character + --fp->_cnt; + c = *fp->_ptr++ & 0xff; + // perform new-line translation + if( c == '\r' ) { + // ensure non-empty buffer + if( fp->_cnt == 0 ) { + if( __fill_buffer( fp ) == 0 ) break; + } + // get character + --fp->_cnt; + c = *fp->_ptr++ & 0xff; + } + // check for DOS end of file marker + if( c == DOS_EOF_CHAR ) { + fp->_flag |= _EOF; + break; + } + // store chracter + buf[len_read] = (char)c; + ++len_read; + if( len_read == n ) break; + } +#endif + } + _ReleaseFile( fp ); + return( len_read / size ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/fseek.c b/programs/develop/open watcom/trunk/clib/src/fseek.c new file mode 100644 index 0000000000..96e9dfe293 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fseek.c @@ -0,0 +1,157 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of fseek - set stream position. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include +#include "fileacc.h" +#include "rtdata.h" +#include "seterrno.h" +#include "flush.h" + + +static int __update_buffer( long diff, FILE *fp ) +{ + /* + diff is relative to fp->_ptr + if diff is within the buffer update the pointers and return 0 + otherwise update the pointers and return 1 + */ + if( diff <= fp->_cnt && diff >= (_FP_BASE(fp) - fp->_ptr) ) { + fp->_flag &= ~(_EOF); + fp->_ptr += diff; + fp->_cnt -= diff; + return( 0 ); + } + return( 1 ); +} + + +/* + * This used to be in __update_buffer(), but we don't want to do this until + * AFTER we've made certain that lseek() will be a successful one. + */ +static void __reset_buffer( FILE *fp ) +{ + fp->_flag &= ~(_EOF); + fp->_ptr = _FP_BASE(fp); + fp->_cnt = 0; +} + + +_WCRTLINK int fseek( FILE *fp, long offset, int origin ) +{ + _ValidFile( fp, -1 ); + _AccessFile( fp ); + /* + if the file is open for any sort of writing we must ensure that + the buffer is flushed when dirty so that the integrity of the + data is preserved. + if there is an ungotten character in the buffer then the data must + be discarded to ensure the integrity of the data + */ + if( fp->_flag & (_WRITE | _UNGET) ) { + if( fp->_flag & _DIRTY ) { + /* + the __flush routine aligns the DOS file pointer with the + start of the resulting cleared buffer, as such, the SEEK_CUR + code used for the non-_DIRTY buffer case is not required + */ + if( __flush( fp ) ) { + // assume __flush set the errno value + // if erroneous input, override errno value + if( origin == SEEK_SET && offset < 0 ) { + __set_errno( EINVAL ); + } + _ReleaseFile( fp ); + return( -1 ); + } + } else { + if( origin == SEEK_CUR ) { + offset -= fp->_cnt; + } + fp->_ptr = _FP_BASE(fp); + fp->_cnt = 0; + } + fp->_flag &= ~(_EOF|_UNGET); + if( lseek( fileno( fp ), offset, origin ) == -1 ) { + _ReleaseFile( fp ); + return( -1 ); + } + } else { + // file is open for read only, + // no characters have been ungotten + // the OS file pointer is at fp->_ptr + fp->_cnt relative to the + // FILE* buffer + switch( origin ) { + case SEEK_CUR: + { long ptr_delta = fp->_cnt; + + if( __update_buffer( offset, fp ) ) { + offset -= ptr_delta; + if( lseek( fileno( fp ), offset, origin ) == -1 ) { + _ReleaseFile( fp ); + return( -1 ); + } + __reset_buffer(fp); + } + } break; + case SEEK_SET: + { long file_ptr = tell( fileno( fp ) ); + + file_ptr -= fp->_cnt; + if( __update_buffer( offset - file_ptr, fp ) ) { + if( lseek( fileno( fp ), offset, origin ) == -1 ) { + _ReleaseFile( fp ); + return( -1 ); + } + __reset_buffer(fp); + } + } break; + case SEEK_END: + fp->_flag &= ~(_EOF); + fp->_ptr = _FP_BASE(fp); + fp->_cnt = 0; + if( lseek( fileno( fp ), offset, origin ) == -1 ) { + _ReleaseFile( fp ); + return( -1 ); + } + break; + default: + __set_errno( EINVAL ); + _ReleaseFile( fp ); + return( -1 ); + } + } + _ReleaseFile( fp ); + return( 0 ); /* indicate success */ +} diff --git a/programs/develop/open watcom/trunk/clib/src/ftell.c b/programs/develop/open watcom/trunk/clib/src/ftell.c new file mode 100644 index 0000000000..ca2c5a77ea --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/ftell.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: Platform independent ftell() implementaiton. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include +#include "fileacc.h" + + +_WCRTLINK long ftell( FILE *fp ) +{ + long pos; + + _ValidFile( fp, -1 ); + if( fp->_flag & _APPEND && fp->_flag & _DIRTY ) { + fflush( fp ); /* if data written in append mode, OS must know */ + } + pos = tell( fileno( fp ) ); + if( pos == -1 ) { + return( -1L ); + } + _AccessFile( fp ); + if( fp->_cnt != 0 ) { /* if something in buffer */ + if( fp->_flag & _DIRTY ) { /* last operation was a put */ + pos += fp->_cnt; + } else { /* last operation was a get */ + pos -= fp->_cnt; + } + } + _ReleaseFile( fp ); + return( pos ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/ftos.h b/programs/develop/open watcom/trunk/clib/src/ftos.h new file mode 100644 index 0000000000..7d07bf3594 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/gtchewnt.c b/programs/develop/open watcom/trunk/clib/src/gtchewnt.c new file mode 100644 index 0000000000..802b98aef4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/gtchewnt.c @@ -0,0 +1,50 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "rtdata.h" + +_WCRTLINK int getche() + { + unsigned c; + unsigned stashed; + + stashed = _RWD_cbyte; + + c = getch(); + if( c != EOF && stashed == 0 ) { + putch( c ); + } + return( c ); + } diff --git a/programs/develop/open watcom/trunk/clib/src/handleio.h b/programs/develop/open watcom/trunk/clib/src/handleio.h new file mode 100644 index 0000000000..0a549e4fd4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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; diff --git a/programs/develop/open watcom/trunk/clib/src/hdlman.c b/programs/develop/open watcom/trunk/clib/src/hdlman.c index 8a30808748..da9b11d32a 100644 --- a/programs/develop/open watcom/trunk/clib/src/hdlman.c +++ b/programs/develop/open watcom/trunk/clib/src/hdlman.c @@ -48,23 +48,6 @@ #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 @@ -153,6 +136,7 @@ HANDLE __getOSHandle( int hid ) return( __OSHandles[ hid ] ); } + int __setOSHandle( unsigned hid, HANDLE hdl ) { // call the Win32 API for a standard file handle @@ -184,24 +168,11 @@ static int __topFakeHandle = 0; HANDLE __NTGetFakeHandle( void ) { HANDLE os_handle; - + static DWORD fakeHandle = 0x80000000L; _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++; - } + + fakeHandle++; + os_handle = (HANDLE)fakeHandle; _ReleaseFList(); return( os_handle ); } diff --git a/programs/develop/open watcom/trunk/clib/src/heap.h b/programs/develop/open watcom/trunk/clib/src/heap.h new file mode 100644 index 0000000000..78bb4926a8 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/heapacc.h b/programs/develop/open watcom/trunk/clib/src/heapacc.h new file mode 100644 index 0000000000..9836dff8b3 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + diff --git a/programs/develop/open watcom/trunk/clib/src/iomode.h b/programs/develop/open watcom/trunk/clib/src/iomode.h new file mode 100644 index 0000000000..1e54d3867e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/kolibri.h b/programs/develop/open watcom/trunk/clib/src/kolibri.h new file mode 100644 index 0000000000..d888282c2e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/kolibri.h @@ -0,0 +1,105 @@ + +#ifdef __cplusplus +extern "C" +{ +#endif + + +#define FONT0 0x00000000 +#define FONT1 0x10000000 + +#define BT_NORMAL 0x00000000 +#define BT_NOFRAME 0x20000000 +#define BT_HIDE 0x40000000 +#define BT_DEL 0x80000000 + +#define EV_REDRAW 1 +#define EV_KEY 2 +#define EV_BUTTON 3 + +#define REL_SCREEN 0 +#define REL_WINDOW 1 + +#define FILE_NOT_FOUND 5 +#define FILE_EOF 6 + + +typedef unsigned int DWORD; +typedef unsigned short int WORD; + +typedef struct +{ DWORD pci_cmd; + DWORD irq; + DWORD glob_cntrl; + DWORD glob_sta; + DWORD codec_io_base; + DWORD ctrl_io_base; + DWORD codec_mem_base; + DWORD ctrl_mem_base; + DWORD codec_id; +} CTRL_INFO; + +typedef struct +{ DWORD cmd; + DWORD offset; + DWORD r1; + DWORD count; + DWORD buff; + char r2; + char *name; +} FILEIO; + +typedef struct +{ DWORD attr; + DWORD flags; + DWORD cr_time; + DWORD cr_date; + DWORD acc_time; + DWORD acc_date; + DWORD mod_time; + DWORD mod_date; + DWORD size; + DWORD size_high; +} FILEINFO; + +void _stdcall InitHeap(int heap_size); +void* _stdcall UserAlloc(int size); +int _stdcall UserFree(void* p); + +void _stdcall GetNotify(void *event); + +void _stdcall CreateThread(void *fn, char *p_stack); + +DWORD _stdcall GetMousePos(DWORD rel_type); + +void _stdcall debug_out_hex(DWORD val); +void debug_out_str(char* str); + +int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo); +int _stdcall read_file (const char *name,char*buff,DWORD offset, DWORD count,DWORD *reads); +int _stdcall write_file(const char *name,char*buff,int offset,int count,int *writes); + +//void exit(); +int _stdcall get_key(int *key); +int _stdcall remap_key(int key); + +int _cdecl get_button_id(); + +void delay(int val); +int wait_for_event(int time); +int wait_for_event_infinite(); +void BeginDraw(void); +void EndDraw(void); + +void _stdcall GetScreenSize(int *x, int*y); +void _stdcall DrawWindow(int x,int y, int sx, int sy,int workcolor,int style, + int captioncolor,int windowtype,int bordercolor); +void _stdcall debug_out(int ch); +void _stdcall make_button(int x, int y, int xsize, int ysize, int id, int color); +void _stdcall draw_bar(int x, int y, int xsize, int ysize, int color); +void _stdcall write_text(int x,int y,int color,char* text,int len); + +#ifdef __cplusplus +extern "C" +} +#endif diff --git a/programs/develop/open watcom/trunk/clib/src/langenv.h b/programs/develop/open watcom/trunk/clib/src/langenv.h new file mode 100644 index 0000000000..fb4a7a7bfc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/langenvd.h b/programs/develop/open watcom/trunk/clib/src/langenvd.h new file mode 100644 index 0000000000..b9d2ebcea1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/liballoc.h b/programs/develop/open watcom/trunk/clib/src/liballoc.h new file mode 100644 index 0000000000..ed192ec391 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/lseek.c b/programs/develop/open watcom/trunk/clib/src/lseek.c new file mode 100644 index 0000000000..3f0813d73a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/lseek.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: lseek wrapper with positive -> extend file check +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#ifdef __NT__ +#include +#endif +#include "iomode.h" +#include "rtcheck.h" +#include "seterrno.h" +#include "lseek.h" + +_WCRTLINK long lseek( int handle, long offset, int origin ) +{ + unsigned iomode_flags; + + __handle_check( handle, -1 ); + + /*** Set the _FILEEXT iomode_flags bit if positive offset ***/ + iomode_flags = __GetIOMode( handle ); + + if( offset > 0 && !(iomode_flags & _APPEND) ) + __SetIOMode( handle, iomode_flags | _FILEEXT ); + return( __lseek( handle, offset, origin ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/lseek.h b/programs/develop/open watcom/trunk/clib/src/lseek.h new file mode 100644 index 0000000000..b7f53b7f09 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/lseekwnt.c b/programs/develop/open watcom/trunk/clib/src/lseekwnt.c index 416885508a..0d27479be3 100644 --- a/programs/develop/open watcom/trunk/clib/src/lseekwnt.c +++ b/programs/develop/open watcom/trunk/clib/src/lseekwnt.c @@ -1,66 +1,105 @@ -/**************************************************************************** -* -* Open Watcom Project -* -* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. -* -* ======================================================================== -* -* This file contains Original Code and/or Modifications of Original -* Code as defined in and that are subject to the Sybase Open Watcom -* Public License version 1.0 (the 'License'). You may not use this file -* except in compliance with the License. BY USING THIS FILE YOU AGREE TO -* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is -* provided with the Original Code and Modifications, and is also -* available at www.sybase.com/developer/opensource. -* -* The Original Code and all software distributed under the License are -* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER -* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM -* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR 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 -#include -#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 ); -} - +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR 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 +#include +#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 + +typedef struct +{ + char *name; + unsigned int offset; +}__file_handle; + +typedef struct +{ DWORD attr; + DWORD flags; + DWORD cr_time; + DWORD cr_date; + DWORD acc_time; + DWORD acc_date; + DWORD mod_time; + DWORD mod_date; + DWORD size; + DWORD size_high; +} FILEINFO; + +int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo); + +_WCRTLINK long __lseek( int hid, long offset, int origin ) +{ + __file_handle *fh; + long rc; + + __handle_check( hid, -1 ); + fh = (__file_handle*) __getOSHandle( hid ); + + switch(origin) + { + case SEEK_SET: + rc = offset; + break; + case SEEK_CUR: + rc = fh->offset + offset; + break; + case SEEK_END: + { + FILEINFO info; + get_fileinfo(fh->name,&info); + rc = offset + info.size; + break; + } + default: + return -1; + }; + + fh->offset = rc; + + return( rc ); +} + diff --git a/programs/develop/open watcom/trunk/clib/src/mbchar.h b/programs/develop/open watcom/trunk/clib/src/mbchar.h new file mode 100644 index 0000000000..403db7f28a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/mdef.inc b/programs/develop/open watcom/trunk/clib/src/mdef.inc new file mode 100644 index 0000000000..ddd5ecf644 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +_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 + 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 + public p1 + else + public "&p1",p2 + endif + endm + +xref macro p1,p2 + ifb + 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 + extrn p1 : dword + else + extrn "&p1",p2 : dword + endif + else + ifb + 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 + public p1 + else + public "&p1",p2 + endif + endm + +xref macro p1,p2 + ifb + 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 + xref "C",_&alias + else + xref "C",function + endif + .code + public "C",`alias` + ifdef _EXPORT + `alias` proc export + else + `alias` proc + endif + ifb + jmp _&alias + else + jmp `function` + endif + `alias` endp + endm + +xred macro p1,p2,p3 + ifb + extrn p1 : p2 + else + extrn "&p1",p2 : p3 + endif + endm + diff --git a/programs/develop/open watcom/trunk/clib/src/mf.h b/programs/develop/open watcom/trunk/clib/src/mf.h new file mode 100644 index 0000000000..34ff9ae203 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 */ + + + diff --git a/programs/develop/open watcom/trunk/clib/src/myvalist.h b/programs/develop/open watcom/trunk/clib/src/myvalist.h new file mode 100644 index 0000000000..036d3cb39e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + +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 diff --git a/programs/develop/open watcom/trunk/clib/src/openklbr.c b/programs/develop/open watcom/trunk/clib/src/openklbr.c new file mode 100644 index 0000000000..dc3e31c858 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/openklbr.c @@ -0,0 +1,404 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Win32 implementation of open() and sopen(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "liballoc.h" +#include "iomode.h" +#include "fileacc.h" +#include "openmode.h" +#include "rtdata.h" +#include "seterrno.h" + +extern unsigned __NFiles; +extern char *__appcwd; +extern int __appcwdlen; + +#if (defined(__WINDOWS__) || defined(__NT__)) + +typedef struct +{ DWORD attr; + DWORD flags; + DWORD cr_time; + DWORD cr_date; + DWORD acc_time; + DWORD acc_date; + DWORD mod_time; + DWORD mod_date; + DWORD size; + DWORD size_high; +} FILEINFO; + +int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo); + + +typedef struct +{ + char *name; + unsigned int offset; +}__file_handle; + + +static char* getfullpath(const char* path) +{ + int prev_is_slash=0; + int len=0, depth=0, i; + char* buff; + char c; + + if(*path == '/') + { + buff = (char*)lib_malloc(strlen(path)+1); + buff[0] = '\0'; + len=0; + } + else + { + len= __appcwdlen; + buff = (char*)lib_malloc(len+strlen(path)+1); + strncpy(buff, __appcwd, __appcwdlen); + + prev_is_slash = 1; + buff[len] = 0; + for(i=0; buff[i]; i++) + if(buff[i] == '/' && i < len-1) depth++; + } + + while(c=*path++) + { + switch (c) + { + + case '.': + if((*path == '.')&& + (*path+1)== '/') + { if(!depth) + { free(buff); + return 0; + }; + buff[len-1] = 0; + len = strrchr(buff, '/') + 1 - buff; + buff[len] = 0; + depth--; + path +=2; + prev_is_slash = 1; + continue; + } + if(*path == '/') + { + path++; + prev_is_slash = 1; + continue; + } + buff[len++] = c; + continue; + + case '/': + prev_is_slash = 1; + buff[len++] = c; + continue; + + default: + prev_is_slash = 0; + buff[len++] = c; + continue; + }; + }; + buff[len]= '\0'; + return buff; +}; + + +size_t FileSize(FILE *fp) +{ + int hdl; + __file_handle *fh; + FILEINFO info; + + hdl = fileno( fp ); + // __handle_check( hdl, -1 ); + + fh = (__file_handle*) __getOSHandle(hdl); + + + get_fileinfo(fh->name,&info); + + return info.size; + +} + +int access(const char *path, int mode) +{ size_t retval; + FILEINFO info; + char *p; + + p = getfullpath(path); + retval=get_fileinfo(p,&info); + free(p); + + return retval; + +} + + +static HANDLE __createFileHandle(const CHAR_TYPE *name) +{ + FILEINFO info; + __file_handle *handle; + char *path; + + path = getfullpath(name); + + if(get_fileinfo(path,&info)) + { +// printf("failed getfileinfo %s\n\r", path); + lib_free(path); + return (HANDLE)-1; + }; + + if ( !(handle=(__file_handle*)lib_malloc(sizeof( __file_handle) ))) + { lib_free(path); + return (HANDLE)-1; + }; + + handle->name = path; + handle->offset = 0; + + return (HANDLE)handle; +}; + + + +static int __F_NAME(_sopen,__wsopen)( const CHAR_TYPE *name, int mode, int share, va_list args ) +{ + HANDLE handle; + int hid, rwmode; + unsigned iomode_flags; + + // First try to get the required slot. + // No point in creating a file only to not use it. JBS 99/10/26 + hid = __allocPOSIXHandle( DUMMY_HANDLE ); + if( hid == -1 ) + { + return( -1 ); + } + + rwmode = mode; + + + /*** Open the file ***/ + + handle = __createFileHandle( name); + + if( handle==(HANDLE)-1 ) + { + + printf("handle = -1 \n\r"); + + if( mode&O_CREAT ) + { +// handle = CreateFileA( name, desired_access, +// share_mode, NULL, create_disp, +// fileattr, NULL ); + } + if( handle == (HANDLE)-1 ) + { + __freePOSIXHandle( hid ); + return( -1 ); //error + } + } + +// Now use the slot we got. + __setOSHandle( hid, handle ); // JBS 99/11/01 + + iomode_flags = 0; + + + if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; + else if( rwmode == O_RDONLY) iomode_flags |= _READ; + else if( rwmode == O_WRONLY) iomode_flags |= _WRITE; + if( mode & O_APPEND ) iomode_flags |= _APPEND; + if( mode & (O_BINARY|O_TEXT) ) { + if( mode & O_BINARY ) iomode_flags |= _BINARY; + } else { + if( _RWD_fmode == O_BINARY ) iomode_flags |= _BINARY; + } + __SetIOMode( hid, iomode_flags ); + return( hid ); +} + +#elif +static int __F_NAME(_sopen,__wsopen)( const CHAR_TYPE *name, int mode, int share, va_list args ) +{ + DWORD create_disp, exists_disp; + DWORD perm, fileattr; + DWORD desired_access, share_mode; + SECURITY_ATTRIBUTES security; + HANDLE handle; + int hid, rwmode; + unsigned iomode_flags; + + // First try to get the required slot. + // No point in creating a file only to not use it. JBS 99/10/26 + hid = __allocPOSIXHandle( DUMMY_HANDLE ); + if( hid == -1 ) { + return( -1 ); + } + + rwmode = mode & OPENMODE_ACCESS_MASK; + __GetNTAccessAttr( rwmode, &desired_access, &perm ); + __GetNTShareAttr( share|rwmode, &share_mode ); + fileattr = FILE_ATTRIBUTE_NORMAL; + + security.nLength = sizeof( SECURITY_ATTRIBUTES ); + security.lpSecurityDescriptor = NULL; + security.bInheritHandle = mode&O_NOINHERIT ? FALSE : TRUE; + +#ifdef DEFAULT_WINDOWING +#ifdef __WIDECHAR__ + if( _WindowsNewWindow != 0 && !_wcsicmp( name, L"con" ) ) +#else + if( _WindowsNewWindow != 0 && !stricmp( name, "con" ) ) +#endif + { + handle = (HANDLE) __NTGetFakeHandle(); + + // Now use the slot we got. + __setOSHandle( hid, handle ); // JBS 99/11/01 + _WindowsNewWindow( NULL, hid, -1 ); + + iomode_flags = _ISTTY; + } else { +#endif + if( mode & O_CREAT ) { + perm = va_arg( args, int ); + va_end( args ); + perm &= ~_RWD_umaskval; /* 05-jan-95 */ + if( ( perm & S_IREAD ) && !( perm & S_IWRITE ) ) { + fileattr = FILE_ATTRIBUTE_READONLY; + } + if( mode & O_EXCL ) { + create_disp = CREATE_NEW; + exists_disp = CREATE_NEW; + } else if( mode & O_TRUNC ) { + create_disp = CREATE_ALWAYS; + exists_disp = CREATE_NEW; + } else { + create_disp = OPEN_ALWAYS; + exists_disp = OPEN_EXISTING; + } + } else if( mode & O_TRUNC ) { + exists_disp = TRUNCATE_EXISTING; + } else { + exists_disp = OPEN_EXISTING; + } + + /*** Open the file ***/ + #ifdef __WIDECHAR__ + handle = __lib_CreateFileW( name, desired_access, share_mode, + &security, exists_disp, fileattr, + NULL ); + #else + handle = CreateFileA( name, desired_access, share_mode, + &security, exists_disp, fileattr, NULL ); + #endif + if( handle==(HANDLE)-1 ) { + if( mode&O_CREAT ) { + #ifdef __WIDECHAR__ + handle = __lib_CreateFileW( name, desired_access, + share_mode, NULL, create_disp, + fileattr, NULL ); + #else + handle = CreateFileA( name, desired_access, + share_mode, NULL, create_disp, + fileattr, NULL ); + #endif + } + if( handle == (HANDLE)-1 ) { + __freePOSIXHandle( hid ); + return( __set_errno_nt() ); + } + } + + // Now use the slot we got. + __setOSHandle( hid, handle ); // JBS 99/11/01 + + iomode_flags = 0; + + if( isatty(hid) ) { + iomode_flags = _ISTTY; + } +#ifdef DEFAULT_WINDOWING + } +#endif + + if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; + else if( rwmode == O_RDONLY) iomode_flags |= _READ; + else if( rwmode == O_WRONLY) iomode_flags |= _WRITE; + if( mode & O_APPEND ) iomode_flags |= _APPEND; + if( mode & (O_BINARY|O_TEXT) ) { + if( mode & O_BINARY ) iomode_flags |= _BINARY; + } else { + if( _RWD_fmode == O_BINARY ) iomode_flags |= _BINARY; + } + __SetIOMode( hid, iomode_flags ); + return( hid ); +} +#endif + +_WCRTLINK int __F_NAME(open,_wopen)( const CHAR_TYPE *name, int mode, ... ) +{ + int permission; + va_list args; + + va_start( args, mode ); + permission = va_arg( args, int ); + va_end( args ); + return( __F_NAME(sopen,_wsopen)( name, mode, SH_COMPAT, permission ) ); +} + + +_WCRTLINK int __F_NAME(sopen,_wsopen)( const CHAR_TYPE *name, int mode, int shflag, ... ) +{ + va_list args; + + va_start( args, shflag ); + return( __F_NAME(_sopen,__wsopen)( name, mode, shflag, args ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/openmode.h b/programs/develop/open watcom/trunk/clib/src/openmode.h new file mode 100644 index 0000000000..4e29d357c0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/openmode.h @@ -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! +* +****************************************************************************/ + + +#ifndef _OPENMODE_H_INCLUDED +#define _OPENMODE_H_INCLUDED +enum { + FILEATTR_MASK = 0x003f, + FILEATTR_NORMAL = 0x0000, + FILEATTR_READONLY = 0x0001, + FILEATTR_HIDDEN = 0x0002, + FILEATTR_SYSTEM = 0x0004, + FILEATTR_DIRECTORY = 0x0010, + FILEATTR_ARCHIVED = 0x0020 +}; + +enum { + OPENFLAG_FAIL_IF_EXISTS = 0x0000, + OPENFLAG_OPEN_IF_EXISTS = 0x0001, + OPENFLAG_REPLACE_IF_EXISTS = 0x0002, + OPENFLAG_FAIL_IF_NOT_EXISTS = 0x0000, + OPENFLAG_CREATE_IF_NOT_EXISTS = 0x0010 +}; + +enum { + OPENMODE_DASD = 0x8000, + OPENMODE_WRITE_THROUGH = 0x4000, + OPENMODE_FAIL_ERRORS = 0x2000, + OPENMODE_NO_CACHE = 0x1000, + OPENMODE_LOCALITY_MASK = 0x0700, + OPENMODE_LOCALITY_RANDSEQ = 0x0300, + OPENMODE_LOCALITY_RANDOM = 0x0200, + OPENMODE_LOCALITY_SEQUENTIAL = 0x0100, + OPENMODE_LOCALITY_NONE = 0x0000, + OPENMODE_INHERITANCE = 0x0080, + OPENMODE_SHARE_MASK = 0x0070, + OPENMODE_DENY_COMPAT = 0x0000, + OPENMODE_DENY_ALL = 0x0010, + OPENMODE_DENY_WRITE = 0x0020, + OPENMODE_DENY_READ = 0x0030, + OPENMODE_DENY_NONE = 0x0040, + OPENMODE_ACCESS_MASK = 0x0007, + OPENMODE_ACCESS_RDONLY = 0x0000, + OPENMODE_ACCESS_WRONLY = 0x0001, + OPENMODE_ACCESS_RDWR = 0x0002 +}; +#endif diff --git a/programs/develop/open watcom/trunk/clib/src/orient.h b/programs/develop/open watcom/trunk/clib/src/orient.h new file mode 100644 index 0000000000..ab097f6bd1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/printf.h b/programs/develop/open watcom/trunk/clib/src/printf.h new file mode 100644 index 0000000000..2c6187e3ba --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/prtscncf.h b/programs/develop/open watcom/trunk/clib/src/prtscncf.h new file mode 100644 index 0000000000..fc410783a9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#include + +/* 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 diff --git a/programs/develop/open watcom/trunk/clib/src/qread.c b/programs/develop/open watcom/trunk/clib/src/qread.c new file mode 100644 index 0000000000..51365cac07 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/qread.c @@ -0,0 +1,68 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "iomode.h" +#include "rtcheck.h" +#include "seterrno.h" +#include "qread.h" +#include + +typedef struct +{ + char *name; + unsigned int offset; +}__file_handle; + + +int _stdcall read_file (const char *name,char *buff,unsigned offset, unsigned count,unsigned *reads); + +int __qread( int handle, void *buffer, unsigned len ) +{ + __file_handle *fh; + unsigned amount_read=0; + + __handle_check( handle, -1 ); + fh = (__file_handle*) __getOSHandle( handle ); + + if(read_file(fh->name,buffer,fh->offset,len,&amount_read)) + { + if ( amount_read == 0) + return (-1); + + } + fh->offset+=amount_read; + return( amount_read ); +}; + + + diff --git a/programs/develop/open watcom/trunk/clib/src/qread.h b/programs/develop/open watcom/trunk/clib/src/qread.h new file mode 100644 index 0000000000..ff1b3e2392 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/qread.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 __qread() internal helper. +* +****************************************************************************/ + + +#ifdef __NETWARE__ + #define __qread( h, b, l ) read( h, b, l ) +#else + extern int __qread( int handle, void *buffer, unsigned len ); +#endif diff --git a/programs/develop/open watcom/trunk/clib/src/qwrite.h b/programs/develop/open watcom/trunk/clib/src/qwrite.h new file mode 100644 index 0000000000..c9eb3b8672 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/rewind.c b/programs/develop/open watcom/trunk/clib/src/rewind.c new file mode 100644 index 0000000000..23749ef765 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/rewind.c @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Platform independent implementation of rewind(). +* +****************************************************************************/ + + +#include "variety.h" +#include + + +_WCRTLINK void rewind( FILE *fp ) +{ + __stream_check( fp, 0 ); + clearerr( fp ); + fseek( fp, 0, SEEK_SET ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/riscstr.h b/programs/develop/open watcom/trunk/clib/src/riscstr.h new file mode 100644 index 0000000000..4008e65295 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#include +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/rtcheck.h b/programs/develop/open watcom/trunk/clib/src/rtcheck.h new file mode 100644 index 0000000000..1a7d874c9d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#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 + diff --git a/programs/develop/open watcom/trunk/clib/src/rtdata.h b/programs/develop/open watcom/trunk/clib/src/rtdata.h new file mode 100644 index 0000000000..f218987f46 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/rtinit.h b/programs/develop/open watcom/trunk/clib/src/rtinit.h new file mode 100644 index 0000000000..73d2f48644 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/scanf.h b/programs/develop/open watcom/trunk/clib/src/scanf.h new file mode 100644 index 0000000000..1dbb53e5b2 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + +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 diff --git a/programs/develop/open watcom/trunk/clib/src/seterrno.h b/programs/develop/open watcom/trunk/clib/src/seterrno.h new file mode 100644 index 0000000000..e313206667 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + diff --git a/programs/develop/open watcom/trunk/clib/src/streamio.h b/programs/develop/open watcom/trunk/clib/src/streamio.h new file mode 100644 index 0000000000..3b61c1398e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 ); diff --git a/programs/develop/open watcom/trunk/clib/src/struct.inc b/programs/develop/open watcom/trunk/clib/src/struct.inc new file mode 100644 index 0000000000..2d88e461ef --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 = __label + endif + endm + +_quif macro cc,name + ifnb + _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 + _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 diff --git a/programs/develop/open watcom/trunk/clib/src/tell.c b/programs/develop/open watcom/trunk/clib/src/tell.c new file mode 100644 index 0000000000..d796483383 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/tell.c @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "lseek.h" + +_WCRTLINK long int tell( int handle ) +{ + return( __lseek( handle, 0L, SEEK_CUR ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/tmpfname.h b/programs/develop/open watcom/trunk/clib/src/tmpfname.h new file mode 100644 index 0000000000..6aabdd3760 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/variety.h b/programs/develop/open watcom/trunk/clib/src/variety.h new file mode 100644 index 0000000000..fecec0e16c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 diff --git a/programs/develop/open watcom/trunk/clib/src/watcom.h b/programs/develop/open watcom/trunk/clib/src/watcom.h new file mode 100644 index 0000000000..362dc5abaa --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 +#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 diff --git a/programs/develop/open watcom/trunk/clib/src/widechar.h b/programs/develop/open watcom/trunk/clib/src/widechar.h new file mode 100644 index 0000000000..7e99f9c3ca --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 /* 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 diff --git a/programs/develop/open watcom/trunk/clib/src/xstring.h b/programs/develop/open watcom/trunk/clib/src/xstring.h new file mode 100644 index 0000000000..7dc834a919 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/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 + +#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 diff --git a/programs/develop/sdk/trunk/uart/uart.inc b/programs/develop/sdk/trunk/uart/uart.inc new file mode 100644 index 0000000000..001b858907 --- /dev/null +++ b/programs/develop/sdk/trunk/uart/uart.inc @@ -0,0 +1,271 @@ + +SRV_GETVERSION equ 0 +PORT_OPEN equ 1 +PORT_CLOSE equ 2 +PORT_RESET equ 3 +PORT_SETMODE equ 4 +PORT_GETMODE equ 5 +PORT_SETMCR equ 6 +PORT_GETMCR equ 7 +PORT_READ equ 8 +PORT_WRITE equ 9 + +RATE_19200 equ 15 +LCR_8BIT equ 0x03 +MCR_OUT_2 equ 0x08 + +io.handle equ esp +io.code equ esp+4 +io.input equ esp+8 +io.inp_size equ esp+12 +io.output equ esp+16 +io.out_size equ esp+20 + +; retval +; ebx= service version +; eax= error code +; 0= no error +; -1= common error + +align 4 +init_uart: + mov eax, 68 + mov ebx, 16 + mov ecx, szUart + int 0x40 + + mov [Uart], eax + test eax, eax + jz .fail + + push 0 ;storage for version + mov eax, esp + xor ebx, ebx + + push 4 ;.out_size + push eax ;.output + push ebx ;.inp_size + push ebx ;.input + push SRV_GETVERSION ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp + int 0x40 + add esp, 24 + pop ebx ;version + ret +.fail: + or eax, -1 + ret + +; param +; eax= port +; +; retval +; ebx= connection +; eax= error code + +align 4 +uart_open: + + push 0 ;connection + mov ebx, esp + push eax ;port + mov eax, esp + + push 4 ;.out_size + push ebx ;.output + push 4 ;.inp_size + push eax ;.input + push PORT_OPEN ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp + int 0x40 + add esp, 28 ;io_control+port + pop ebx ;connection + ret + +; param +; eax= connection +; +; retval +; eax= error code + +align 4 +uart_close: + push eax ;connection + mov eax, esp + xor ebx, ebx + + push ebx ;.out_size + push ebx ;.output + push 4 ;.inp_size + push eax ;.input + push PORT_CLOSE ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+4 ;io_control + ret + +; param +; eax= connection +; +; retval +; eax= error code + +align 4 +uart_reset: + push eax ;connection + mov eax, esp + xor ebx, ebx + + push ebx ;.out_size + push ebx ;.output + push 4 ;.inp_size + push eax ;.input + push PORT_RESET ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+4 ;io_control + ret + +; param +; eax= connection +; ebx= rate +; ecx= mode +; +; retval +; eax= error code + +align 4 +uart_setmode: + push ecx ;mode + push ebx ;rate + push eax ;connection + mov eax, esp + xor ecx, ecx + + push ecx ;.out_size + push ecx ;.output + push 12 ;.inp_size + push eax ;.input + push PORT_SETMODE ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+12 ;io_control + ret + +; param +; eax= connection +; ebx= modem control value +; +; retval +; eax= error code + +align 4 +uart_set_mcr: + push ebx ;mcr + push eax ;connection + mov eax, esp + xor ecx, ecx + + push ecx ;.out_size + push ecx ;.output + push 8 ;.inp_size + push eax ;.input + push PORT_SETMCR ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+8 ;io_control + ret + +; param +; eax= connection +; ebx= buffer +; ecx= size +; +; retval +; ebx= bytes read +; eax= error code + +align 4 +uart_read: + push 0 ;bytes read + push ecx ;size + push ebx ;buffer + push eax ;connection + mov eax, esp + lea ebx, [esp+12] + + push 4 ;.out_size + push ebx ;.output + push 12 ;.inp_size + push eax ;.input + push PORT_READ ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+12 ;io_control + pop ebx + ret + +; param +; eax= connection +; ebx= buffer +; ecx= size +; +; retval +; eax= error code + +align 4 +uart_write: + push ecx ;size + push ebx ;buffer + push eax ;connection + mov eax, esp + xor ecx, ecx + + push ecx ;.out_size + push ecx ;.output + push 12 ;.inp_size + push eax ;.input + push PORT_WRITE ;.code + push [Uart] ;.handle + + mov eax, 68 + mov ebx, 17 + mov ecx, esp ;io_contol + int 0x40 + add esp, 24+12 ;io_control + ret + +align 4 +Uart rd 1 + +szUart db 'UART',0 + + diff --git a/programs/games/doom/trunk/kolibc/src/file/fclose.c b/programs/games/doom/trunk/kolibc/src/file/fclose.c deleted file mode 100644 index f76cda3644..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fclose.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "kolibc.h" - -int write_buffer(FILE *f); - -int fclose(FILE* file) -{ - int err; - -// if((file->mode & FILE_OPEN_WRITE)|| -// (file->mode & FILE_OPEN_APPEND)|| -// (file->mode & FILE_OPEN_PLUS)) -// err=write_buffer(file); - -// UserFree dlfree(file->buffer); - dlfree(file->filename); - dlfree(file); - return err == 0 ? 0:EOF; -} diff --git a/programs/games/doom/trunk/kolibc/src/file/feof.c b/programs/games/doom/trunk/kolibc/src/file/feof.c deleted file mode 100644 index d97ffa840e..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/feof.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "kolibc.h" -int feof(FILE* file) -{ - return (file->filepos-file->strpos)>=file->filesize; -} \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/file/fgetc.c b/programs/games/doom/trunk/kolibc/src/file/fgetc.c deleted file mode 100644 index 4d331fe11f..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fgetc.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "kolibc.h" - -extern int fill_buff(FILE* f); - -int fgetc(FILE* f) -{ char retval; - - if(!((f->mode & FILE_OPEN_READ)|(f->mode & FILE_OPEN_PLUS))) - return EOF; - - if(f->remain ==0) - { f->filepos+=8192; - if(!fill_buff(f)) - return EOF; - }; - - retval= *(f->stream); - f->strpos++; - f->stream++; - f->remain--; - return (int)retval; -} \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/file/fopen.c b/programs/games/doom/trunk/kolibc/src/file/fopen.c deleted file mode 100644 index 1f55203619..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fopen.c +++ /dev/null @@ -1,180 +0,0 @@ - -#include "kolibri.h" -#include -#include -#include "kolibc.h" - -extern char *__appcwd; -extern int __appcwdlen; - -char* getfullpath(char* path) -{ - int prev_is_slash=0; - int len=0, depth=0, i; - char* buff; - char c; - - len= __appcwdlen; - - buff = (char*)malloc(len+strlen(path)+1); - strncpy(buff, __appcwd, __appcwdlen); - - if(*path == '/') - { buff[0] = '\0'; - len=0; - } - else - { - prev_is_slash = 1; - buff[len] = 0; - for(i=0; buff[i]; i++) - if(buff[i] == '/' && i < len-1) depth++; - } - - while(c=*path++) - { - switch (c) - { - - case '.': - if((*path == '.')&& - (*path+1)== '/') - { if(!depth) - { free(buff); - return 0; - }; - buff[len-1] = 0; - len = strrchr(buff, '/') + 1 - buff; - buff[len] = 0; - depth--; - path +=2; - prev_is_slash = 1; - continue; - } - if(*path == '/') - { - path++; - prev_is_slash = 1; - continue; - } - buff[len++] = c; - continue; - - case '/': - prev_is_slash = 1; - buff[len++] = c; - continue; - - default: - prev_is_slash = 0; - buff[len++] = c; - continue; - }; - }; - buff[len]= '\0'; - return buff; -} - -FILE* fopen(const char* filename, const char *mode) -{ - FILEINFO fileinfo; - FILE* res; - char *path; - int err; - int imode; - size_t bytes; - - imode=0; - if (*mode=='r') - { - imode=FILE_OPEN_READ; - mode++; - } - else - if (*mode=='w') - { - imode=FILE_OPEN_WRITE; - mode++; - } - else - if (*mode=='a') - { - imode=FILE_OPEN_APPEND; - mode++; - } - else - return 0; - if (*mode=='t') - { - imode|=FILE_OPEN_TEXT; - mode++; - } - else - if (*mode=='b') - mode++; - if (*mode=='+') - { - imode|=FILE_OPEN_PLUS; - mode++; - } - if (*mode!=0) - return 0; - - path= getfullpath(filename); - err=get_fileinfo(path, &fileinfo); - if(err) - { - if ((imode & 7)== 0) - { free(path); - return 0; - }; - // err=_msys_create_file(path); - if (err) - { free(path); - return 0; - } - fileinfo.size=0; - }; - - res=(FILE*)malloc(sizeof(FILE)); - if(!res) - { free(path); - return 0; - }; - - res->buffer=UserAlloc(8192); - res->stream=res->buffer; - res->strpos=0; - res->remain=8192; - res->buffersize=8192; - res->filesize=fileinfo.size; - res->filename=path; - res->mode=imode; - - if (imode & FILE_OPEN_APPEND) - { size_t bytes; - res->strpos= res->filesize & 8191; - if (res->strpos) //not align - { - res->filepos=res->filesize & -8192; // align buffer - res->remain=8192-res->strpos; - err=read_file(res->filename,res->buffer, - res->filesize,res->remain,&bytes); - res->stream=res->buffer+res->strpos; - }; - } - else - { size_t bytes; - - err=read_file(res->filename,res->buffer, - 0,8192,&bytes); - res->filepos=0; - }; - return res; -} - -size_t FileSize(FILE *handle) -{ - return handle->filesize; - -} diff --git a/programs/games/doom/trunk/kolibc/src/file/fprintf.c b/programs/games/doom/trunk/kolibc/src/file/fprintf.c deleted file mode 100644 index e8e702ebf7..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fprintf.c +++ /dev/null @@ -1,216 +0,0 @@ -#include "kolibc.h" -const char xdigs_lower[16]="0123456789abcdef"; -const char xdigs_upper[16]="0123456789ABCDEF"; -int fprintf(FILE* file, const char* format, ...) -{ - char* arg; - int ispoint; - int beforepoint; - int afterpoint; - int longflag; - int contflag; - int i; - long long number; - char buffer[512]; - char* str; - arg= (void*)&format; - arg+=sizeof(const char*); - while (*format!='\0') - { - if (*format!='%') - { - fputc(*format,file); - format++; - continue; - } - ispoint=0; - beforepoint=0; - afterpoint=0; - longflag=0; - contflag=1; - format++; - while (*format && contflag) - { - switch (*format) - { - case '.': - ispoint=1; - format++; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (ispoint) - afterpoint=afterpoint*10+(*format)-'0'; - else - beforepoint=beforepoint*10+(*format)-'0'; - format++; - break; - case 'l': - if (longflag==0) - longflag=1; - else - longflag=2; - format++; - break; - case 'L': - longflag=2; - format++; - break; - case 'f': - case 'd': - case 'x': - case 'X': - case 'c': - case 's': - case '%': - contflag=0; - break; - default: - contflag=0; - } - } - if (contflag) - break; - switch (*format) - { - case '%': - fputc('%',file); - break; - case 'd': - if (longflag==2) - { - number=*((long long *)arg); - arg+=sizeof(long long); - }else - { - number=*((int*)arg); - arg+=sizeof(int); - } - if (number<0) - { - beforepoint--; - fputc('-',file); - number=-number; - } - i=0; - while (number>0) - { - buffer[i]='0'+number%10; - number=number/10; - i++; - } - while (i0) - { - i--; - fputc(buffer[i],file); - } - break; - case 'c': - fputc(*(char*)arg,file); - arg+=sizeof(char); - break; - case 's': - str=*(char**)arg; - arg+=sizeof(char*); - if (beforepoint==0) - beforepoint--; - while (*str && beforepoint) - { - fputc(*str,file); - beforepoint--; - str++; - } - break; - case 'x': - if (longflag==2) - { - number=*((long long *)arg); - arg+=sizeof(long long); - }else - { - number=*((int*)arg); - arg+=sizeof(int); - } - if (number<0) - { - beforepoint--; - fputc('-',file); - number=-number; - } - i=0; - while (number>0) - { - buffer[i]=xdigs_lower[number & 15]; - number=number>>4; - i++; - } - while (i0) - { - i--; - fputc(buffer[i],file); - } - break; - case 'X': - if (longflag==2) - { - number=*((long long *)arg); - arg+=sizeof(long long); - }else - { - number=*((int*)arg); - arg+=sizeof(int); - } - if (number<0) - { - beforepoint--; - fputc('-',file); - number=-number; - } - i=0; - while (number>0) - { - buffer[i]=xdigs_upper[number & 15]; - number=number>>4; - i++; - } - while (i0) - { - i--; - fputc(buffer[i],file); - } - break; - case 'f': - if (longflag==2) - arg+=10; - else if (longflag==1) - arg+=8; - else - arg+=4; - break; - } - format++; - } -} diff --git a/programs/games/doom/trunk/kolibc/src/file/fputc.c b/programs/games/doom/trunk/kolibc/src/file/fputc.c deleted file mode 100644 index fbe1ea37c4..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fputc.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "kolibc.h" -#include "kolibri.h" - -int write_buffer(FILE *f); -int fill_buff(FILE* f); - -int fputc(int c,FILE* f) -{ - if(!((f->mode & FILE_OPEN_WRITE)|(f->mode & FILE_OPEN_PLUS))) - return EOF; - - if(!f->remain) - { if (!write_buffer(f)) - return EOF; - f->filepos+=8192; - fill_buff(f); - }; - - *f->stream = (char)c; - f->stream++; - f->remain--; - f->strpos++; - if((f->filepos+f->strpos) > f->filesize) - f->filesize=f->filepos+f->strpos; - - return c; -}; - -int write_buffer(FILE *f) -{ size_t bytes; - int err; - - bytes= f->filepos+8192 > f->filesize ? f->strpos:8192; - err=write_file(f->filename,f->buffer,f->filepos,bytes,&bytes); - if(err) - return 0; - return 1; -}; diff --git a/programs/games/doom/trunk/kolibc/src/file/fread.c b/programs/games/doom/trunk/kolibc/src/file/fread.c deleted file mode 100644 index 5820b78a62..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fread.c +++ /dev/null @@ -1,59 +0,0 @@ - -#include "kolibri.h" -#include - -#include "kolibc.h" - -int fill_buff(FILE* f); - -int fread(void* dst,size_t size,size_t count,FILE* f) -{ size_t req; - size_t cnt; - char *p; -// if(!((f->mode & FILE_OPEN_READ)|(f->mode & FILE_OPEN_PLUS))) -// return 0; - req=count*size; - p= (char*)dst; - - if (req+f->filepos+f->strpos > f->filesize) - req=f->filesize-f->filepos-f->strpos; - count=0; - while(req) - { - if (f->remain) - { cnt= (req > f->remain) ? f->remain : req; - memcpy(p,f->stream,cnt); - p+=cnt; - f->stream+=cnt; - f->strpos+=cnt; - f->remain-=cnt; - count+=cnt; - req-=cnt; - } - else - { - f->filepos+=8192; - if(!fill_buff(f)) - { printf("error reading file %d=",f->filepos); //eof or error - break; - } - }; - }; - return count/size; -} - -int fill_buff(FILE* f) -{ int err; - size_t bytes; - - err=read_file(f->filename,f->buffer,f->filepos, - 8192,&bytes); - if(bytes == -1) - return 0; -// if(!bytes) return 0; - f->stream = f->buffer; - f->remain = 8192; - f->strpos=0; - return bytes; -}; - diff --git a/programs/games/doom/trunk/kolibc/src/file/fscanf.c b/programs/games/doom/trunk/kolibc/src/file/fscanf.c deleted file mode 100644 index b462cd6572..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fscanf.c +++ /dev/null @@ -1,188 +0,0 @@ -#include "kolibc.h" -void skipspaces(FILE* file) -{ - int c; - while(1) - { - c=getc(file); - if (c!=' ' && c!='\r' && c!='\n') - { - ungetc(c,file); - return; - } - } -} -int fscanf(FILE* file,const char* format, ...) -{ - int res; - char* arg; - int i; - int c; - int contflag; - int longflag; - int sign; - long long number; - long double rnumber; - char* str; - res=0; - arg=(char*)&format; - arg+=sizeof(const char*); - while (*format!='\0') - { - if (*format!='%') - { - c=fgetc(file); - if (c!=*format) - { - fungetc(c,file); - return -1; - } - format++; - continue; - } - contflag=1; - longflag=0; - while (*format && contflag) - { - switch(*format) - { - case '.': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - format++; - continue; - break; - case 'l': - if (longflag==0) - longflag=1; - else - longflag=2; - format++; - break; - case 'L': - longflag=2; - format++; - break; - case 'f': - case 'd': - case 'c': - case 's': - case '%': - contflag=0; - break; - default: - contflag=0; - } - } - if (contflag) - break; - switch(*format) - { - case '%': - c=fgetc(file); - if (c!='%') - { - ungetc(c,file); - return -1; - } - res--; - break; - case 'd': - number=0; - sign=1; - skipspaces(file); - c=fgetc(file); - if (c=='-') - { - sign=-1; - }else if (c!='+') - ungetc(c,file); - contflag=0; - while(1) - { - c=fgetc(file); - if (c>='0' && c<='9') - { - contflag++; - number=number*10+(c-'0'); - }else - break; - } - ungetc(c,file); - if (!contflag) - return res; - if (longflag<=1) - { - *((int*)arg)=number; - arg+=sizeof(int); - }else - { - *((long long*)arg)=number; - arg+=sizeof(long long); - } - break; - case 'c': - c=fgetc(file); - if (c==EOF) - return res; - *((char*)arg)=c; - arg+=sizeof(char); - break; - case 's': - skipspaces(file); - contflag=0; - str=*((char**)arg); - arg+=sizeof(char*); - while(1) - { - c=fgetc(file); - if (c==EOF || c==' ' || c=='\n' || c=='\r') - { - ungetc(c,file); - break; - } - *str=c; - str++; - contflag++; - } - if (!contflag) - return res; - break; - case 'f': - skipspaces(file); - // TODO: read real numbers - rnumber=0; - switch (longflag) - { - case 0: - *((float*)arg)=rnumber; - arg+=sizeof(float); - break; - case 1: - *((double*)arg)=rnumber; - arg+=sizeof(double); - break; - case 2: - *((long double*)arg)=rnumber; - arg+=sizeof(long double); - break; - default: - return res; - } - break; - default: - break; - } - format++; - res++; - } - return res; -} diff --git a/programs/games/doom/trunk/kolibc/src/file/fseek.c b/programs/games/doom/trunk/kolibc/src/file/fseek.c deleted file mode 100644 index 3d522bff63..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fseek.c +++ /dev/null @@ -1,15 +0,0 @@ - -//#include -#include "kolibc.h" - -int fseek(FILE* file,long offset,int origin) -{ - if (origin==SEEK_CUR) - offset+=file->filepos+file->strpos; - else if (origin==SEEK_END) - offset+=file->filesize; - else if (origin!=SEEK_SET) - return EOF; - - return fsetpos(file,&offset); -} diff --git a/programs/games/doom/trunk/kolibc/src/file/fsetpos.c b/programs/games/doom/trunk/kolibc/src/file/fsetpos.c deleted file mode 100644 index 067249e677..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fsetpos.c +++ /dev/null @@ -1,23 +0,0 @@ - -#include "kolibri.h" -#include "kolibc.h" - -int fsetpos(FILE* f,const fpos_t * pos) -{ int err; - size_t bytes; - - bytes = *pos; - - bytes= *pos & -8192; - err=read_file(f->filename,f->buffer,bytes, - 8192,&bytes); - if(bytes == -1) - return EOF; - - f->filepos= *pos & -8192; - f->strpos = *pos & 8191; - f->remain = 8192-f->strpos; - f->stream = f->buffer+f->strpos; - return 0; -} - diff --git a/programs/games/doom/trunk/kolibc/src/file/ftell.c b/programs/games/doom/trunk/kolibc/src/file/ftell.c deleted file mode 100644 index ce4aac0152..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/ftell.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "kolibc.h" - -long ftell(FILE* file) -{ - return file->filepos+file->strpos; -} - diff --git a/programs/games/doom/trunk/kolibc/src/file/fwrite.c b/programs/games/doom/trunk/kolibc/src/file/fwrite.c deleted file mode 100644 index 011cfd872f..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/fwrite.c +++ /dev/null @@ -1,44 +0,0 @@ - -#include -#include "kolibc.h" - -int write_buffer(FILE *f); -int fill_buff(FILE* f); - -int fwrite(const void* src,size_t size,size_t count,FILE* f) -{ - size_t req; - size_t cnt; - -//append mode unsupported - -/************ - if(!((f->mode & FILE_OPEN_WRITE)|(f->mode & FILE_OPEN_PLUS))) - return EOF; - - req=count*size; - count=0; - while(req) - { - if(f->remain) - { cnt= req > f->remain ? f->remain : req; - memcpy(f->stream,src,cnt); - f->stream+=cnt; - f->strpos+=cnt; - f->remain-=cnt; - count+=cnt; - req-=cnt; - } - else - { -// if(!write_buffer(f)) -// break; - f->filepos+=8192; - fill_buff(f); - }; - }; - ***********/ - return count; - - return count/size; -}; diff --git a/programs/games/doom/trunk/kolibc/src/file/rewind.c b/programs/games/doom/trunk/kolibc/src/file/rewind.c deleted file mode 100644 index 107a9bc716..0000000000 --- a/programs/games/doom/trunk/kolibc/src/file/rewind.c +++ /dev/null @@ -1,12 +0,0 @@ - -#include "kolibc.h" - -void rewind(FILE* file) -{ - file->filepos=0; - file->stream=file->buffer; - file->strpos=0; - file->remain=8192; - - fill_buff(file); -} diff --git a/programs/games/doom/trunk/kolibc/src/mem/malloc.c b/programs/games/doom/trunk/kolibc/src/mem/malloc.c deleted file mode 100644 index e13ca4e6df..0000000000 --- a/programs/games/doom/trunk/kolibc/src/mem/malloc.c +++ /dev/null @@ -1,603 +0,0 @@ - -#include "mf.h" -#include "kolibri.h" - -void * kmemcpy(void * dst, const void * src, size_t count); - -static struct m_state ms; - -void mf_init() -{ mchunkptr chp; - int i; - char *p; - - dword psize= 0x40000; - p = 0x2600000; //(char*)UserAlloc(psize); - ms.top = (mchunkptr)p; - ms.topsize = psize; - ms.smallmap=0; - ms.treemap=0; - - chp = (mchunkptr)p; - chp->head=psize|1; - - for(i=0; i<32; i++) - { - mchunkptr p = &ms.smallbins[i]; - p->fd = p; - p->bk = p; - - }; -} - -void *dlmalloc(size_t size) -{ size_t nb, psize,rsize; - dword idx; - dword smallbits; - mchunkptr B,F,p,r; - void *mem; - - nb = ((size+7)&~7)+8; - - if (nb < 256) - { - idx = nb >> 3; -// smallbits= (-1<fd; - F = p->fd; - if (B == F) - { -// ms.smallmap &= ~(1<< idx); - _asm - { - mov eax, [idx] - btr dword ptr [ms], eax - } - } - B->fd = F; - F->bk = B; - - if(rsize<16) - { - p->head = psize|PINUSE_BIT|CINUSE_BIT; - ((mchunkptr)((char*)p + psize))->head |= PINUSE_BIT; - return chunk2mem(p); - }; - p->head = nb|PINUSE_BIT|CINUSE_BIT; - r = chunk_plus_offset(p, nb); - r->head = rsize|PINUSE_BIT; - ((mchunkptr)((char*)r + rsize))->prev_foot = rsize; - { - dword I; - mchunkptr B; - mchunkptr F; - - I = rsize>>3; - ms.smallmap |= 1<< I; - B = &ms.smallbins[I]; - F = B->fd; - B->fd = r; - F->bk = r; - r->fd = F; - r->bk = B; - } - return chunk2mem(p); - } - if (ms.treemap != 0 && (mem = malloc_small(nb)) != 0) - return mem; - } - else - { - if (ms.treemap != 0 && (mem = malloc_large(nb)) != 0) - return mem; - }; - - if (nb < ms.topsize) - { - size_t rsize = ms.topsize -= nb; - mchunkptr p = ms.top; - mchunkptr r = ms.top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - p->head = nb |PINUSE_BIT|CINUSE_BIT; - return chunk2mem(p); - }; - - return 0; -}; - -void dlfree(void *mem) -{ size_t psize; - size_t prevsize; - size_t nsize; - mchunkptr next; - mchunkptr prev; - - mchunkptr p = mem2chunk(mem); - if(p->head & CINUSE_BIT) - { - psize = p->head & (~3); - next = chunk_plus_offset(p, psize); - - if(!(p->head & PINUSE_BIT)) - { - prevsize = p->prev_foot; - prev=(mchunkptr)(((char*)p) - prevsize); - psize += prevsize; - p = prev; - if (prevsize < 256) - { - dword I; - mchunkptr F = p->fd; - mchunkptr B = p->bk; - I = prevsize>>3; - if (F == B) - { - ms.smallmap &= ~(1<< I); - } - F->bk = B; - B->fd = F; - } - else - unlink_large_chunk((tchunkptr)p); - }; - - if(next->head & PINUSE_BIT) - { - if (! (next->head & CINUSE_BIT)) - { - if (next == ms.top) - { size_t tsize = ms.topsize += psize; - ms.top = p; - p->head = tsize | PINUSE_BIT; - return; - } - - nsize = next->head & ~INUSE_BITS; - psize += nsize; - - if (nsize < 256) - { - dword I; - mchunkptr F = next->fd; - mchunkptr B = next->bk; - I = nsize>>3; - if (F == B) - ms.smallmap &= ~(1<< I); - F->bk = B; - B->fd = F; - } - else - unlink_large_chunk((tchunkptr)next); - - p->head = psize|PINUSE_BIT; - ((mchunkptr)((char*)p+psize))->prev_foot = psize; - } - else - { - next->head &= ~PINUSE_BIT; - p->head = psize|PINUSE_BIT; - ((mchunkptr)((char*)p+psize))->prev_foot = psize; - }; - insert_chunk(p,psize); - }; - }; -} - -static void insert_chunk(mchunkptr P, size_t S) -{ - dword I; - mchunkptr B; - mchunkptr F; - if (S < 256) - { - I = S>>3; - B = &ms.smallbins[I]; - F = B->fd; - ms.smallmap |= 1<< I; - - B->fd = P; - F->bk = P; - P->fd = F; - P->bk = B; - } - else - insert_large_chunk((tchunkptr)P, S); -}; - -/******** -static void insert_small_chunk(mchunkptr p, size_t s) -{ - DWORD I = s>>3; - - mchunkptr B = &ms.smallbins[I]; - mchunkptr F = B->fd; - if (!(ms.smallmap & 1<fd = p; - F->bk = p; - p->fd = F; - p->bk = B; -} -*********/ - -static dword compute_tree_index(size_t s) -{ dword idx; - - _asm - { mov edx, [s] - shr edx, 8 - bsr eax, edx - lea ecx, [eax+7] - mov edx, [s] - shr edx, cl - and edx, 1 - lea eax, [edx+eax*2] - mov [idx], eax - }; - - return idx; -}; - -static void insert_large_chunk(tchunkptr X, size_t S) -{ - tbinptr* H; - dword I; - I = compute_tree_index(S); - H = &ms.treebins[I]; - X->index = I; - X->child[0] = X->child[1] = 0; - if (!(ms.treemap & 1<parent = (tchunkptr)H; - X->fd = X->bk = X; - } - else - { - tchunkptr T = *H; - size_t K = S << leftshift_for_tree_index(I); - for (;;) - { - if ((T->head & ~INUSE_BITS) != S) - { - tchunkptr* C = &(T->child[(K >> 31) & 1]); - K <<= 1; - if (*C != 0) - T = *C; - else - { - *C = X; - X->parent = T; - X->fd = X->bk = X; - break; - } - } - else - { - tchunkptr F = T->fd; - T->fd = F->bk = X; - X->fd = F; - X->bk = T; - X->parent = 0; - break; - }; - }; - }; -}; - -static void* malloc_small(size_t nb) -{ - tchunkptr t, v; - mchunkptr r; - size_t rsize; - dword i; - - _asm - { bsf ecx,dword ptr [ms+4] - mov [i], ecx - } - v = t = ms.treebins[i]; - rsize = (t->head & ~INUSE_BITS) - nb; - - while ((t = leftmost_child(t)) != 0) - { - size_t trem = (t->head & ~INUSE_BITS) - nb; - if (trem < rsize) - { rsize = trem; - v = t; - } - } - - r = chunk_plus_offset((mchunkptr)v, nb); - unlink_large_chunk(v); - if (rsize < 16) - { - v->head = (rsize + nb)|PINUSE_BIT|CINUSE_BIT; - ((mchunkptr)((char*)v+rsize + nb))->head |= PINUSE_BIT; - } - else - { - v->head = nb|PINUSE_BIT|CINUSE_BIT; - r->head = rsize|PINUSE_BIT; - ((mchunkptr)((char*)r+rsize))->prev_foot = rsize; - insert_chunk(r, rsize); -// replace_dv(r, rsize); - } - return chunk2mem(v); -} - -/******** -static void replace_dv(mchunkptr P, size_t S) -{ - size_t DVS = ms.dvsize; - if (DVS != 0) - { - mchunkptr DV = ms.dv; - insert_small_chunk(DV, DVS); - } - ms.dvsize = S; - ms.dv = P; -} -***********/ - -void static unlink_large_chunk(tchunkptr X) -{ - tchunkptr XP = X->parent; - tchunkptr R; - if (X->bk != X) - { - tchunkptr F = X->fd; - R = X->bk; - F->bk = R; - R->fd = F; - } - else - { - tchunkptr* RP; - if (((R = *(RP = &(X->child[1]))) != 0) || - ((R = *(RP = &(X->child[0]))) != 0)) - { - tchunkptr* CP; - while ((*(CP = &(R->child[1])) != 0) || - (*(CP = &(R->child[0])) != 0)) - { - R = *(RP = CP); - } - *RP = 0; - } - } - if (XP != 0) - { - tbinptr* H = &ms.treebins[X->index]; - if (X == *H) - { - if ((*H = R) == 0) - ms.treemap &= ~(1<index); - } - else - { - if (XP->child[0] == X) - XP->child[0] = R; - else - XP->child[1] = R; - }; - if (R != 0) - { - tchunkptr C0, C1; - R->parent = XP; - if ((C0 = X->child[0]) != 0) - { - R->child[0] = C0; - C0->parent = R; - } - if ((C1 = X->child[1]) != 0) - { - R->child[1] = C1; - C1->parent = R; - } - } - } -} - -static void* malloc_large(size_t nb) -{ - tchunkptr v = 0; - size_t rsize = -nb; /* Unsigned negation */ - tchunkptr t; - dword idx; - idx = compute_tree_index(nb); - - if ((t = ms.treebins[idx]) != 0) - { - /* Traverse tree for this bin looking for node with size == nb */ - size_t sizebits = nb << leftshift_for_tree_index(idx); - tchunkptr rst = 0; /* The deepest untaken right subtree */ - for (;;) - { - tchunkptr rt; - size_t trem = (t->head & ~INUSE_BITS) - nb; - - if (trem < rsize) - { - v = t; - if ((rsize = trem) == 0) - break; - } - rt = t->child[1]; - t = t->child[(sizebits >> 31) & 1]; - if (rt != 0 && rt != t) - rst = rt; - if (t == 0) - { - t = rst; /* set t to least subtree holding sizes > nb */ - break; - } - sizebits <<= 1; - } - } - - if (t == 0 && v == 0) - { /* set t to root of next non-empty treebin */ - dword leftbits = (-1<head & ~INUSE_BITS) - nb; - if (trem < rsize) - { - rsize = trem; - v = t; - } - t = leftmost_child(t); - } - - /* If dv is a better fit, return 0 so malloc will use it */ - if (v != 0) - { - mchunkptr r = chunk_plus_offset((mchunkptr)v, nb); - unlink_large_chunk(v); - if (rsize < 16) - { - v->head = (rsize + nb)|PINUSE_BIT|CINUSE_BIT; - ((mchunkptr)((char*)v+rsize + nb))->head |= PINUSE_BIT; - } - else - { - v->head = nb|PINUSE_BIT|CINUSE_BIT; - r->head = rsize|PINUSE_BIT; - ((mchunkptr)((char*)r+rsize))->prev_foot = rsize; - insert_chunk((mchunkptr)r, rsize); - } - return chunk2mem(v); - } - return 0; -} - -static void* internal_realloc(struct m_state *m, void* oldmem, - size_t bytes); - -void* dlrealloc(void* oldmem, size_t bytes) -{ - if (oldmem == 0) - return dlmalloc(bytes); - else - { - struct m_state *m = &ms; - return internal_realloc(m, oldmem, bytes); - } -}; - -#define check_inuse_chunk(M,P) - -#define MAX_REQUEST 256*1024*1024 -#define set_inuse(M,p,s)\ - ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ - ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) - -static void* internal_realloc(struct m_state *m, void* oldmem, size_t bytes) -{ mchunkptr oldp; - size_t oldsize; - mchunkptr next; - mchunkptr newp; - void* extra; - - if (bytes >= MAX_REQUEST) - return 0; - - oldp = mem2chunk(oldmem); - oldsize = oldp->head & ~INUSE_BITS; - next = chunk_plus_offset(oldp, oldsize); - newp = 0; - extra = 0; - - /* Try to either shrink or extend into top. Else malloc-copy-free */ - - if( (oldp->head & CINUSE_BIT) && - ((char*)oldp < (char*)next)&& - (next->head & PINUSE_BIT)) - { - size_t nb = ((bytes+7)&~7)+8; - if (oldsize >= nb) - { /* already big enough */ - size_t rsize = oldsize - nb; - newp = oldp; - if (rsize >= 16) - { - mchunkptr remainder = chunk_plus_offset(newp, nb); - set_inuse(m, newp, nb); - set_inuse(m, remainder, rsize); - extra = chunk2mem(remainder); - } - } - else - if (next == m->top && oldsize + m->topsize > nb) - { - /* Expand into top */ - size_t newsize = oldsize + m->topsize; - size_t newtopsize = newsize - nb; - mchunkptr newtop = chunk_plus_offset(oldp, nb); - set_inuse(m, oldp, nb); - newtop->head = newtopsize |PINUSE_BIT; - m->top = newtop; - m->topsize = newtopsize; - newp = oldp; - } - } - else - { - return 0; - } - - - if (newp != 0) - { - if (extra != 0) - dlfree(extra); - - check_inuse_chunk(m, newp); - return chunk2mem(newp); - } - else - { - void* newmem = dlmalloc(bytes); - if (newmem != 0) - { - size_t oc = oldsize - 4; - memcpy(newmem, oldmem, (oc < bytes)? oc : bytes); - dlfree(oldmem); - } - return newmem; - } - return 0; -} - diff --git a/programs/games/doom/trunk/kolibc/src/string/atoi.c b/programs/games/doom/trunk/kolibc/src/string/atoi.c deleted file mode 100644 index 9ac5bf4c8b..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/atoi.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "kolibc.h" - -/* -** atoi(s) - convert s to integer. -*/ -int atoi(char *s) -{ - int sign, n; - while(isspace(*s)) ++s; - sign = 1; - switch(*s) { - case '-': sign = -1; - case '+': ++s; - } - n = 0; - while(isdigit(*s)) n = 10 * n + *s++ - '0'; - return (sign * n); -} diff --git a/programs/games/doom/trunk/kolibc/src/string/doprnt.c b/programs/games/doom/trunk/kolibc/src/string/doprnt.c deleted file mode 100644 index 84a1edda66..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/doprnt.c +++ /dev/null @@ -1,769 +0,0 @@ -#include "kolibc.h" - -#define NULL (void*)0 - -static int isspeciall(long double d, char *bufp); -static char * exponentl(char *p, int expv, unsigned char fmtch); - - -/*** -struct __FILE { - int _cnt; - char *_ptr; - char *_base; - int _bufsiz; - int _flag; - int _file; - int _fillsize; -}; - -typedef struct __FILE FILE; -*****/ - -static char decimal = '.'; - -/* 11-bit exponent (VAX G floating point) is 308 decimal digits */ -#define MAXEXP 308 -#define MAXEXPLD 4952 /* this includes subnormal numbers */ -/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */ -#define MAXFRACT 39 - -#define DEFPREC 6 -#define DEFLPREC 6 - -#define BUF (MAXEXPLD+MAXFRACT+1) /* + decimal point */ - -#define PUTC(ch) (void) putc(ch, fp) - -#define ARG(basetype) \ - _ulong = flags&LONGINT ? va_arg(argp, long basetype) : \ - flags&SHORTINT ? (short basetype)va_arg(argp, int) : \ - va_arg(argp, int) - -static int nan2 = 0; - -static int todigit(char c) -{ - if (c<='0') return 0; - if (c>='9') return 9; - return c-'0'; -} -static char tochar(int n) -{ - if (n>=9) return '9'; - if (n<=0) return '0'; - return n+'0'; -} - -/* have to deal with the negative buffer count kludge */ - -#define LONGINT 0x01 /* long integer */ -#define LONGDBL 0x02 /* long double */ -#define SHORTINT 0x04 /* short integer */ -#define ALT 0x08 /* alternate form */ -#define LADJUST 0x10 /* left adjustment */ -#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */ -#define HEXPREFIX 0x40 /* add 0x or 0X prefix */ - -static cvtl(long double number, int prec, int flags, char *signp, - unsigned char fmtch, char *startp, char *endp); -static char *roundl(long double fract, int *expv, char *start, char *end, - char ch, char *signp); -static char *exponentl(char *p, int expv, unsigned char fmtch); - -static char NULL_REP[] = "(null)"; -static char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ - -int _doprnt(char *dest, size_t maxlen, const char *fmt0, va_list argp) -{ - const char *fmt; /* format string */ - int ch; /* character from fmt */ - int cnt; /* return value accumulator */ - int n; /* random handy integer */ - char *t; /* buffer pointer */ - long double _ldouble; /* double and long double precision arguments - %L.[eEfgG] */ - unsigned long _ulong; /* integer arguments %[diouxX] */ - int base; /* base for [diouxX] conversion */ - int dprec; /* decimal precision in [diouxX] */ - int fieldsz; /* field size expanded by sign, etc */ - int flags; /* flags as above */ - int fpprec; /* `extra' floating precision in [eEfgG] */ - int prec; /* precision from format (%.3d), or -1 */ - int realsz; /* field size expanded by decimal precision */ - int size; /* size of converted field or string */ - int width; /* width from format (%8d), or 0 */ - char sign; /* sign prefix (' ', '+', '-', or \0) */ - char softsign; /* temporary negative sign for floats */ - const char *digs; /* digits for [diouxX] conversion */ - char *p; - digs = "0123456789abcdef"; - - fmt = fmt0; - p = dest; - - for (cnt = 0;; ++fmt) - { - while((ch=*fmt)&&(ch!='%')) - { *p++ = ch; - cnt++; - fmt++; - maxlen--; - }; - - n = maxlen; - if (!ch) - { *p=0; - return cnt; - }; - flags = 0; dprec = 0; fpprec = 0; width = 0; - prec = -1; - sign = '\0'; -rflag: - switch (*++fmt) - { case ' ': - if (!sign) - sign = ' '; - goto rflag; - case '#': - flags |= ALT; - goto rflag; - case '*': - if ((width = va_arg(argp, int)) >= 0) - goto rflag; - width = -width; - /* FALLTHROUGH */ - case '-': - flags |= LADJUST; - goto rflag; - case '+': - sign = '+'; - goto rflag; - case '.': - if (*++fmt == '*') - n = va_arg(argp, int); - else - { n = 0; - while (isascii(*fmt) && isdigit(*fmt)) - n = 10 * n + todigit(*fmt++); - --fmt; - } - prec = n < 0 ? -1 : n; - goto rflag; - case '0': - flags |= ZEROPAD; - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do - { n = 10 * n + todigit(*fmt); - } while (isascii(*++fmt) && isdigit(*fmt)); - width = n; - --fmt; - goto rflag; - case 'L': - flags |= LONGDBL; - goto rflag; - case 'h': - flags |= SHORTINT; - goto rflag; - case 'l': - flags |= LONGINT; - goto rflag; - case 'c': - *(t = buf) = va_arg(argp, int); - size = 1; - sign = '\0'; - goto pforw; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - ARG(int); - if ((long)_ulong < 0) - { _ulong = -_ulong; - sign = '-'; - } - base = 10; - goto number; - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - if (flags & LONGDBL) - _ldouble = va_arg(argp, long double); - else - _ldouble = (long double)va_arg(argp, double); - if (prec > MAXFRACT) - { - if (*fmt != 'g' && (*fmt != 'G' || (flags&ALT))) - fpprec = prec - MAXFRACT; - prec = MAXFRACT; - } - else if (prec == -1) - { if (flags&LONGINT) - prec = DEFLPREC; - else - prec = DEFPREC; - } - if (_ldouble < 0) - { - softsign = '-'; - _ldouble = -_ldouble; - } - else - softsign = 0; - *buf = 0; - size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf, - buf + sizeof(buf)); - if (softsign && !nan2) - sign = '-'; - nan2 = 0; - t = *buf ? buf : buf + 1; - goto pforw; - case 'n': - if (flags & LONGINT) - *va_arg(argp, long *) = cnt; - else if (flags & SHORTINT) - *va_arg(argp, short *) = cnt; - else - *va_arg(argp, int *) = cnt; - break; - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - ARG(unsigned); - base = 8; - goto nosign; - case 'p': - /* NOSTRICT */ - _ulong = (unsigned long)va_arg(argp, void *); - base = 16; - goto nosign; - case 's': - if (!(t = va_arg(argp, char *))) - t = NULL_REP; - if (prec >= 0) - { char *p /*, *memchr() */; - if ((p = memchr(t, 0, prec))) - { size = p - t; - if (size > prec) - size = prec; - } - else - size = prec; - } - else - size = strlen(t); - sign = '\0'; - goto pforw; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - ARG(unsigned); - base = 10; - goto nosign; - case 'X': - digs = "0123456789ABCDEF"; - /* FALLTHROUGH */ - case 'x': - ARG(unsigned); - base = 16; - /* leading 0x/X only if non-zero */ - if (flags & ALT && _ulong != 0) - flags |= HEXPREFIX; - - /* unsigned conversions */ -nosign: sign = '\0'; -number: if ((dprec = prec) >= 0) - flags &= ~ZEROPAD; - - t = buf + BUF; - if (_ulong != 0 || prec != 0) - { - do - { - *--t = digs[_ulong % base]; - _ulong /= base; - } while (_ulong); - digs = "0123456789abcdef"; - if (flags & ALT && base == 8 && *t != '0') - *--t = '0'; /* octal leading 0 */ - } - size = buf + BUF - t; - -pforw: - fieldsz = size + fpprec; - realsz = dprec > fieldsz ? dprec : fieldsz; - if (sign) - realsz++; - if (flags & HEXPREFIX) - realsz += 2; - - /* right-adjusting blank padding */ - if ((flags & (LADJUST|ZEROPAD)) == 0 && width) - for (n = realsz; n < width; n++) - *p++ = ' '; - /* prefix */ - if (sign) - *p++ = sign; - if (flags & HEXPREFIX) - { - *p++ = '0'; - *p++ = (char)*fmt; - } - /* right-adjusting zero padding */ - if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) - for (n = realsz; n < width; n++) - *p++ = '0'; - /* leading zeroes from decimal precision */ - for (n = fieldsz; n < dprec; n++) - *p++ = '0'; - - /* the string or number proper */ - n = size; -// if (fp->_cnt - n >= 0 ) -// { -// fp->_cnt -= n; - maxlen-= n; - memcpy(p, t, n); - p+=n; -// fp->_ptr += n; -// } -// else -// while (--n >= 0) -// PUTC(*t++); - /* trailing f.p. zeroes */ - while (--fpprec >= 0) - *p++= '0'; - /* left-adjusting padding (always blank) */ - if (flags & LADJUST) - for (n = realsz; n < width; n++) - *p++ = ' '; - /* finally, adjust cnt */ - cnt += width > realsz ? width : realsz; - break; - case '\0': /* "%?" prints ?, unless ? is NULL */ - return cnt; - default: - *p++ = (char)*fmt; - cnt++; - } - } - /* NOTREACHED */ -} - -static long double pten[] = -{ - 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 1e64, 1e128, 1e256}; - -static long double ptenneg[] = -{ - 1e-1L, 1e-2L, 1e-4L, 1e-8L, 1e-16L, 1e-32L, 1e-64L, 1e-128L, 1e-256L, - 1e-512L, 1e-1024L, 1e-2048L, 1e-4096L -}; - -#define MAXP 4096 -#define NP 12 -#define P (4294967296.0L * 4294967296.0L * 2.0L) /* 2^65 */ -static long double INVPREC = P; -static long double PREC = 1.0L/P; -#undef P -/* - * Defining FAST_LDOUBLE_CONVERSION results in a little bit faster - * version, which might be less accurate (about 1 bit) for long - * double. For 'normal' double it doesn't matter. - */ -/* #define FAST_LDOUBLE_CONVERSION */ - -static int -cvtl(long double number, int prec, int flags, char *signp, unsigned char fmtch, - char *startp, char *endp) -{ - char *p, *t; - long double fract; - int dotrim, expcnt, gformat; - long double integer, tmp; - - if ((expcnt = isspeciall(number, startp))) - return(expcnt); - - dotrim = expcnt = gformat = 0; - /* fract = modfl(number, &integer); */ - integer = number; - - /* get an extra slot for rounding. */ - t = ++startp; - - p = endp - 1; - if (integer) - { - int i, lp=NP, pt=MAXP; -#ifndef FAST_LDOUBLE_CONVERSION - long double oint = integer, dd=1.0L; -#endif - if (integer > INVPREC) - { - integer *= PREC; - while(lp >= 0) { - if (integer >= pten[lp]) - { - expcnt += pt; - integer *= ptenneg[lp]; -#ifndef FAST_LDOUBLE_CONVERSION - dd *= pten[lp]; -#endif - } - pt >>= 1; - lp--; - } -#ifndef FAST_LDOUBLE_CONVERSION - integer = oint/dd; -#else - integer *= INVPREC; -#endif - } - /* - * Do we really need this ? - */ - for (i = 0; i < expcnt; i++) - *p-- = '0'; - } - number = integer; - // fract = modfl(number, &integer); - /* - * get integer portion of number; put into the end of the buffer; the - * .01 is added for modf(356.0 / 10, &integer) returning .59999999... - */ - for (; integer; ++expcnt) - { -// tmp = modfl(integer * 0.1L , &integer); - *p-- = tochar((int)((tmp + .01L) * 10)); - } - switch(fmtch) - { - case 'f': - /* reverse integer into beginning of buffer */ - if (expcnt) - for (; ++p < endp; *t++ = *p); - else - *t++ = '0'; - /* - * if precision required or alternate flag set, add in a - * decimal point. - */ - if (prec || flags&ALT) - *t++ = decimal; - /* if requires more precision and some fraction left */ - if (fract) - { - if (prec) - do { -// fract = modfl(fract * 10.0L, &tmp); - *t++ = tochar((int)tmp); - } while (--prec && fract); - if (fract) - startp = roundl(fract, (int *)NULL, startp, - t - 1, (char)0, signp); - } - for (; prec--; *t++ = '0'); - break; - case 'e': - case 'E': - eformat: - if (expcnt) - { - *t++ = *++p; - if (prec || flags&ALT) - *t++ = decimal; - /* if requires more precision and some integer left */ - for (; prec && ++p < endp; --prec) - *t++ = *p; - /* - * if done precision and more of the integer component, - * round using it; adjust fract so we don't re-round - * later. - */ - if (!prec && ++p < endp) - { - fract = 0; - startp = roundl((long double)0.0L, &expcnt, - startp, t - 1, *p, signp); - } - /* adjust expcnt for digit in front of decimal */ - --expcnt; - } - /* until first fractional digit, decrement exponent */ - else if (fract) - { - int lp=NP, pt=MAXP; -#ifndef FAST_LDOUBLE_CONVERSION - long double ofract = fract, dd=1.0L; -#endif - expcnt = -1; - if (fract < PREC) - { - fract *= INVPREC; - while(lp >= 0) - { - if (fract <= ptenneg[lp]) - { - expcnt -= pt; - fract *= pten[lp]; -#ifndef FAST_LDOUBLE_CONVERSION - dd *= pten[lp]; -#endif - } - pt >>= 1; - lp--; - } -#ifndef FAST_LDOUBLE_CONVERSION - fract = ofract*dd; -#else - fract *= PREC; -#endif - } - /* adjust expcnt for digit in front of decimal */ - for ( /* expcnt = -1 */ ;; --expcnt) - { -// fract = modfl(fract * 10.0L, &tmp); - if (tmp) - break; - } - *t++ = tochar((int)tmp); - if (prec || flags&ALT) - *t++ = decimal; - } - else - { - *t++ = '0'; - if (prec || flags&ALT) - *t++ = decimal; - } - /* if requires more precision and some fraction left */ - if (fract) - { - if (prec) - do { -// fract = modfl(fract * 10.0L, &tmp); - *t++ = tochar((int)tmp); - } while (--prec && fract); - if (fract) - startp = roundl(fract, &expcnt, startp, - t - 1, (char)0, signp); - } - /* if requires more precision */ - for (; prec--; *t++ = '0'); - - /* unless alternate flag, trim any g/G format trailing 0's */ - if (gformat && !(flags&ALT)) - { - while (t > startp && *--t == '0'); - if (*t == decimal) - --t; - ++t; - } - t = exponentl(t, expcnt, fmtch); - break; - case 'g': - case 'G': - /* a precision of 0 is treated as a precision of 1. */ - if (!prec) - ++prec; - /* - * ``The style used depends on the value converted; style e - * will be used only if the exponent resulting from the - * conversion is less than -4 or greater than the precision.'' - * -- ANSI X3J11 - */ - if (expcnt > prec || (!expcnt && fract && fract < .0001)) - { - /* - * g/G format counts "significant digits, not digits of - * precision; for the e/E format, this just causes an - * off-by-one problem, i.e. g/G considers the digit - * before the decimal point significant and e/E doesn't - * count it as precision. - */ - --prec; - fmtch -= 2; /* G->E, g->e */ - gformat = 1; - goto eformat; - } - /* - * reverse integer into beginning of buffer, - * note, decrement precision - */ - if (expcnt) - for (; ++p < endp; *t++ = *p, --prec); - else - *t++ = '0'; - /* - * if precision required or alternate flag set, add in a - * decimal point. If no digits yet, add in leading 0. - */ - if (prec || flags&ALT) - { - dotrim = 1; - *t++ = decimal; - } - else - dotrim = 0; - /* if requires more precision and some fraction left */ - while (prec && fract) - { -// fract = modfl(fract * 10.0L, &tmp); - *t++ = tochar((int)tmp); - prec--; - } - if (fract) - startp = roundl(fract, (int *)NULL, startp, t - 1, - (char)0, signp); - /* alternate format, adds 0's for precision, else trim 0's */ - if (flags&ALT) - for (; prec--; *t++ = '0'); - else if (dotrim) - { - while (t > startp && *--t == '0'); - if (*t != decimal) - ++t; - } - } - return t - startp; -} - -static char * -roundl(long double fract, int *expv, char *start, char *end, char ch, - char *signp) -{ - long double tmp; - - if (fract) - { - if (fract == 0.5L) - { - char *e = end; - if (*e == '.') - e--; - if (*e == '0' || *e == '2' || *e == '4' - || *e == '6' || *e == '8') - { - tmp = 3.0; - goto start; - } - } -// (void)modfl(fract * 10.0L, &tmp); - } - else - tmp = todigit(ch); - start: - if (tmp > 4) - for (;; --end) - { - if (*end == decimal) - --end; - if (++*end <= '9') - break; - *end = '0'; - if (end == start) - { - if (expv) - { /* e/E; increment exponent */ - *end = '1'; - ++*expv; - } - else - { /* f; add extra digit */ - *--end = '1'; - --start; - } - break; - } - } - /* ``"%.3f", (double)-0.0004'' gives you a negative 0. */ - else if (*signp == '-') - for (;; --end) - { - if (*end == decimal) - --end; - if (*end != '0') - break; - if (end == start) - *signp = 0; - } - return start; -} - -static char * exponentl(char *p, int expv, unsigned char fmtch) -{ - char *t; - char expbuf[MAXEXPLD]; - - *p++ = fmtch; - if (expv < 0) - { - expv = -expv; - *p++ = '-'; - } - else - *p++ = '+'; - t = expbuf + MAXEXPLD; - if (expv > 9) - { - do { - *--t = tochar(expv % 10); - } while ((expv /= 10) > 9); - *--t = tochar(expv); - for (; t < expbuf + MAXEXPLD; *p++ = *t++); - } - else - { - *p++ = '0'; - *p++ = tochar(expv); - } - return p; -} - -static int isspeciall(long double d, char *bufp) -{ - struct IEEExp { - unsigned manl:32; - unsigned manh:32; - unsigned exp:15; - unsigned sign:1; - } *ip = (struct IEEExp *)&d; - - nan2 = 0; /* don't assume the static is 0 (emacs) */ - if (ip->exp != 0x7fff) - return(0); - if ((ip->manh & 0x7fffffff) || ip->manl) - { - strcpy(bufp, "NaN"); - nan2 = 1; /* kludge: we don't need the sign, it's not nice - but it should work */ - } - else - (void)strcpy(bufp, "Inf"); - return(3); -} - -static unsigned int strlen(const char* string) -{ - int i; - i=0; - while (*string++) i++; - return i; -} - -static char* strcpy(char* dst,const char* src) -{ - char* res= dst; - while(*dst++ = *src++) ; - return res; -} - diff --git a/programs/games/doom/trunk/kolibc/src/string/doscan.c b/programs/games/doom/trunk/kolibc/src/string/doscan.c deleted file mode 100644 index 9f28b936f3..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/doscan.c +++ /dev/null @@ -1,354 +0,0 @@ - -//#include -//#include -#include "ctype.h" - -//#include -//#include - -#define SPC 01 -#define STP 02 - -#define SHORT 0 -#define REGULAR 1 -#define LONG 2 -#define LONGDOUBLE 4 -#define INT 0 -#define FLOAT 1 - -//static int _innum(int **ptr, int type, int len, int size, FILE *iop, -// int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), -// int *eofptr); -//static int _instr(char *ptr, int type, int len, FILE *iop, -// int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), -// int *eofptr); -//static const char *_getccl(const unsigned char *s); - -static char _sctab[256] = { - 0,0,0,0,0,0,0,0, - 0,SPC,SPC,SPC,SPC,SPC,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - SPC,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, -}; - -static int nchars = 0; - -//int -//_doscan(FILE *iop, const char *fmt, void **argp) -//{ -// return(_doscan_low(iop, fgetc, ungetc, fmt, argp)); -//} - -int _doscan_low(char *src, const char *fmt, void **argp) -{ - int ch; - int nmatch, len, ch1; - int **ptr, fileended, size; - - nchars = 0; - nmatch = 0; - fileended = 0; - for (;;) switch (ch = *fmt++) { - case '\0': - return (nmatch); - case '%': - if ((ch = *fmt++) == '%') - goto def; - if (ch == 'n') - { - **(int **)argp++ = nchars; - break; - } - if (fileended) - return(nmatch? nmatch: -1); - ptr = 0; - if (ch != '*') - ptr = (int **)argp++; - else - ch = *fmt++; - len = 0; - size = REGULAR; - while (isdigit(ch)) { - len = len*10 + ch - '0'; - ch = *fmt++; - } - if (len == 0) - len = 30000; - if (ch=='l') { - size = LONG; - ch = *fmt++; - } else if (ch=='h') { - size = SHORT; - ch = *fmt++; - } else if (ch=='L') { - size = LONGDOUBLE; - ch = *fmt++; - } else if (ch=='[') - fmt = _getccl((const unsigned char *)fmt); - if (isupper(ch)) { - /* ch = tolower(ch); - gcc gives warning: ANSI C forbids braced - groups within expressions */ - ch += 'a' - 'A'; - size = LONG; - } - if (ch == '\0') - return(-1); - if (_innum(ptr, ch, len, size, src, &fileended) && ptr) - nmatch++; -/* breaks %n */ -/* if (fileended) { - return(nmatch? nmatch: -1); - } */ - break; - case ' ': - case '\n': - case '\t': - case '\r': - case '\f': - case '\v': - while (((nchars++, ch1 = scan_getc(iop))!=EOF) && (_sctab[ch1] & SPC)) - ; - if (ch1 != EOF) - { - scan_ungetc(ch1, iop); - } - nchars--; - break; - - default: - def: - ch1 = scan_getc(iop); - if (ch1 != EOF) nchars++; - if (ch1 != ch) { - if (ch1==EOF) - return(-1); - scan_ungetc(ch1, iop); - nchars--; - return(nmatch); - } - } -} - -static int -_innum(int **ptr, int type, int len, int size, FILE *iop, - int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr) -{ - register char *np; - char numbuf[64]; - register c, base; - int expseen, scale, negflg, c1, ndigit; - long lcval; - int cpos; - - if (type=='c' || type=='s' || type=='[') - return(_instr(ptr? *(char **)ptr: (char *)NULL, type, len, - iop, scan_getc, scan_ungetc, eofptr)); - lcval = 0; - ndigit = 0; - scale = INT; - if (type=='e'||type=='f'||type=='g') - scale = FLOAT; - base = 10; - if (type=='o') - base = 8; - else if (type=='x') - base = 16; - np = numbuf; - expseen = 0; - negflg = 0; - while (((nchars++, c = scan_getc(iop)) != EOF) && (_sctab[c] & SPC)) - ; - if (c == EOF) nchars--; - if (c=='-') { - negflg++; - *np++ = c; - c = scan_getc(iop); - nchars++; - len--; - } else if (c=='+') { - len--; - c = scan_getc(iop); - nchars++; - } - cpos = 0; - for ( ; --len>=0; *np++ = c, c = scan_getc(iop), nchars++) { - cpos++; - if (c == '0' && cpos == 1 && type == 'i') - base = 8; - if ((c == 'x' || c == 'X') && (type == 'i' || type == 'x') - && cpos == 2 && lcval == 0) - { - base = 16; - continue; - } - if (isdigit(c) - || (base==16 && (('a'<=c && c<='f') || ('A'<=c && c<='F')))) { - ndigit++; - if (base==8) - lcval <<=3; - else if (base==10) - lcval = ((lcval<<2) + lcval)<<1; - else - lcval <<= 4; - c1 = c; - if (isdigit(c)) - c -= '0'; - else if ('a'<=c && c<='f') - c -= 'a'-10; - else - c -= 'A'-10; - lcval += c; - c = c1; - continue; - } else if (c=='.') { - if (base!=10 || scale==INT) - break; - ndigit++; - continue; - } else if ((c=='e'||c=='E') && expseen==0) { - if (base!=10 || scale==INT || ndigit==0) - break; - expseen++; - *np++ = c; - c = scan_getc(iop); - nchars++; - if (c!='+'&&c!='-'&&('0'>c||c>'9')) - break; - } else - break; - } - if (negflg) - lcval = -lcval; - if (c != EOF) { - scan_ungetc(c, iop); - *eofptr = 0; - } else - *eofptr = 1; - nchars--; - if (ptr==NULL || np==numbuf || (negflg && np==numbuf+1) ) /* gene dykes*/ - return(0); - *np++ = 0; - switch((scale<<4) | size) { - - case (FLOAT<<4) | SHORT: - case (FLOAT<<4) | REGULAR: - **(float **)ptr = atof(numbuf); - break; - - case (FLOAT<<4) | LONG: - **(double **)ptr = atof(numbuf); - break; - - case (FLOAT<<4) | LONGDOUBLE: - **(long double **)ptr = _atold(numbuf); - break; - - case (INT<<4) | SHORT: - **(short **)ptr = (short)lcval; - break; - - case (INT<<4) | REGULAR: - **(int **)ptr = (int)lcval; - break; - - case (INT<<4) | LONG: - case (INT<<4) | LONGDOUBLE: - **(long **)ptr = lcval; - break; - } - return(1); -} - -static int -_instr(char *ptr, int type, int len, FILE *iop, - int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr) -{ - register ch; - register char *optr; - int ignstp; - - *eofptr = 0; - optr = ptr; - if (type=='c' && len==30000) - len = 1; - ignstp = 0; - if (type=='s') - ignstp = SPC; - while ((nchars++, ch = scan_getc(iop)) != EOF && _sctab[ch] & ignstp) - ; - ignstp = SPC; - if (type=='c') - ignstp = 0; - else if (type=='[') - ignstp = STP; - while (ch!=EOF && (_sctab[ch]&ignstp)==0) { - if (ptr) - *ptr++ = ch; - if (--len <= 0) - break; - ch = scan_getc(iop); - nchars++; - } - if (ch != EOF) { - if (len > 0) - { - scan_ungetc(ch, iop); - nchars--; - } - *eofptr = 0; - } else - { - nchars--; - *eofptr = 1; - } - if (ptr && ptr!=optr) { - if (type!='c') - *ptr++ = '\0'; - return(1); - } - return(0); -} - -static const char * -_getccl(const unsigned char *s) -{ - register c, t; - - t = 0; - if (*s == '^') { - t++; - s++; - } - for (c = 0; c < (sizeof _sctab / sizeof _sctab[0]); c++) - if (t) - _sctab[c] &= ~STP; - else - _sctab[c] |= STP; - if ((c = *s) == ']' || c == '-') { /* first char is special */ - if (t) - _sctab[c] |= STP; - else - _sctab[c] &= ~STP; - s++; - } - while ((c = *s++) != ']') { - if (c==0) - return((const char *)--s); - else if (c == '-' && *s != ']' && s[-2] < *s) { - for (c = s[-2] + 1; c < *s; c++) - if (t) - _sctab[c] |= STP; - else - _sctab[c] &= ~STP; - } else if (t) - _sctab[c] |= STP; - else - _sctab[c] &= ~STP; - } - return((const char *)s); -} diff --git a/programs/games/doom/trunk/kolibc/src/string/is.c b/programs/games/doom/trunk/kolibc/src/string/is.c deleted file mode 100644 index 9d1e6de27f..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/is.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "ctype.h" - -short int _is[128] = { - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004, - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, - 0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253, - 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, - 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, - 0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073, - 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, - 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, - 0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004 - }; diff --git a/programs/games/doom/trunk/kolibc/src/string/istable.c b/programs/games/doom/trunk/kolibc/src/string/istable.c deleted file mode 100644 index 4f1a12cd6e..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/istable.c +++ /dev/null @@ -1,263 +0,0 @@ -#include "kolibc.h" - -const char _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__ }; diff --git a/programs/games/doom/trunk/kolibc/src/string/memchr.c b/programs/games/doom/trunk/kolibc/src/string/memchr.c deleted file mode 100644 index ad6e6afe4d..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/memchr.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "string.h" - -#if 0 -void* memchr(const void* buf,int c,int count) -{ - int i; - for (i=0;i 0 ) - ret = 1 ; - return( ret ); -} - -char *strcat (char * dst, const char * src) -{ - char * cp = dst; - - while( *cp ) - cp++; - - while( *cp++ = *src++ ) ; - - return dst ; -} - -int abs (int number ) -{ - return( number>=0 ? number : -number ); -} - -#endif \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/string/sprintf.c b/programs/games/doom/trunk/kolibc/src/string/sprintf.c deleted file mode 100644 index ca9498342e..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/sprintf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "kolibc.h" - -int _doprnt(char *dest, size_t maxlen, const char *fmt, - va_list argp); - - -int sprintf(char *dest, const char *format,...) -{ - va_list arg; - va_start (arg, format); - return _doprnt(dest,512, format, arg); -} - - diff --git a/programs/games/doom/trunk/kolibc/src/string/strcpy.c b/programs/games/doom/trunk/kolibc/src/string/strcpy.c deleted file mode 100644 index 3ff1b2b365..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strcpy.c +++ /dev/null @@ -1,7 +0,0 @@ - -char* strcpy(char* dst,const char* src) -{ - char* res= dst; - while(*dst++ = *src++) ; - return res; -} \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/string/strlen.c b/programs/games/doom/trunk/kolibc/src/string/strlen.c deleted file mode 100644 index 8e8b09df1e..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strlen.c +++ /dev/null @@ -1,7 +0,0 @@ -unsigned int strlen(const char* string) -{ - int i; - i=0; - while (*string++) i++; - return i; -} diff --git a/programs/games/doom/trunk/kolibc/src/string/strncmp.c b/programs/games/doom/trunk/kolibc/src/string/strncmp.c deleted file mode 100644 index 1eb92f26cf..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strncmp.c +++ /dev/null @@ -1,12 +0,0 @@ -int strncmp(const char* string1, const char* string2, int count) -{ - while(count>0 && *string1==*string2) - { - if (*string1) return 0; - ++string1; - ++string2; - --count; - } - if(count) return (*string1 - *string2); - return 0; -} \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/string/strncpy.c b/programs/games/doom/trunk/kolibc/src/string/strncpy.c deleted file mode 100644 index 9c4b9fab2c..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strncpy.c +++ /dev/null @@ -1,14 +0,0 @@ -char* strncpy(char* strDest,const char* strSource,int count) -{ - char* res; - res=strDest; - while (count>0) - { - *strDest=*strSource; - if (*strSource!='\0') - strSource++; - strDest++; - count--; - } - return res; -} \ No newline at end of file diff --git a/programs/games/doom/trunk/kolibc/src/string/strrchr.c b/programs/games/doom/trunk/kolibc/src/string/strrchr.c deleted file mode 100644 index 4eb7166ab0..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strrchr.c +++ /dev/null @@ -1,14 +0,0 @@ -char* strrchr(const char* s,int c) -{ - char* res; - res=(char*)0; - while (1) - { - if (*s==(char)c) - res=(char*)s; - if (*s=='\0') - break; - s++; - } - return res; -} diff --git a/programs/games/doom/trunk/kolibc/src/string/strupr.c b/programs/games/doom/trunk/kolibc/src/string/strupr.c deleted file mode 100644 index f10cfdb177..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/strupr.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "kolibc.h" - -char * strupr(char *_s) -{ - char *rv = _s; - while (*_s) - { - *_s = toupper(*_s); - _s++; - } - return rv; -} diff --git a/programs/games/doom/trunk/kolibc/src/string/toupper.c b/programs/games/doom/trunk/kolibc/src/string/toupper.c deleted file mode 100644 index a8b1becdc6..0000000000 --- a/programs/games/doom/trunk/kolibc/src/string/toupper.c +++ /dev/null @@ -1,8 +0,0 @@ -/* -** return upper-case of c if it is lower-case, else c -*/ -char toupper(char c) -{ - if(c<='z' && c>='a') return (c-32); - return (c); -}