/programs/develop/open watcom/trunk/clib_r.tgt |
---|
File deleted |
/programs/develop/open watcom/trunk/clib.wpj |
---|
File deleted |
/programs/develop/open watcom/trunk/clib/handleio/write.c |
---|
File deleted |
/programs/develop/open watcom/trunk/clib/handleio/filelen.c |
---|
File deleted |
/programs/develop/open watcom/trunk/clib/handleio/int64.h |
---|
File deleted |
/programs/develop/open watcom/trunk/clib/src/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 |
/programs/develop/open watcom/trunk/clib/src/fstatus.inc |
---|
0,0 → 1,47 |
;***************************************************************************** |
;* |
;* Open Watcom Project |
;* |
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
;* |
;* ======================================================================== |
;* |
;* This file contains Original Code and/or Modifications of Original |
;* Code as defined in and that are subject to the Sybase Open Watcom |
;* Public License version 1.0 (the 'License'). You may not use this file |
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
;* provided with the Original Code and Modifications, and is also |
;* available at www.sybase.com/developer/opensource. |
;* |
;* The Original Code and all software distributed under the License are |
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
;* NON-INFRINGEMENT. Please see the License for the specific language |
;* governing rights and limitations under the License. |
;* |
;* ======================================================================== |
;* |
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
;* DESCRIBE IT HERE! |
;* |
;***************************************************************************** |
FPE_OK equ 0 |
FPE_INVALID equ 81h |
FPE_DENORMAL equ 82h |
FPE_ZERODIVIDE equ 83h |
FPE_OVERFLOW equ 84h |
FPE_UNDERFLOW equ 85h |
FPE_INEXACT equ 86h |
FPE_UNEMULATED equ 87h |
FPE_SQRTNEG equ 88h |
FPE_STACKOVERFLOW equ 8ah |
FPE_STACKUNDERFLOW equ 8bh |
FPE_EXPLICITGEN equ 8ch |
FPE_IOVERFLOW equ 8dh |
FPE_LOGERR equ 8eh |
FPE_MODERR equ 8fh |
/programs/develop/open watcom/trunk/clib/src/saferlib.h |
---|
0,0 → 1,103 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Internal data and routines for "Safer C", or bounds-checking |
* library extension. |
* |
****************************************************************************/ |
#ifndef _SAFERLIB_H_INCLUDED |
#define _SAFERLIB_H_INCLUDED |
#define __STDC_WANT_LIB_EXT1__ 1 |
#include <stdlib.h> |
#include <stdint.h> |
// Maximum length of runtime-constraint error message |
#define RTCT_MSG_MAX 128 |
#define _RWD_rtcthandler __runtime_constraint_handler |
extern constraint_handler_t __runtime_constraint_handler; |
extern void __rtct_fail( const char *fn, const char *reason, void *reserved ); |
// Runtime-constraint validation macros. Call the handler and return zero if check |
// failed, return non-zero value if check succeeded. |
#define __check_constraint_nullptr( arg ) \ |
((arg == NULL) ? __rtct_fail( __func__, #arg " == NULL", NULL ), 0 : 1) |
#define __check_constraint_maxsize( arg ) \ |
((arg > RSIZE_MAX) ? __rtct_fail( __func__, #arg " > RSIZE_MAX", NULL ), 0 : 1) |
#define __check_constraint_zero( arg ) \ |
((arg == 0) ? __rtct_fail( __func__, #arg " == 0", NULL ), 0 : 1) |
#define __check_constraint_toosmall( name, left ) \ |
((left == 0) ? __rtct_fail( __func__, #name " is too small to hold data", NULL ), 0 : 1) |
// Runtime-constraint validation macros. Construct the message and return |
// zero if check failed, return non-zero value if check succeeded. |
// __rtct_fail has to be explicitly called later. |
#define __check_constraint_nullptr_msg( msg, arg ) \ |
((arg == NULL) ? ( msg = #arg " == NULL" ), 0 : 1) |
#define __check_constraint_maxsize_msg( msg, arg ) \ |
((arg > RSIZE_MAX) ? ( msg = #arg " > RSIZE_MAX" ), 0 : 1) |
#define __check_constraint_zero_msg( msg, arg ) \ |
((arg == 0) ? ( msg = #arg " == 0" ), 0 : 1) |
#define __check_constraint_toosmall_msg( msg, name, left ) \ |
((left == 0) ? ( msg = #name " is too small to hold data" ), 0 : 1) |
#define __check_constraint_a_gt_b_msg( msg, a, b ) \ |
((a > b) ? ( msg = #a " > " #b ), 0 : 1) |
#define __check_constraint_overlap_msg( msg, p1, len1, p2, len2 ) \ |
(((p1 == p2) || ( (p1 > p2) && ( p1 < (CHAR_TYPE *)p2 + len2 * sizeof( CHAR_TYPE ))) \ |
|| ( (p2 > p1) && ( p2 < (CHAR_TYPE *)p1 + len1 * sizeof( CHAR_TYPE )))) \ |
? ( msg = #p1 " overlap " #p2 ), 0 : 1) |
// For 16-bit targets, the RSIZE_MAX check is effectively no-op. Object sizes |
// up to SIZE_MAX are legal and not uncommon. |
#if RSIZE_MAX == SIZE_MAX |
#undef __check_constraint_maxsize |
#define __check_constraint_maxsize( arg ) 1 |
#undef __check_constraint_maxsize_msg |
#define __check_constraint_maxsize_msg( msg, arg ) 1 |
#define __lte_rsizmax( arg ) 1 |
#else |
#define __lte_rsizmax( arg ) (arg <= RSIZE_MAX) |
#endif |
#endif // _SAFERLIB_H_INCLUDED |
/programs/develop/open watcom/trunk/clib/src/strdup.h |
---|
0,0 → 1,41 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#ifndef __STRDUP_H_INCLUDED |
#define __STRDUP_H_INCLUDED |
#include "variety.h" |
#include "widechar.h" |
_WCRTLINK extern char *__clib_strdup( const char *str ); |
_WCRTLINK extern wchar_t *__clib_wcsdup( const wchar_t *str ); |
#endif |
/programs/develop/open watcom/trunk/clib/src/fclose.c |
---|
0,0 → 1,122 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Platform independent fclose() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include "liballoc.h" |
#include "mf.h" |
#include <string.h> |
#include "fileacc.h" |
#include "tmpfname.h" |
#include "rtdata.h" |
#include "lseek.h" |
#include "streamio.h" |
#include "close.h" |
#include "flush.h" |
#ifndef __UNIX__ |
void (*__RmTmpFileFn)( FILE *fp ); |
#endif |
int __doclose( FILE *fp, int close_handle ) |
{ |
int ret; |
if( fp->_flag == 0 ) { |
return( -1 ); /* file already closed */ |
} |
ret = 0; |
if( fp->_flag & _DIRTY ) { |
ret = __flush( fp ); |
} |
_AccessFile( fp ); |
/* |
* 02-nov-92 G.Turcotte Syncronize buffer pointer with the file pointer |
* IEEE Std 1003.1-1988 B.8.2.3.2 |
* 03-nov-03 B.Oldeman Inlined ftell; we already know the buffer isn't |
* dirty (because of the flush), so only a "get" applies |
*/ |
if( fp->_cnt != 0 ) { /* if something in buffer */ |
__lseek( fileno( fp ), -fp->_cnt, SEEK_CUR ); |
} |
if( close_handle ) { |
#if defined( __UNIX__ ) || defined( __NETWARE__ ) |
// we don't get to implement the close function on these systems |
ret |= close( fileno( fp ) ); |
#else |
ret |= __close( fileno( fp ) ); |
#endif |
} |
if( fp->_flag & _BIGBUF ) { /* if we allocated the buffer */ |
lib_free( _FP_BASE(fp) ); |
_FP_BASE(fp) = NULL; |
} |
#ifndef __UNIX__ |
/* this never happens under UNIX */ |
if( fp->_flag & _TMPFIL ) { /* if this is a temporary file */ |
__RmTmpFileFn( fp ); |
} |
#endif |
_ReleaseFile( fp ); |
return( ret ); |
} |
int __shutdown_stream( FILE *fp, int close_handle ) |
{ |
int ret; |
ret = __doclose( fp, close_handle ); |
__freefp( fp ); |
return( ret ); |
} |
_WCRTLINK int fclose( FILE *fp ) |
{ |
__stream_link *link; |
_AccessIOB(); |
link = _RWD_ostream; |
for( ;; ) { |
if( link == NULL ) { |
_ReleaseIOB(); |
return( -1 ); /* file not open */ |
} |
if( link->stream == fp ) break; |
link = link->next; |
} |
_ReleaseIOB(); |
return( __shutdown_stream( fp, 1 ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/fwrite.c |
---|
0,0 → 1,161 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR 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 fwrite() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include <string.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "qwrite.h" |
#include "flush.h" |
#include "streamio.h" |
_WCRTLINK size_t fwrite( const void *buf, size_t size, size_t n, FILE *fp ) |
{ |
size_t count; |
unsigned oflag; |
_ValidFile( fp, 0 ); |
_AccessFile( fp ); |
if( (fp->_flag & _WRITE) == 0 ) { |
__set_errno( EBADF ); |
fp->_flag |= _SFERR; |
_ReleaseFile( fp ); |
return( 0 ); /* POSIX says return 0 */ |
} |
n *= size; |
if( n == 0 ) { |
_ReleaseFile( fp ); |
return( n ); |
} |
if( _FP_BASE(fp) == NULL ) { |
__ioalloc( fp ); /* allocate buffer */ |
} |
oflag = fp->_flag & (_SFERR | _EOF); /* JBS 27-jan-92 */ |
fp->_flag &= ~(_SFERR | _EOF); /* JBS 27-jan-92 */ |
count = 0; |
#if !defined( __UNIX__ ) |
if( fp->_flag & _BINARY ) { /* binary I/O */ |
#else |
{ |
#endif |
size_t bytes_left = n, bytes; |
do { |
/* if our buffer is empty, and user's buffer is larger, |
then write directly from user's buffer. 28-apr-90 */ |
if( fp->_cnt == 0 && bytes_left >= fp->_bufsize ) { |
bytes = bytes_left & -512; /* multiple of 512 */ |
if( bytes == 0 ) { |
bytes = bytes_left; /* bufsize < 512 */ |
} |
n = __qwrite( fileno( fp ), buf, bytes ); |
if( n == -1 ) { |
fp->_flag |= _SFERR; |
} |
#if !defined( __UNIX__ ) |
else if( n == 0 ) { |
_RWD_errno = ENOSPC; |
fp->_flag |= _SFERR; |
} |
#endif |
bytes = n; |
} else { |
bytes = fp->_bufsize - fp->_cnt; |
if( bytes > bytes_left ) { |
bytes = bytes_left; |
} |
memcpy( fp->_ptr, buf, bytes ); |
fp->_ptr += bytes; |
fp->_cnt += bytes; |
fp->_flag |= _DIRTY; |
if( (fp->_cnt == fp->_bufsize) || (fp->_flag & _IONBF) ) { |
__flush(fp); |
} |
} |
buf = ((const char *)buf) + bytes; |
count += bytes; |
bytes_left -= bytes; |
} while( bytes_left && !ferror( fp ) ); |
#if !defined( __UNIX__ ) |
} else { /* text I/O */ |
const char *bufptr; |
int not_buffered; |
#ifndef __NETWARE__ |
int old_orientation; |
#endif |
/* temporarily enable buffering saving the previous setting */ |
not_buffered = 0; |
if( fp->_flag & _IONBF ) { |
not_buffered = 1; |
fp->_flag &= ~_IONBF; |
fp->_flag |= _IOFBF; |
} |
/*** Use fputc, and make it think the stream is byte-oriented ***/ |
#ifndef __NETWARE__ |
old_orientation = _FP_ORIENTATION(fp); |
_FP_ORIENTATION(fp) = _BYTE_ORIENTED; |
#endif |
bufptr = (const char *)buf; |
do { |
fputc( *(bufptr++), fp ); |
if( fp->_flag & (_EOF | _SFERR) ) break; |
++count; |
} while( count != n ); |
#ifndef __NETWARE__ |
_FP_ORIENTATION(fp) = old_orientation; |
#endif |
if( not_buffered ) { /* if wasn't buffered, then reset */ |
fp->_flag &= ~_IOFBF; |
fp->_flag |= _IONBF; |
__flush( fp ); |
} |
#endif |
} |
if( fp->_flag & _SFERR ) { |
/* |
* Quantum 11-17-92 Temporary buffering confuses the return |
* value if the call is interrupted. |
* kludge: return 0 on error |
*/ |
count = 0; |
} |
fp->_flag |= oflag; /* JBS 27-jan-92 */ |
_ReleaseFile( fp ); |
return( count / size ); |
} |
/programs/develop/open watcom/trunk/clib/src/openklbr.c |
---|
0,0 → 1,399 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR 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 <stdio.h> |
#include <stdlib.h> |
#include <stdarg.h> |
#include <string.h> |
#include <errno.h> |
#include <io.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#include <share.h> |
#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); |
int _stdcall create_file(const char *name); |
typedef struct |
{ |
char *name; |
unsigned int offset; |
}__file_handle; |
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 __openFileHandle(const CHAR_TYPE *name, int mode) |
{ |
FILEINFO info; |
__file_handle *handle; |
char *path; |
int err; |
path = getfullpath(name); |
if(err=get_fileinfo(path,&info)) |
{ |
// printf("failed getfileinfo %s\n\r", path); |
if(mode & O_CREAT) |
err=create_file(path); |
if(err) |
{ |
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 = __openFileHandle( name, mode); |
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 ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/qwrit.c |
---|
0,0 → 1,129 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <errno.h> |
#include "iomode.h" |
#include "fileacc.h" |
#include "rtcheck.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "qwrite.h" |
#include "liballoc.h" |
/* |
Use caution when setting the file pointer in a multithreaded |
application. You must synchronize access to shared resources. For |
example, an application whose threads share a file handle, update the |
file pointer, and read from the file must protect this sequence by |
using a critical section object or a mutex object. |
*/ |
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; |
typedef struct |
{ |
char *name; |
unsigned int offset; |
}__file_handle; |
int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo); |
int _stdcall write_file(const char *name,const void *buff,unsigned offset,unsigned count,unsigned *writes); |
char* getfullpath(const char* path); |
int __qwrite( int handle, const void *buffer, unsigned len ) |
{ |
int atomic; |
__file_handle *fh; |
unsigned len_written; |
__handle_check( handle, -1 ); |
fh = (__file_handle*) __getOSHandle( handle ); |
atomic = 0; |
if( __GetIOMode( handle ) & _APPEND ) |
{ |
FILEINFO info; |
_AccessFileH( handle ); |
atomic = 1; |
get_fileinfo(fh->name,&info); |
fh->offset = info.size; |
}; |
if(write_file(fh->name,buffer,fh->offset,len,&len_written)) |
{ |
if ( len_written == 0) |
{ |
if( atomic == 1 ) |
_ReleaseFileH( handle ); |
return (-1); |
}; |
}; |
fh->offset+=len_written; |
if( atomic == 1 ) |
{ |
_ReleaseFileH( handle ); |
} |
return( len_written ); |
} |
int write_once(const char *name, void *buffer, unsigned len) |
{ char *path; |
unsigned count; |
path= getfullpath(name); |
write_file(path,buffer,0,len,&count); |
lib_free(path); |
return count; |
} |
/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 <stdio.h> |
#include <string.h> |
#include <errno.h> |
#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 */ |
} |
/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 |
/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 ); |
/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 "*_"; |
/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 <stdio.h> |
#include "commode.h" |
int _commode = 0; |
/* |
* Before changing any of this, check startup/c/commode.c! |
*/ |
_WCRTLINK void _WCI86FAR __set_commode( void ) |
{ |
_commode = _COMMIT; |
} |
/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 |
/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 |
/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 |
/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 |
/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 |
/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 |
/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 <stdio.h> |
#include <unistd.h> |
#ifndef __UNIX__ |
#include <conio.h> |
#endif |
#include "fileacc.h" |
#include <errno.h> |
#include "rtdata.h" |
#include "seterrno.h" |
#ifdef __WIDECHAR__ |
#include <mbstring.h> |
#include <wchar.h> |
#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 |
/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 |
/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; |
/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 ); |
/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 <stdio.h> |
#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 ) ); |
} |
/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 */ |
/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 <stdio.h> |
#include <ctype.h> |
#ifdef __WIDECHAR__ |
#include <wctype.h> |
#endif |
#include <errno.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#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 ); |
} |
/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 ); |
/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 <stdio.h> |
#include <unistd.h> |
#include "fileacc.h" |
#include <string.h> |
#include <errno.h> |
#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 ); |
} |
/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 <stdio.h> |
#include <errno.h> |
#include <unistd.h> |
#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 */ |
} |
/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 <stdio.h> |
#include <string.h> |
#include <unistd.h> |
#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 ); |
} |
/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 |
/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 <conio.h> |
#include <stdio.h> |
#include "rtdata.h" |
_WCRTLINK int getche() |
{ |
unsigned c; |
unsigned stashed; |
stashed = _RWD_cbyte; |
c = getch(); |
if( c != EOF && stashed == 0 ) { |
putch( c ); |
} |
return( c ); |
} |
/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; |
/programs/develop/open watcom/trunk/clib/src/hdlman.c |
---|
0,0 → 1,257 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Handle manager routines. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include "liballoc.h" |
#include <string.h> |
#ifdef _M_IX86 |
#include <i86.h> |
#endif |
#include <unistd.h> |
#include <errno.h> |
#if defined(__OS2__) |
#elif defined(__WINDOWS__) || defined(__NT__) |
#endif |
#include "iomode.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "handleio.h" |
#undef __getOSHandle |
extern unsigned __NFiles; // the size of the iomode array |
extern void __grow_iomode( int num ); |
unsigned __NHandles = 0; |
#if defined(__NT__) |
HANDLE *__OSHandles = NULL; |
unsigned __growPOSIXHandles( unsigned num ) |
{ |
HANDLE *new2; |
unsigned i; |
if( num > __NHandles ) |
{ |
_AccessFList(); |
if( __OSHandles == NULL ) |
{ |
new2 = lib_malloc( num * sizeof( int ) ); |
} |
else |
{ |
new2 = lib_realloc( __OSHandles, num * sizeof( int ) ); |
} |
if( new2 == NULL ) |
{ |
__set_errno( ENOMEM ); |
num = __NHandles; |
} |
else |
{ |
for( i = __NHandles; i < num; i++ ) |
{ |
new2[ i ] = NULL_HANDLE; |
} |
__OSHandles = new2; |
__NHandles = num; |
} |
_ReleaseFList(); |
} |
return( __NHandles ); |
} |
int __allocPOSIXHandle( HANDLE hdl ) |
{ |
int i; |
_AccessFList(); |
for( i = 0; i < __NHandles; i++ ) |
{ |
if( __OSHandles[i] == NULL_HANDLE ) break; |
} |
if( i >= __NHandles ) |
{ |
// 20 -> (20+10+1) -> 31 |
// 31 -> (31+15+1) -> 47 |
// 47 -> (47+23+1) -> 71 |
__growPOSIXHandles( i + (i >> 1) + 1 ); |
// keep iomode array in sync |
if( __NHandles > __NFiles ) __grow_iomode( __NHandles ); |
for( ; i < __NHandles; i++ ) |
{ |
if( __OSHandles[i] == NULL_HANDLE ) break; |
} |
} |
if( i >= __NHandles ) |
{ |
i = -1; |
} else { |
__OSHandles[i] = hdl; |
} |
_ReleaseFList(); |
return( i ); |
} |
void __freePOSIXHandle( int hid ) |
{ |
__OSHandles[ hid ] = NULL_HANDLE; |
} |
HANDLE __getOSHandle( int hid ) |
{ |
return( __OSHandles[ hid ] ); |
} |
int __setOSHandle( unsigned hid, HANDLE hdl ) |
{ |
// call the Win32 API for a standard file handle |
switch( hid ) { |
case STDIN_FILENO: |
// SetStdHandle( STD_INPUT_HANDLE, hdl ); |
break; |
case STDOUT_FILENO: |
// SetStdHandle( STD_OUTPUT_HANDLE, hdl ); |
break; |
case STDERR_FILENO: |
// SetStdHandle( STD_ERROR_HANDLE, hdl ); |
break; |
} |
if( hid < __NHandles ) |
{ |
__OSHandles[ hid ] = hdl; |
} |
else |
{ |
hid = (unsigned)-1; // this should never happen |
} |
return( hid ); |
} |
HANDLE *__FakeHandles = 0; |
static int __topFakeHandle = 0; |
HANDLE __NTGetFakeHandle( void ) |
{ |
HANDLE os_handle; |
static DWORD fakeHandle = 0x80000000L; |
_AccessFList(); |
fakeHandle++; |
os_handle = (HANDLE)fakeHandle; |
_ReleaseFList(); |
return( os_handle ); |
} |
// called from library startup code |
void __initPOSIXHandles( void ) |
{ |
HANDLE h; |
// __OSHandles = NULL; |
// __NHandles = 0; |
__growPOSIXHandles( __NFiles ); |
h = 0; //GetStdHandle( STD_INPUT_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 0==STDIN_FILENO |
h = 0; //GetStdHandle( STD_OUTPUT_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 1==STDOUT_FILENO |
h = 0; //GetStdHandle( STD_ERROR_HANDLE ); |
if( h == 0 || h == INVALID_HANDLE_VALUE ) { |
h = (HANDLE)__NTGetFakeHandle(); |
} |
__allocPOSIXHandle( h ); // should return 3==STDERR_FILENO |
} |
static void __finiPOSIXHandles( void ) |
{ |
if( __OSHandles != NULL ) { |
lib_free( __OSHandles ); |
__OSHandles = NULL; |
} |
if( __FakeHandles != NULL ) |
{ |
int i; |
for( i = 0 ; i < __topFakeHandle ; i++ ) |
{ |
// CloseHandle( __FakeHandles[i] ); |
} |
lib_free( __FakeHandles ); |
__FakeHandles = 0; |
} |
} |
AYI( __finiPOSIXHandles, INIT_PRIORITY_LIBRARY-1 ) |
#endif |
void __set_handles( int num ) |
{ |
__NHandles = num; |
} |
_WCRTLINK int _grow_handles( int num ) |
{ |
if( num > __NHandles ) |
{ |
#if defined(MSDOS) |
#elif defined( __OS2_286__ ) |
#elif defined( __WARP__ ) |
#elif defined(__WINDOWS__) |
#elif defined(__NT__) |
{ |
num = __growPOSIXHandles( num ); |
} |
#elif defined(__NETWARE__) |
#elif defined(__UNIX__) |
#endif |
if( num > __NFiles ) { |
__grow_iomode( num ); // sets new __NFiles if successful |
} |
__NHandles = num; |
} |
return( __NHandles ); |
} |
/programs/develop/open watcom/trunk/clib/src/iomode.h |
---|
0,0 → 1,70 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: prototypes and definitions for iomode array manipulation |
* |
****************************************************************************/ |
#ifndef _IOMODE_H_INCLUDED |
#define _IOMODE_H_INCLUDED |
#if defined(__NT__) |
#include <windows.h> |
#define NULL_HANDLE (HANDLE)-1 |
#define DUMMY_HANDLE (HANDLE)-2 |
extern unsigned __NHandles; |
extern void __initPOSIXHandles( void ); |
extern unsigned __growPOSIXHandles( unsigned num ); |
extern int __allocPOSIXHandle( HANDLE hdl ); |
extern void __freePOSIXHandle( int hid ); |
extern HANDLE __getOSHandle( int hid ); |
extern int __setOSHandle( unsigned hid, HANDLE hdl ); |
extern HANDLE __NTGetFakeHandle( void ); |
extern HANDLE *__OSHandles; |
#define __getOSHandle( hid ) __OSHandles[ hid ] |
#define NT_STDIN_FILENO (__getOSHandle( STDIN_FILENO )) |
#define NT_STDOUT_FILENO (__getOSHandle( STDOUT_FILENO )) |
#define NT_STDERR_FILENO (__getOSHandle( STDERR_FILENO )) |
#endif |
#if !defined(__NETWARE__) |
extern unsigned __GetIOMode( int __handle ); |
extern int __SetIOMode( int __handle, unsigned __value ); |
extern void __SetIOMode_nogrow( int __handle, unsigned __value ); |
extern void __ChkTTYIOMode( int __handle ); |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/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 |
/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 |
/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 |
/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 <malloc.h> |
#ifdef __NETWARE__ |
/* |
// NetWare uses Alloc and Free because the heap will not have |
// been initialised at _Prelude time... |
*/ |
#define lib_malloc( x ) _NW_malloc( x ) |
#define lib_free( x ) _NW_free( x ) |
#if defined (_NETWARE_CLIB) |
#define lib_realloc( x, y, z) _NW_realloc( x, y, z ) |
#else |
#define lib_realloc( x, y) _NW_realloc( x, y) |
#endif |
#define lib_calloc( x, y ) _NW_calloc( x, y ) |
extern void *_NW_calloc( size_t __n,size_t __size ); |
extern void *_NW_malloc( size_t ); |
#if defined (_NETWARE_CLIB) |
extern void *_NW_realloc( void *ptr,size_t size,size_t old); |
#else |
extern void *_NW_realloc( void *ptr,size_t size); |
#endif |
extern void _NW_free( void *ptr ); |
#else |
#define lib_malloc( x ) malloc( x ) |
#define lib_free( x ) free( x ) |
#define lib_realloc( x, y ) realloc( x, y ) |
#define lib_nmalloc( x ) _nmalloc( x ) |
#define lib_nfree( x ) _nfree( x ) |
#define lib_nrealloc( x, y ) _nrealloc( x, y ) |
#define lib_fmalloc( x ) _fmalloc( x ) |
#define lib_ffree( x ) _ffree( x ) |
#define lib_frealloc( x, y ) _frealloc( x, y ) |
#define lib_calloc( x, y ) calloc( x, y ) |
#endif |
// these are used by the C++ library |
// they are real routines so that the C++ library |
// remains platform independent. |
#ifdef __cplusplus |
extern "C" { |
#endif |
_WCRTLINK extern void _plib_free( void *ptr ); |
_WCRTLINK extern void *_plib_malloc( size_t size ); |
#ifdef __cplusplus |
} |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/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 <stdio.h> |
#include <unistd.h> |
#ifdef __NT__ |
#include <windows.h> |
#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 ) ); |
} |
/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 |
/programs/develop/open watcom/trunk/clib/src/lseekwnt.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: low level lseek without file extend for Windows NT |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include "iomode.h" |
#include "rtcheck.h" |
#include "seterrno.h" |
#include "lseek.h" |
#include "handleio.h" |
/* |
DWORD SetFilePointer( |
HANDLE hFile, // handle to file |
LONG lDistanceToMove, // bytes to move pointer |
PLONG lpDistanceToMoveHigh, // bytes to move pointer |
DWORD dwMoveMethod // starting point |
); |
*/ |
#ifndef INVALID_SET_FILE_POINTER |
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF |
#endif |
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 ); |
} |
/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 |
/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 <alignment> |
_TEXT segment word public 'CODE' |
else |
_TEXT segment alignment public 'CODE' |
endif |
assume cs:_TEXT |
endm |
calli macro regname |
call dword ptr [regname] |
endm |
codeptr macro p1,p2 |
ifb <p2> |
extrn p1 : dword |
else |
extrn "&p1",p2 : dword |
endif |
endm |
docall macro dest |
call far ptr dest |
endm |
dojmp macro dest |
jmp far ptr dest |
endm |
defp macro dsym,exp |
dsym proc far exp |
endm |
defpe macro dsym |
ifdef _EXPORT |
dsym proc far export |
else |
dsym proc far |
endif |
endm |
defn macro dsym |
dsym proc near |
endm |
endproc macro dsym |
dsym endp |
endm |
epilog macro |
if _MODEL and _USE_32_SEGS |
pop EBP |
dec EBP |
mov ESP,EBP |
else |
pop BP |
dec BP |
endif |
endm |
prolog macro |
if _MODEL and _USE_32_SEGS |
inc EBP |
push EBP |
mov EBP,ESP |
else |
inc BP |
push BP |
mov BP,SP |
endif |
endm |
xdefp macro p1,p2 |
ifb <p2> |
public p1 |
else |
public "&p1",p2 |
endif |
endm |
xref macro p1,p2 |
ifb <p2> |
extrn `p1` : far |
else |
extrn "&p1",`p2` : far |
endif |
endm |
lcall macro dest |
push cs |
call near ptr dest |
endm |
else |
modstart macro modname,alignment |
ifdef NDEBUG |
name modname |
endif |
if _MODEL and _USE_32_SEGS |
_TEXT segment use32 alignment public 'CODE' |
else |
_TEXT segment alignment public 'CODE' |
endif |
assume cs:_TEXT |
endm |
calli macro regname |
call regname |
endm |
codeptr macro p1,p2 |
if _MODEL and _USE_32_SEGS |
ifb <p2> |
extrn p1 : dword |
else |
extrn "&p1",p2 : dword |
endif |
else |
ifb <p2> |
extrn p1 : word |
else |
extrn "&p1",p2 : word |
endif |
endif |
endm |
defn macro dsym |
dsym proc near |
endm |
defp macro dsym,exp |
dsym proc near exp |
endm |
defpe macro dsym |
ifdef _EXPORT |
dsym proc near export |
else |
dsym proc near |
endif |
endm |
docall macro dest |
call dest |
endm |
dojmp macro dest |
jmp dest |
endm |
endproc macro dsym |
dsym endp |
endm |
epilog macro |
if _MODEL and _USE_32_SEGS |
pop EBP |
else |
pop BP |
endif |
endm |
prolog macro |
if _MODEL and _USE_32_SEGS |
push EBP |
mov EBP,ESP |
else |
push BP |
mov BP,SP |
endif |
endm |
xdefp macro p1,p2 |
ifb <p2> |
public p1 |
else |
public "&p1",p2 |
endif |
endm |
xref macro p1,p2 |
ifb <p2> |
extrn `p1` : near |
else |
extrn "&p1",`p2` : near |
endif |
endm |
lcall macro dest |
call dest |
endm |
endif |
endmod macro |
_TEXT ends |
endm |
dataseg macro |
DGROUP group _DATA |
assume ds:DGROUP,ss:DGROUP |
if _MODEL and _USE_32_SEGS |
_DATA segment use32 dword public 'DATA' |
else |
_DATA segment word public 'DATA' |
endif |
endm |
datasegment macro |
dataseg ; should be phased out |
endm |
enddata macro |
_DATA ends |
endm |
bss_segment macro |
if _MODEL and _USE_32_SEGS |
_BSS segment use32 dword public 'BSS' |
else |
_BSS segment word public 'BSS' |
endif |
DGROUP group _BSS |
assume ds:DGROUP |
endm |
endbss macro |
_BSS ends |
endm |
alias_function macro alias, function |
ifb <function> |
xref "C",_&alias |
else |
xref "C",function |
endif |
.code |
public "C",`alias` |
ifdef _EXPORT |
`alias` proc export |
else |
`alias` proc |
endif |
ifb <function> |
jmp _&alias |
else |
jmp `function` |
endif |
`alias` endp |
endm |
xred macro p1,p2,p3 |
ifb <p3> |
extrn p1 : p2 |
else |
extrn "&p1",p2 : p3 |
endif |
endm |
/programs/develop/open watcom/trunk/clib/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 */ |
/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 <stdarg.h> |
typedef struct my_va_list { |
va_list v; |
} my_va_list; |
#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) |
#define MY_VA_LIST( a ) (*(my_va_list *)&(a)) |
#else |
#define MY_VA_LIST( a ) (*(my_va_list *)(a)) |
#endif |
#define _MYVALIST_H_INCLUDED |
#endif |
/programs/develop/open watcom/trunk/clib/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 |
/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 |
/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 |
/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 <limits.h> |
#include <stdint.h> |
/* Currently size_t is always 'unsigned int', but won't be on LP64 systems */ |
#if SIZE_MAX == UINT_MAX |
#define ZSPEC_IS_INT |
#elif SIZE_MAX == ULONG_MAX |
#define ZSPEC_IS_LONG |
#else |
#error Could not configure zspec |
#endif |
/* Currently intmax_t is always 'long long int' but might be something |
* else, in theory at least |
*/ |
#if INTMAX_MAX == LLONG_MAX |
#define JSPEC_IS_LLONG |
#define JSPEC_CASE_LLONG case 'j': |
#else |
#error Could not configure jspec |
#endif |
/* Currently ptrdiff_t can be either 'long int' or 'int' */ |
#if PTRDIFF_MAX == INT_MAX |
#define TSPEC_IS_INT |
#elif PTRDIFF_MAX == LONG_MAX |
#define TSPEC_IS_LONG |
#else |
#error Could not configure tspec |
#endif |
#ifdef ZSPEC_IS_INT |
#define ZSPEC_CASE_INT case 'z': |
#else |
#define ZSPEC_CASE_INT |
#endif |
#ifdef ZSPEC_IS_LONG |
#define ZSPEC_CASE_LONG case 'z': |
#else |
#define ZSPEC_CASE_LONG |
#endif |
#ifdef TSPEC_IS_INT |
#define TSPEC_CASE_INT case 't': |
#else |
#define TSPEC_CASE_INT |
#endif |
#ifdef TSPEC_IS_LONG |
#define TSPEC_CASE_LONG case 't': |
#else |
#define TSPEC_CASE_LONG |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/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 <stdio.h> |
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 ); |
}; |
/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 |
/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 |
/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 <stdio.h> |
_WCRTLINK void rewind( FILE *fp ) |
{ |
__stream_check( fp, 0 ); |
clearerr( fp ); |
fseek( fp, 0, SEEK_SET ); |
} |
/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 <string.h> |
#include <wchar.h> |
#include "watcom.h" |
/* |
* Choose between 32- and 64-bit words. |
*/ |
#define USE_INT64 0 /* no 64-bit stuff for now */ |
#ifndef USE_INT64 |
#ifdef __AXP__ |
#define USE_INT64 1 |
#else |
#define USE_INT64 0 |
#endif |
#endif |
#if USE_INT64 |
#define INT __int64 |
#define UINT unsigned __int64 |
#else |
#define INT int |
#define UINT uint_32 |
#endif |
#define BYTES_PER_WORD ( sizeof( UINT ) ) |
#define INT_SIZE ( BYTES_PER_WORD * 8 ) |
#define CHARS_PER_WORD ( BYTES_PER_WORD / CHARSIZE ) |
#define MOD_BYTES_PER_WORD(__n) ( (__n) & (BYTES_PER_WORD-1) ) |
/* |
* Macros to mask off a single character. |
*/ |
#if USE_INT64 |
#define BYTE1 ( _riscdata->byteMasks[0].val ) |
#define BYTE2 ( _riscdata->byteMasks[1].val ) |
#define BYTE3 ( _riscdata->byteMasks[2].val ) |
#define BYTE4 ( _riscdata->byteMasks[3].val ) |
#define BYTE5 ( _riscdata->byteMasks[4].val ) |
#define BYTE6 ( _riscdata->byteMasks[5].val ) |
#define BYTE7 ( _riscdata->byteMasks[6].val ) |
#define BYTE8 ( _riscdata->byteMasks[7].val ) |
#else |
#define BYTE1 ( 0x000000FF ) |
#define BYTE2 ( 0x0000FF00 ) |
#define BYTE3 ( 0x00FF0000 ) |
#define BYTE4 ( 0xFF000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1MASK ( BYTE1 | BYTE2 ) |
#define CHR2MASK ( BYTE3 | BYTE4 ) |
#else |
#define CHR1MASK ( BYTE1 ) |
#define CHR2MASK ( BYTE2 ) |
#define CHR3MASK ( BYTE3 ) |
#define CHR4MASK ( BYTE4 ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1(__w) ( (__w) & CHR1MASK ) |
#define CHR2(__w) ( (__w) & CHR2MASK ) |
#else |
#define CHR1(__w) ( (__w) & BYTE1 ) |
#define CHR2(__w) ( (__w) & BYTE2 ) |
#define CHR3(__w) ( (__w) & BYTE3 ) |
#define CHR4(__w) ( (__w) & BYTE4 ) |
#if USE_INT64 |
#define CHR5(__w) ( (__w) & BYTE5 ) |
#define CHR6(__w) ( (__w) & BYTE6 ) |
#define CHR7(__w) ( (__w) & BYTE7 ) |
#define CHR8(__w) ( (__w) & BYTE8 ) |
#endif |
#endif |
/* |
* Macros for extracting the first characters in a word. |
*/ |
#if USE_INT64 |
#define FRONT_BYTES(__n) ( _riscdata->frontCharsMasks[(__n)].val ) |
#define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES_riscdata[(__o)].val ) |
#else |
// extern UINT __FRONT_BYTES[]; |
// #define FRONT_BYTES __FRONT_BYTES |
#define FRONT_BYTES ( _riscdata->frontCharsMasks ) |
#define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES[(__o)] ) |
#endif |
/* |
* Macros for ignoring the first characters in a word. |
*/ |
#if USE_INT64 |
#define SKIP_CHRS_MASKS(__n) ( _riscdata->skipCharsMasks[(__n)].val ) |
#define SKIP_CHRS(__w,__o) ( (__w) & SKIP_CHRS_MASKS(__o) ) |
#else |
// extern UINT __SKIP_CHRS_MASKS[]; |
// #define SKIP_CHRS_MASKS __SKIP_CHRS_MASKS |
#define SKIP_CHRS_MASKS(__n) ( _riscdata->skipCharsMasks[(__n)] ) |
#define SKIP_CHRS(__w,__o) ( (__w) & SKIP_CHRS_MASKS(__o) ) |
#endif |
/* |
* Macros for checking if a word contains a null byte. |
*/ |
#if USE_INT64 |
#define SUB_M ( _riscdata->_01Mask.val ) |
#define NIL_M ( _riscdata->_80Mask.val ) |
#define SUB_MASK(__n) ( _riscdata->subMasks[(__n)].val ) |
#else |
#ifdef __WIDECHAR__ |
#define SUB_M ( 0x00010001 ) |
#define NIL_M ( 0x80008000 ) |
#else |
#define SUB_M ( 0x01010101 ) |
#define NIL_M ( 0x80808080 ) |
#endif |
// extern UINT __SubMask[]; |
// #define SUB_MASK __SubMask |
#define SUB_MASK(__n) ( _riscdata->subMasks[(__n)] ) |
#endif |
#define GOT_NIL(__w) ( ( (~(__w)) & ((__w) - SUB_M) ) & NIL_M ) |
#ifdef __WIDECHAR__ |
#define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK((__o)/CHARSIZE)) ) & NIL_M ) |
#else |
#define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK(__o)) ) & NIL_M ) |
#endif |
/* |
* Some handy pointer manipulation macros. |
*/ |
#define ROUND(__p) ( (UINT*) ( (UINT)(__p) & (-sizeof(UINT)) ) ) |
#define OFFSET(__p) ( ((unsigned int)(__p)) & (sizeof(UINT)-1) ) |
/* |
* Macros for uppercase and lowercase stuff. |
*/ |
#ifdef __WIDECHAR__ |
#define CHR1_A ( 0x00000041 ) |
#define CHR2_A ( 0x00410000 ) |
#define CHR1_Z ( 0x0000005A ) |
#define CHR2_Z ( 0x005A0000 ) |
#define CHR1_A2a(s) ( s | 0x00000020 ) |
#define CHR2_A2a(s) ( s | 0x00200000 ) |
#else |
#define CHR1_A ( 0x00000041 ) |
#define CHR2_A ( 0x00004100 ) |
#define CHR3_A ( 0x00410000 ) |
#define CHR4_A ( 0x41000000 ) |
#define CHR1_Z ( 0x0000005A ) |
#define CHR2_Z ( 0x00005A00 ) |
#define CHR3_Z ( 0x005A0000 ) |
#define CHR4_Z ( 0x5A000000 ) |
#define CHR1_A2a(s) ( s | 0x00000020 ) |
#define CHR2_A2a(s) ( s | 0x00002000 ) |
#define CHR3_A2a(s) ( s | 0x00200000 ) |
#define CHR4_A2a(s) ( s | 0x20000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s ) |
#define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s ) |
#else |
#define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s ) |
#define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s ) |
#define TO_LOW_CHR3(s) ( ( (s>=CHR3_A) && (s<=CHR3_Z) ) ? CHR3_A2a(s) : s ) |
#define TO_LOW_CHR4(s) ( ( (s>=CHR4_A) && (s<=CHR4_Z) ) ? CHR4_A2a(s) : s ) |
#endif |
#ifdef __WIDECHAR__ |
#define CHR1_a ( 0x00000061 ) |
#define CHR2_a ( 0x00610000 ) |
#define CHR1_z ( 0x0000007A ) |
#define CHR2_z ( 0x007A0000 ) |
#define CHR1_a2A(s) ( s & 0x000000DF ) |
#define CHR2_a2A(s) ( s & 0x00DF0000 ) |
#else |
#define CHR1_a ( 0x00000061 ) |
#define CHR2_a ( 0x00006100 ) |
#define CHR3_a ( 0x00610000 ) |
#define CHR4_a ( 0x61000000 ) |
#define CHR1_z ( 0x0000007A ) |
#define CHR2_z ( 0x00007A00 ) |
#define CHR3_z ( 0x007A0000 ) |
#define CHR4_z ( 0x7A000000 ) |
#define CHR1_a2A(s) ( s & 0x000000DF ) |
#define CHR2_a2A(s) ( s & 0x0000DF00 ) |
#define CHR3_a2A(s) ( s & 0x00DF0000 ) |
#define CHR4_a2A(s) ( s & 0xDF000000 ) |
#endif |
#ifdef __WIDECHAR__ |
#define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s ) |
#define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s ) |
#else |
#define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s ) |
#define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s ) |
#define TO_UPR_CHR3(s) ( ( (s>=CHR3_a) && (s<=CHR3_z) ) ? CHR3_a2A(s) : s ) |
#define TO_UPR_CHR4(s) ( ( (s>=CHR4_a) && (s<=CHR4_z) ) ? CHR4_a2A(s) : s ) |
#endif |
/* |
* Tweak characters within a word. |
*/ |
#ifdef __WIDECHAR__ |
#define REVERSE_CHARS(__w) ( (CHR1(__w)<<16) | (CHR2(__w)>>16) ) |
#else |
#define REVERSE_CHARS(__w) ( (CHR1(__w)<<24) | (CHR2(__w)<<8) | \ |
(CHR3(__w)>>8) | (CHR4(__w)>>24) ) |
#endif |
#define SWAP_BYTES(__w) ( (((__w)&BYTE1)<<8) | (((__w)&BYTE2)>>8) | \ |
(((__w)&BYTE3)<<8) | (((__w)&BYTE4)>>8) ) |
/* |
* Data used by the RISC string functions. |
*/ |
struct __F_NAME(__RISC_StrData,__wRISC_StrData) { |
#if USE_INT64 |
unsigned_64 byteMasks[8]; |
unsigned_64 frontCharsMasks[8]; |
unsigned_64 skipCharsMasks[8]; |
unsigned_64 _01Mask; |
unsigned_64 _80Mask; |
unsigned_64 subMasks[8]; |
#else |
#ifdef __WIDECHAR__ |
uint_32 frontCharsMasks[2]; |
uint_32 skipCharsMasks[2]; |
uint_32 subMasks[2]; |
#else |
uint_32 frontCharsMasks[4]; |
uint_32 skipCharsMasks[4]; |
uint_32 subMasks[4]; |
#endif |
#endif |
}; |
#ifdef __WIDECHAR__ |
extern struct __wRISC_StrData __wRISC_StringData; |
#define RISC_DATA_LOCALREF struct __wRISC_StrData *_riscdata = &__wRISC_StringData |
#else |
extern struct __RISC_StrData __RISC_StringData; |
#define RISC_DATA_LOCALREF struct __RISC_StrData *_riscdata = &__RISC_StringData |
#endif |
/* |
* Prototype functions called by the RISC-oriented string functions. |
*/ |
_WCRTLINK extern wchar_t * __simple_wcschr( const wchar_t *str, wint_t ch ); |
_WCRTLINK extern int __simple_wcscmp( const wchar_t *s1, const wchar_t *s2 ); |
_WCRTLINK extern wchar_t * __simple_wcscpy( wchar_t *dest, const wchar_t *src ); |
_WCRTLINK extern int __simple__wcsicmp( const wchar_t *s1, const wchar_t *s2 ); |
_WCRTLINK extern size_t __simple_wcslen( const wchar_t *str ); |
_WCRTLINK extern wchar_t * __simple__wcslwr( wchar_t *str ); |
_WCRTLINK extern int __simple_wcsncmp( const wchar_t *s1, const wchar_t *s2, size_t n ); |
_WCRTLINK extern wchar_t * __simple_wcsncpy( wchar_t *dest, const wchar_t *src, size_t n ); |
_WCRTLINK extern int __simple__wcsnicmp( const wchar_t *s1, const wchar_t *s2, size_t n ); |
_WCRTLINK extern wchar_t * __simple__wcsnset( wchar_t *str, int ch, size_t n ); |
_WCRTLINK extern wchar_t * __simple_wcsrchr( const wchar_t *str, wint_t ch ); |
_WCRTLINK extern wchar_t * __simple__wcsset( wchar_t *str, wchar_t ch ); |
_WCRTLINK extern wchar_t * __simple__wcsupr( wchar_t *str ); |
#endif /* #ifdef __RISCSTR__ */ |
#endif |
/programs/develop/open watcom/trunk/clib/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 <errno.h> |
#include "seterrno.h" |
/*********** |
#if ( defined(__NT__) || defined(__RUNTIME_HANDLE_CHECKS__) ) \ |
&& ( !defined(__NETWARE__) && !defined(__UNIX__) \ |
&& !defined(__OSI__) ) |
extern unsigned __NFiles; |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
__set_errno( EBADF ); \ |
return( __r ); \ |
} |
#else |
#define __handle_check( __h, __r ) |
#endif |
**************/ |
#define __handle_check( __h, __r ) |
#endif |
/programs/develop/open watcom/trunk/clib/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 <stdio.h> |
#include "errorno.h" |
/* DOS based platforms have stdaux/stdprn in addition to stdin/out/err */ |
#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OSI__) |
#define NUM_STD_STREAMS 5 |
#else |
#define NUM_STD_STREAMS 3 |
#endif |
#if defined(__NT__) || defined(__OS2__) |
struct __pipe_info { |
int isPipe; /* non-zero if it's a pipe */ |
int pid; /* PID of spawned process */ |
}; |
#endif |
typedef struct __stream_link { |
struct __stream_link * next; |
struct __iobuf * stream; |
unsigned char * _base; /* location of buffer */ |
int _orientation; /* wide/byte/not oriented */ |
int _extflags; /* extended flags */ |
unsigned char _tmpfchar; /* tmpfile number */ |
unsigned char _filler[sizeof(int)-1];/* explicit padding */ |
#if defined(__NT__) || defined(__OS2__) |
struct __pipe_info pipeInfo; /* pipe-related fields */ |
#endif |
} __stream_link; |
typedef void _WCI86FAR FPEhandler( int ); |
#define _FP_BASE(__fp) ((__fp)->_link->_base) |
#ifndef __NETWARE__ |
#define _FP_ORIENTATION(__fp) ((__fp)->_link->_orientation) |
#define _FP_EXTFLAGS(__fp) ((__fp)->_link->_extflags) |
#endif |
#define _FP_TMPFCHAR(__fp) ((__fp)->_link->_tmpfchar) |
#ifndef __NETWARE__ |
#define _FP_PIPEDATA(__fp) ((__fp)->_link->pipeInfo) |
#endif |
extern __stream_link *__OpenStreams; |
extern __stream_link *__ClosedStreams; |
extern char * _WCNEAR __env_mask; /* ptr to char array of flags */ |
extern FPEhandler *__FPE_handler; |
extern void (*__FPE_handler_exit)( void ); |
#if !defined(__NETWARE__) |
extern int _cbyte; |
extern int _cbyte2; |
extern int _child; |
extern int __umaskval; |
extern unsigned _curbrk; |
extern int _commode; |
#endif |
#if !defined (_NETWARE_LIBC) |
extern unsigned _STACKTOP; |
#endif |
#if !defined(__QNX__) && !defined(__LINUX__) |
extern void (*__Save8087)();/* Ptr to FP state save rtn (spawn) */ |
extern void (*__Rest8087)();/* Ptr to FP state restore rtn (spawn) */ |
#endif |
extern unsigned short _8087cw; /* control word initializer */ |
extern unsigned char _no87; /* NO87 environment var defined */ |
extern unsigned char _8087; /* type of 8087/emulator present */ |
extern unsigned char _real87; /* 8087 coprocessor hardware present */ |
#if defined(_M_IX86) |
#pragma aux _8087cw "_*"; |
#pragma aux _no87 "_*"; |
#pragma aux _8087 "_*"; |
#pragma aux _real87 "_*"; |
#endif |
#if !defined(__SW_BM) |
extern unsigned _STACKLOW; |
#endif |
#define _RWD_ostream __OpenStreams |
#define _RWD_cstream __ClosedStreams |
#define _RWD_iob __iob |
#if !defined(__NETWARE__) |
#define _RWD_threadid _threadid |
#endif |
#define _RWD_environ environ |
#define _RWD_wenviron _wenviron |
#define _RWD_env_mask __env_mask |
#define _RWD_abort __abort |
#define _RWD_sigtab __SIGNALTABLE |
#define _RWD_FPE_handler_exit __FPE_handler_exit |
#define _RWD_FPE_handler __FPE_handler |
#define _RWD_fmode _fmode |
#if !defined(__NETWARE__) |
#define _RWD_umaskval __umaskval |
#define _RWD_cbyte _cbyte |
#define _RWD_cbyte2 _cbyte2 |
#define _RWD_child _child |
#define _RWD_amblksiz _amblksiz |
#define _RWD_curbrk _curbrk |
#define _RWD_dynend _dynend |
#define _RWD_psp _psp |
#endif |
#if !defined (_NETWARE_LIBC) |
#define _RWD_stacktop _STACKTOP |
#endif |
#if !defined(__QNX__) && !defined(__LINUX__) |
#define _RWD_Save8087 __Save8087 |
#define _RWD_Rest8087 __Rest8087 |
#endif |
#define _RWD_8087cw _8087cw |
#define _RWD_no87 _no87 |
#define _RWD_8087 _8087 |
#define _RWD_real87 _real87 |
#if !defined(__NETWARE__) |
#define _RWD_HShift _HShift |
#define _RWD_osmajor _osmajor |
#define _RWD_osminor _osminor |
#define _RWD_osmode _osmode |
#if defined(__NT__) |
#define _RWD_osbuild _osbuild |
#define _RWD_osver _osver |
#define _RWD_winmajor _winmajor |
#define _RWD_winminor _winminor |
#define _RWD_winver _winver |
#endif |
#define _RWD_doserrno _DOSERRNO |
#endif |
#define _RWD_tmpfnext __tmpfnext |
#if !defined(_RWD_errno) |
#define _RWD_errno _ERRNO |
#endif |
#define _RWD_nexttok _NEXTTOK |
#define _RWD_nextftok _NEXTFTOK |
#define _RWD_nextmbtok _NEXTMBTOK |
#define _RWD_nextmbftok _NEXTMBFTOK |
#define _RWD_nextwtok _NEXTWTOK |
#define _RWD_tzname tzname |
#define _RWD_timezone timezone |
#define _RWD_daylight daylight |
#define _RWD_dst_adjust __dst_adjust |
#define _RWD_start_dst __start_dst |
#define _RWD_end_dst __end_dst |
#define _RWD_asctime _RESULT |
#ifdef __SW_BM |
#define _RWD_cvtbuf __THREADDATAPTR->__cvt_buffer |
#else |
#define _RWD_cvtbuf cvt_buffer |
#endif |
#if defined(__NETWARE__) |
#define _RWD_ioexit __ioexit |
#define _RWD_tmpnambuf (__THREADDATAPTR->__tmpnambuf) |
#define _RWD_randnextinit (__THREADDATAPTR->__randnextinit) |
#else |
#define _RWD_tmpnambuf _tmpname |
#define _RWD_randnextinit THREAD_PTR.__randnextinit |
#endif |
#define _RWD_stacklow _STACKLOW |
#define _RWD_randnext _RANDNEXT |
#define _RWD_ThreadData _ThreadData |
#define _RWD_StaticInitSema _StaticInitSema |
#define _RWD_PureErrorFlag _PureErrorFlag |
#define _RWD_UndefVfunFlag _UndefVfunFlag |
#define _RWD_ModuleInit _ModuleInit |
/* |
For the sake of efficiency, tell the compiler |
that the __exit... routines never return. |
*/ |
_WCRTLINK extern void __exit( unsigned ); |
#if defined(_M_IX86) |
#pragma aux __exit aborts; |
#endif |
extern void (*__abort)( void ); // Defined in abort.c |
extern void __terminate( void ); // Defined in abort.c |
#endif // _RTDATA_H_INCLUDED |
/programs/develop/open watcom/trunk/clib/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 |
/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 <stdarg.h> |
typedef struct { |
int (*cget_rtn)(); /* character get rtn */ |
void (*uncget_rtn)(); /* unget a character rtn */ |
CHAR_TYPE *ptr; /* file or string pointer */ |
int width; /* conversion field width */ |
unsigned assign : 1; /* assignment flag for current argument */ |
unsigned eoinp : 1; /* end of input reached */ |
unsigned far_ptr : 1; /* F - far pointer */ |
unsigned near_ptr : 1; /* N - near pointer */ |
unsigned char_var : 1; /* hh - char variable */ |
unsigned short_var : 1; /* h - short variable */ |
unsigned long_var : 1; /* l - long variable */ |
unsigned long_long_var : 1; /* ll - long long variable */ |
unsigned long_double_var: 1; /* L - long double variable */ |
unsigned p_format : 1; /* %p (pointer conversion) */ |
} SCNF_SPECS; |
#if defined(__HUGE__) |
#define PTR_SCNF_SPECS SCNF_SPECS _WCFAR * |
#else |
#define PTR_SCNF_SPECS SCNF_SPECS * |
#endif |
#if defined( __STDC_WANT_LIB_EXT1__ ) && __STDC_WANT_LIB_EXT1__ == 1 |
#if defined(__WIDECHAR__) |
extern int __wscnf_s( PTR_SCNF_SPECS, const CHAR_TYPE *, const char **msg, va_list ); |
#else |
extern int __scnf_s( PTR_SCNF_SPECS, const CHAR_TYPE *, const char **msg, va_list ); |
#endif |
#else |
#if defined(__WIDECHAR__) |
extern int __wscnf( PTR_SCNF_SPECS, const CHAR_TYPE *, va_list ); |
#else |
extern int __scnf( PTR_SCNF_SPECS, const CHAR_TYPE *, va_list ); |
#endif |
#endif |
//#pragma off(unreferenced); |
#endif |
/programs/develop/open watcom/trunk/clib/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 |
/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 ); |
/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> |
name = __label |
endif |
endm |
_quif macro cc,name |
ifnb <name> |
_set __elbl,,name,<> |
_j cc,_l,%__elbl |
else |
_set __albl,,__astk,%__depth |
_j cc,_l,%__albl |
endif |
endm |
_quit macro name |
_quif ,name |
endm |
_admit macro |
_set __albl,,__astk,%__depth |
__label = __label + 1 |
_set __astk,%__depth,__label,<> |
_set __elbl,,__estk,%__depth |
_j ,_l,%__elbl |
_label _l,%__albl |
endm |
_endguess macro |
_set __albl,,__astk,%__depth |
_label _l,%__albl |
_set __elbl,,__estk,%__depth |
_label _l,%__elbl |
__depth = __depth - 1 |
endm |
_loop macro name |
_guess name |
_set __albl,,__astk,%__depth |
_label _m,%__albl |
_set __elbl,,__estk,%__depth |
_label _m,%__elbl |
_set __llbl,%__depth,%__inner_loop,<> |
_set __inner_loop,,%__depth,<> |
endm |
_loopif macro cc,name |
ifnb <name> |
_set __elbl,,name,<> |
_j cc,_m,%__elbl |
else |
_set __albl,,__astk,%__inner_loop |
_j cc,_m,%__albl |
endif |
endm |
_until macro cc |
_set __albl,,__astk,%__depth |
_jn cc,_m,%__albl |
_set __inner_loop,,__llbl,%__depth |
_endguess |
endm |
_endloop macro |
_set __albl,,__astk,%__depth |
_j ,_m,%__albl |
_set __inner_loop,,__llbl,%__depth |
_endguess |
endm |
_if macro cc |
_guess |
_set __albl,,__astk,%__depth |
_jn cc,_l,%__albl |
endm |
_else macro |
_admit |
endm |
_endif macro |
_endguess |
endm |
_set macro base1,ext1,base2,ext2 |
base1&ext1 = base2&ext2 |
endm |
_label macro base,ext |
base&ext: |
endm |
_j macro cc,base,ext |
j&cc base&ext |
endm |
_jn macro cc,base,ext |
jn&cc base&ext |
endm |
jnna macro label |
ja label |
endm |
jnnae macro label |
jae label |
endm |
jnnb macro label |
jb label |
endm |
jnnbe macro label |
jbe label |
endm |
jnnc macro label |
jc label |
endm |
jnne macro label |
je label |
endm |
jnng macro label |
jg label |
endm |
jnnge macro label |
jge label |
endm |
jnnl macro label |
jl label |
endm |
jnnle macro label |
jle label |
endm |
jnno macro label |
jo label |
endm |
jnnp macro label |
jp label |
endm |
jnns macro label |
js label |
endm |
jnnz macro label |
jz label |
endm |
jnpe macro label |
jpo label |
endm |
jnpo macro label |
jpe label |
endm |
j macro label |
jmp label |
endm |
jn macro label |
nop |
endm |
_shl macro reg,count |
add reg,reg |
endm |
_rcl macro reg,count |
adc reg,reg |
endm |
/programs/develop/open watcom/trunk/clib/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 <sys/types.h> |
#include <unistd.h> |
#include "lseek.h" |
_WCRTLINK long int tell( int handle ) |
{ |
return( __lseek( handle, 0L, SEEK_CUR ) ); |
} |
/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 |
/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 |
/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 <errno.h> |
#ifndef __WATCOMC__ |
#include "clibext.h" |
#endif |
#if !defined(__sun__) && !defined(sun) && !defined(__sgi) && !defined(__hppa) && !defined(_AIX) && !defined(__alpha) && !defined(_TYPES_H_) && !defined(_SYS_TYPES_H) |
typedef unsigned uint; |
#endif |
typedef unsigned char uint_8; |
typedef unsigned short uint_16; |
#if defined (LONG_IS_64BITS) |
typedef unsigned int uint_32; |
#else |
typedef unsigned long uint_32; |
#endif |
typedef unsigned char unsigned_8; |
typedef unsigned short unsigned_16; |
#if defined (LONG_IS_64BITS) |
typedef unsigned int unsigned_32; |
#else |
typedef unsigned long unsigned_32; |
#endif |
typedef signed char int_8; |
typedef signed short int_16; |
#if defined (LONG_IS_64BITS) |
typedef signed int int_32; |
#else |
typedef signed long int_32; |
#endif |
typedef signed char signed_8; |
typedef signed short signed_16; |
#if defined (LONG_IS_64BITS) |
typedef signed int signed_32; |
#else |
typedef signed long signed_32; |
#endif |
typedef struct { |
union { |
unsigned_32 _32[2]; |
unsigned_16 _16[4]; |
unsigned_8 _8[8]; |
struct { |
#if defined( __BIG_ENDIAN__ ) |
unsigned v : 1; |
unsigned : 15; |
unsigned : 16; |
unsigned : 16; |
unsigned : 16; |
#else |
unsigned : 16; |
unsigned : 16; |
unsigned : 16; |
unsigned : 15; |
unsigned v : 1; |
#endif |
} sign; |
#if defined(__WATCOM_INT64__) || defined(__GNUC__) |
unsigned long long _64[1]; |
#endif |
} u; |
} unsigned_64; |
typedef unsigned_64 signed_64; |
/* Macros for low/high end access on little and big endian machines */ |
#if defined( __BIG_ENDIAN__ ) |
#define I64LO32 1 |
#define I64HI32 0 |
#define I64LO16 3 |
#define I64HI16 0 |
#define I64LO8 7 |
#define I64HI8 0 |
#else |
#define I64LO32 0 |
#define I64HI32 1 |
#define I64LO16 0 |
#define I64HI16 3 |
#define I64LO8 0 |
#define I64HI8 7 |
#endif |
/* Define _crtn for prototypes for external C routines called from C++. |
* Eg. extern _crtn void Foo(); |
*/ |
#if !defined( _crtn ) |
#if defined( __cplusplus ) |
#define _crtn "C" |
#else |
#define _crtn |
#endif |
#endif |
/* Macros for little/big endian conversion; These exist to simplify writing |
* code that handles both little and big endian data on either little or big |
* endian host platforms. Some of these macros could be implemented as inline |
* assembler where instructions to byte swap data in registers or read/write |
* memory access with byte swapping is available. |
* |
* NOTE: The SWAP_XX macros will swap data in place. If you only want to take a |
* a copy of the data and leave the original intact, then use the SWAPNC_XX |
* macros. |
*/ |
#define SWAPNC_16(w) (\ |
(((w) & 0x000000FFUL) << 8) |\ |
(((w) & 0x0000FF00UL) >> 8)\ |
) |
#define SWAPNC_32(w) (\ |
(((w) & 0x000000FFUL) << 24) |\ |
(((w) & 0x0000FF00UL) << 8) |\ |
(((w) & 0x00FF0000UL) >> 8) |\ |
(((w) & 0xFF000000UL) >> 24)\ |
) |
#define SWAPNC_64(w) (\ |
(((w) & 0x00000000000000FFULL) << 56) |\ |
(((w) & 0x000000000000FF00ULL) << 40) |\ |
(((w) & 0x0000000000FF0000ULL) << 24) |\ |
(((w) & 0x00000000FF000000ULL) << 8) |\ |
(((w) & 0x000000FF00000000ULL) >> 8) |\ |
(((w) & 0x0000FF0000000000ULL) >> 24) |\ |
(((w) & 0x00FF000000000000ULL) >> 40) |\ |
(((w) & 0xFF00000000000000ULL) >> 56)\ |
) |
#if defined( __BIG_ENDIAN__ ) |
/* Macros to get little endian data */ |
#define GET_LE_16(w) SWAPNC_16(w) |
#define GET_LE_32(w) SWAPNC_32(w) |
#define GET_LE_64(w) SWAPNC_64(w) |
/* Macros to get big endian data */ |
#define GET_BE_16(w) (w) |
#define GET_BE_32(w) (w) |
#define GET_BE_64(w) (w) |
/* Macros to convert little endian data in place */ |
#define CONV_LE_16(w) (w) = SWAPNC_16(w) |
#define CONV_LE_32(w) (w) = SWAPNC_32(w) |
#define CONV_LE_64(w) (w) = SWAPNC_64(w) |
/* Macros to convert big endian data in place */ |
#define CONV_BE_16(w) |
#define CONV_BE_32(w) |
#define CONV_BE_64(w) |
/* Macros to swap byte order */ |
#define SWAP_16 CONV_LE_16 |
#define SWAP_32 CONV_LE_32 |
#define SWAP_64 CONV_LE_64 |
#else |
/* Macros to get little endian data */ |
#define GET_LE_16(w) (w) |
#define GET_LE_32(w) (w) |
#define GET_LE_64(w) (w) |
/* Macros to get big endian data */ |
#define GET_BE_16(w) SWAPNC_16(w) |
#define GET_BE_32(w) SWAPNC_32(w) |
#define GET_BE_64(w) SWAPNC_64(w) |
/* Macros to convert little endian data in place */ |
#define CONV_LE_16(w) |
#define CONV_LE_32(w) |
#define CONV_LE_64(w) |
/* Macros to convert big endian data in place */ |
#define CONV_BE_16(w) (w) = SWAPNC_16(w) |
#define CONV_BE_32(w) (w) = SWAPNC_32(w) |
#define CONV_BE_64(w) (w) = SWAPNC_64(w) |
/* Macros to swap byte order */ |
#define SWAP_16 CONV_BE_16 |
#define SWAP_32 CONV_BE_32 |
#define SWAP_64 CONV_BE_64 |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/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 <stdlib.h> /* for wchar_t and _atouni */ |
/*** Define some handy macros ***/ |
#ifdef __WIDECHAR__ |
#define DIR_TYPE struct _wdirent |
#define CHAR_TYPE wchar_t |
#define UCHAR_TYPE wchar_t |
#define INTCHAR_TYPE wint_t |
#define INT_WC_TYPE wchar_t |
#define VOID_WC_TYPE wchar_t |
#define NULLCHAR 0 |
#define STRING(a) L##a |
#define _AToUni(p1,p2) _atouni(p1,p2) |
#define IS_ASCII(c) ( (c & 0xff00) == 0 ) |
#define TO_ASCII(c) ( c ) |
#define __F_NAME(n1,n2) n2 |
#define UNICODE |
#define _UNICODE |
#define __UNICODE__ |
#else |
#define DIR_TYPE struct dirent |
#define CHAR_TYPE char |
#define UCHAR_TYPE unsigned char |
#define INTCHAR_TYPE int |
#define INT_WC_TYPE int |
#define VOID_WC_TYPE void |
#define NULLCHAR '\0' |
#define STRING(a) a |
#define _AToUni(p1,p2) (p2) |
#define IS_ASCII(c) ( 1 ) |
#define TO_ASCII(c) ( (unsigned char)c ) |
#define __F_NAME(n1,n2) n1 |
#endif |
#define CHARSIZE (sizeof( CHAR_TYPE )) |
/* must be the larger of char and wchar_t */ |
#define MAX_CHAR_TYPE wchar_t |
#endif |
/programs/develop/open watcom/trunk/clib/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 <string.h> |
#ifdef __cplusplus |
extern "C" { |
#endif |
#ifdef __INLINE_FUNCTIONS__ |
void *_inline_memchr( const void *__s, int __c, size_t __n ); |
int _inline_memcmp( const void *__s1, const void *__s2, size_t __n ); |
void *_inline_memcpy( void *__s1, const void *__s2, size_t __n ); |
void *_inline_memmove( void *__s1, const void *__s2, size_t __n ); |
void *_inline_memset( void *__s, int __c, size_t __n ); |
char *_inline_strcat( char *__s1, const char *__s2 ); |
char *_inline_strchr( const char *__s, int __c ); |
int _inline_strcmp( const char *__s1, const char *__s2 ); |
char *_inline_strcpy( char *__s1, const char *__s2 ); |
size_t _inline_strlen( const char *__s ); |
void _WCFAR *_inline__fmemchr( const void _WCFAR *__s, int __c, size_t __n ); |
void _WCFAR *_inline__fmemcpy( void _WCFAR *__s1, const void _WCFAR *__s2, size_t __n ); |
void _WCFAR *_inline__fmemset( void _WCFAR *__s, int __c, size_t __n ); |
int _inline__fmemcmp( const void _WCFAR *__s1, const void _WCFAR *__s2, size_t __n ); |
char _WCFAR *_inline__fstrcat( char _WCFAR *__s1, const char _WCFAR *__s2 ); |
char _WCFAR *_inline__fstrchr( const char _WCFAR *__s, int __c ); |
int _inline__fstrcmp( const char _WCFAR *__s1, const char _WCFAR *__s2 ); |
char _WCFAR *_inline__fstrcpy( char _WCFAR *__s1, const char _WCFAR *__s2 ); |
size_t _inline__fstrlen( const char _WCFAR *__s ); |
void _inline_movedata( unsigned __srcseg, unsigned __srcoff, |
unsigned __tgtseg, unsigned __tgtoff, unsigned __len ); |
#endif /* __INLINE_FUNCTIONS__ */ |
#define _XSTRING_H_INCLUDED |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/src/_clsewnt.c |
---|
0,0 → 1,64 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <errno.h> |
#include "fileacc.h" |
//#include <windows.h> |
#include "rtcheck.h" |
#include "rtdata.h" |
#include "iomode.h" |
#include "seterrno.h" |
//#include "defwin.h" |
#include "close.h" |
int __close( int hid ) |
{ |
int is_closed; |
int rc; |
HANDLE h; |
__handle_check( hid, -1 ); |
is_closed = 0; |
rc = 0; |
// h = __getOSHandle( hid ); |
// if( !is_closed && !CloseHandle( h ) ) |
// { |
// rc = __set_errno_nt(); |
// } |
// __freePOSIXHandle( hid ); |
// __SetIOMode_nogrow( hid, 0 ); |
return( rc ); |
} |
/programs/develop/open watcom/trunk/clib/src/chktty.c |
---|
0,0 → 1,52 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of chktty() - check if stream is teletype. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <malloc.h> |
#include <unistd.h> |
#include "rtdata.h" |
#include "fileacc.h" |
#include "streamio.h" |
void __chktty( FILE *fp ) |
{ |
/* if we have not determined that we've got a tty then check for one */ |
if( !(fp->_flag & _ISTTY) ) { |
if( isatty( fileno( fp ) ) ) { |
fp->_flag |= _ISTTY; |
if( ( fp->_flag & (_IONBF | _IOLBF | _IOFBF) ) == 0 ) { |
fp->_flag |= _IOLBF; |
} |
} |
} |
} |
/programs/develop/open watcom/trunk/clib/src/fflush.c |
---|
0,0 → 1,48 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of fflush() - flush streams. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <errno.h> |
#include <fcntl.h> |
#include "rtdata.h" |
#include "fileacc.h" |
#include "flush.h" |
_WCRTLINK int fflush( FILE *fp ) |
{ |
if( fp == NULL ) { |
flushall(); |
return( 0 ); |
} |
_ValidFile( fp, EOF ); |
return( __flush( fp ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/flush.c |
---|
0,0 → 1,113 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of fflush() helper routine. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include <fcntl.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "qwrite.h" |
#include "lseek.h" |
#include "flush.h" |
#if defined( __NETWARE__ ) && defined( _THIN_LIB ) |
/* Take flush from LibC */ |
_WCRTLINK int __flush( FILE *fp ) |
{ |
return( fflush( fp ) ); |
} |
#else |
_WCRTLINK int __flush( FILE *fp ) |
{ |
int len; |
long offset; |
int ret; |
char *ptr; |
unsigned amount; |
ret = 0; |
_AccessFile( fp ); |
if( fp->_flag & _DIRTY ) { |
fp->_flag &= ~_DIRTY; |
if( (fp->_flag & _WRITE) && (_FP_BASE(fp) != NULL) ) { |
ptr = _FP_BASE(fp); |
amount = fp->_cnt; |
while( amount != 0 && ret == 0 ) { |
len = __qwrite( fileno( fp ), ptr, amount ); /* 02-aug-90 */ |
if( len == -1 ) { |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
#ifndef __UNIX__ |
else if( len == 0 ) { |
__set_errno( ENOSPC ); /* 12-nov-88 */ |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
#endif |
ptr += len; |
amount -= len; |
} |
} |
} else if( _FP_BASE(fp) != NULL ) { /* not dirty */ |
/* fseek( fp, ftell(fp), SEEK_SET ); */ |
fp->_flag &= ~_EOF; |
if( !(fp->_flag & _ISTTY) ) { |
offset = fp->_cnt; |
if( offset != 0 ) { /* 10-aug-89 JD */ |
offset = __lseek( fileno( fp ), -offset, SEEK_CUR ); |
} |
if( offset == -1 ) { |
fp->_flag |= _SFERR; |
ret = EOF; |
} |
} |
} |
fp->_ptr = _FP_BASE(fp); /* reset ptr to start of buffer */ |
fp->_cnt = 0; |
#if !defined( __NETWARE__ ) && !defined( __OSI__ ) |
if( ret == 0 && (_FP_EXTFLAGS(fp) & _COMMIT) ) { |
if( fsync( fileno( fp ) ) == -1 ) { |
ret = EOF; |
} |
} |
#endif |
_ReleaseFile( fp ); |
return( ret ); |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/fputc.c |
---|
0,0 → 1,145 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Platform independent fputc() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include <errno.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "seterrno.h" |
#include "orient.h" |
#ifdef __WIDECHAR__ |
#include <mbstring.h> |
#include <wchar.h> |
#endif |
#include "flush.h" |
#include "streamio.h" |
#ifndef __WIDECHAR__ |
_WCRTLINK int fputc( int c, FILE *fp ) |
{ |
int flags; |
_ValidFile( fp, EOF ); |
_AccessFile( fp ); |
/*** Deal with stream orientation ***/ |
ORIENT_STREAM(fp,EOF); |
if( !(fp->_flag & _WRITE) ) { |
__set_errno( EBADF ); |
fp->_flag |= _SFERR; |
_ReleaseFile( fp ); |
return( EOF ); |
} |
if( _FP_BASE(fp) == NULL ) { |
__ioalloc( fp ); |
} |
flags = _IONBF; |
if( c == '\n' ) { |
flags = _IONBF | _IOLBF; |
#ifndef __UNIX__ |
if( !(fp->_flag & _BINARY) ) { |
fp->_flag |= _DIRTY; |
*(char*)fp->_ptr = '\r'; /* '\n' -> '\r''\n' */ |
fp->_ptr++; |
fp->_cnt++; |
if( fp->_cnt == fp->_bufsize ) { |
if( __flush( fp ) ) { |
_ReleaseFile( fp ); |
return( EOF ); |
} |
} |
} |
#endif |
} |
fp->_flag |= _DIRTY; |
*(char *)fp->_ptr = c; |
fp->_ptr++; |
fp->_cnt++; |
if( (fp->_flag & flags) || (fp->_cnt == fp->_bufsize) ) { |
if( __flush( fp ) ) { |
_ReleaseFile( fp ); |
return( EOF ); |
} |
} |
_ReleaseFile( fp ); |
return( (UCHAR_TYPE)c ); |
} |
#else |
static int __write_wide_char( FILE *fp, wchar_t wc ) |
/**************************************************/ |
{ |
if( fp->_flag & _BINARY ) { |
/*** Dump the wide character ***/ |
return( fwrite( &wc, sizeof( wchar_t ), 1, fp ) ); |
} else { |
char mbc[MB_CUR_MAX]; |
int rc; |
/*** Convert the wide character to multibyte form and write it ***/ |
rc = wctomb( mbc, wc ); |
if( rc > 0 ) { |
return( fwrite( mbc, rc, 1, fp ) ); |
} else { |
__set_errno( EILSEQ ); |
return( 0 ); |
} |
} |
} |
_WCRTLINK wint_t fputwc( wint_t c, FILE *fp ) |
{ |
_ValidFile( fp, WEOF ); |
_AccessFile( fp ); |
/*** Deal with stream orientation ***/ |
ORIENT_STREAM(fp,WEOF); |
/*** Write the character ***/ |
if( !__write_wide_char( fp, c ) ) { |
_ReleaseFile( fp ); |
return( WEOF ); |
} else { |
_ReleaseFile( fp ); |
return( c ); |
} |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/fputs.c |
---|
0,0 → 1,91 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of fputs() - put string to stream. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include "fileacc.h" |
#include "rtdata.h" |
#include "flush.h" |
#include "streamio.h" |
_WCRTLINK int __F_NAME(fputs,fputws)( const CHAR_TYPE *s, FILE *fp ) |
{ |
const CHAR_TYPE *start; |
int c; |
int not_buffered; |
int rc; |
_ValidFile( fp, __F_NAME(EOF,WEOF) ); |
_AccessFile( fp ); |
if( _FP_BASE(fp) == NULL ) { |
__ioalloc( fp ); /* allocate buffer */ |
} |
not_buffered = 0; |
if( fp->_flag & _IONBF ) { |
not_buffered = 1; |
fp->_flag &= ~_IONBF; |
fp->_flag |= _IOLBF; |
} |
rc = 0; |
start = s; |
while( c = *s ) { |
s++; |
#ifndef __WIDECHAR__ |
if( (fputc)( c, fp ) == EOF ) { /* 23-oct-91 */ |
rc = EOF; |
break; |
} |
#else |
if( (fputwc)( c, fp ) == WEOF ) { /* 23-oct-91 */ |
rc = -1; |
break; |
} |
#endif |
} |
if( not_buffered ) { |
fp->_flag &= ~_IOLBF; |
fp->_flag |= _IONBF; |
if( rc == 0 ) { |
rc = __flush( fp ); /* 23-oct-91 */ |
} |
} |
if( rc == 0 ) { |
/* return the number of items written */ |
/* this is ok by ANSI which says that success is */ |
/* indicated by a non-negative return value */ |
rc = s - start; |
} |
_ReleaseFile( fp ); |
return( rc ); |
} |
/programs/develop/open watcom/trunk/clib/src/freefp.c |
---|
0,0 → 1,92 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Platform independent __allocfp() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "liballoc.h" |
#include "fileacc.h" |
#include "rtdata.h" |
#include "streamio.h" |
#ifdef DLHEAP |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_free dlfree |
#endif |
/* |
NOTE: This routine does not actually free the link/FILE structures. |
That is because code assumes that it can fclose the file and then |
freopen is a short time later. The __purgefp routine can be called |
to actually release the storage. |
*/ |
void __freefp( FILE * fp ) |
{ |
__stream_link **owner; |
__stream_link *link; |
_AccessIOB(); |
owner = &_RWD_ostream; |
for( ;; ) { |
link = *owner; |
if( link == NULL ) |
return; |
if( link->stream == fp ) |
break; |
owner = &link->next; |
} |
fp->_flag |= _READ | _WRITE; |
(*owner) = link->next; |
link->next = _RWD_cstream; |
_RWD_cstream = link; |
_ReleaseIOB(); |
} |
void __purgefp( void ) |
{ |
__stream_link *next; |
_AccessIOB(); |
while( _RWD_cstream != NULL ) { |
next = _RWD_cstream->next; |
lib_free( _RWD_cstream ); |
_RWD_cstream = next; |
} |
_ReleaseIOB(); |
} |
/programs/develop/open watcom/trunk/clib/src/fsync.c |
---|
0,0 → 1,74 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <errno.h> |
#if defined(__DOS__) || defined(__WINDOWS__) |
#elif defined(__NT__) |
#elif defined(__OS2__) |
#elif defined(__NETWARE__) |
#endif |
#include <unistd.h> |
#include "iomode.h" |
#include "rtcheck.h" |
#include "seterrno.h" |
/* |
// take fsync from LIBC import file |
*/ |
#if !defined (_NETWARE_LIBC) |
_WCRTLINK int fsync( int handle ) |
/*******************************/ |
{ |
int ret = 0; |
__handle_check( handle, -1 ); |
#if defined(__DOS__) || defined(__WINDOWS__) |
#elif defined(__NT__) |
// if( !FlushFileBuffers( __getOSHandle( handle ) ) ) |
// { |
// __set_errno_nt(); |
// ret = -1; |
// } |
#elif defined(__OS2__) |
#elif defined(__NETWARE__) |
#else |
#error Unknown target system |
#endif |
return( ret ); |
} |
#endif /* !defined (_NETWARE_LIBC) */ |
/programs/develop/open watcom/trunk/clib/src/hugeval.c |
---|
0,0 → 1,34 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
_WCRTLINKD unsigned short const _HUGEDATA _HugeValue[] = { 0x0000, 0x0000, 0x0000, 0x7ff0 }; |
/programs/develop/open watcom/trunk/clib/src/initfile.c |
---|
0,0 → 1,83 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Stream I/O initializer. |
* |
****************************************************************************/ |
//#include "dll.h" // needs to be first |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include "liballoc.h" |
#include "mf.h" |
#include "rtdata.h" |
#include "exitwmsg.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_malloc dlmalloc |
#define lib_free dlfree |
#define lib_realloc dlrealloc |
#endif |
void __InitFiles( void ) |
{ |
__stream_link *link; |
FILE *fp; |
fp = _RWD_iob; |
stderr->_flag &= ~(_IONBF | _IOLBF | _IOFBF); |
stderr->_flag |= _IONBF; |
for( fp = _RWD_iob; fp->_flag != 0; ++fp ) |
{ |
link = lib_malloc( sizeof( __stream_link ) ); |
if( link == NULL ) |
{ |
__fatal_runtime_error( |
"Not enough memory to allocate file structures\r\n", 1 ); |
} |
link->stream = fp; |
link->next = _RWD_ostream; |
_RWD_ostream = link; |
fp->_link = link; |
fp->_link->_base = NULL; |
fp->_link->_tmpfchar = 0; |
fp->_link->_orientation = _NOT_ORIENTED; |
} |
_RWD_cstream = NULL; |
} |
/programs/develop/open watcom/trunk/clib/src/ioalloc.c |
---|
0,0 → 1,68 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Platform independent __ioalloc() implementation. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "liballoc.h" |
#include <unistd.h> |
#include "rtdata.h" |
#include "streamio.h" |
void __ioalloc( FILE *fp ) |
{ |
__chktty( fp ); /* JBS 28-aug-90 */ |
if( fp->_bufsize == 0 ) { |
if( fp->_flag & _IOLBF ) { |
fp->_bufsize = 134; |
} else if( fp->_flag & _IONBF ) { |
/* Use small but reasonably sized buffer; otherwise we will end |
* up calling into the OS for every character, completely killing |
* performance on unbuffered stream output through printf() etc., |
* especially in extended DOS because of mode switches. |
*/ |
fp->_bufsize = 64; |
} else { |
fp->_bufsize = BUFSIZ; |
} |
} |
_FP_BASE(fp) = lib_malloc( fp->_bufsize ); |
if( _FP_BASE(fp) == NULL ) { |
fp->_flag &= ~(_IONBF | _IOLBF | _IOFBF); |
fp->_flag |= _IONBF; /* can't get big buffer */ |
_FP_BASE(fp) = (char *)&(fp->_ungotten); |
fp->_bufsize = 1; |
} else { |
fp->_flag |= _BIGBUF; /* got big buffer */ |
} |
fp->_ptr = _FP_BASE(fp); |
fp->_cnt = 0; |
} |
/programs/develop/open watcom/trunk/clib/src/iob.c |
---|
0,0 → 1,62 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Definition of __iob array. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include "rtdata.h" |
#include "rtinit.h" |
#include "tmpfname.h" |
_WCRTLINKD FILE _WCNEAR __iob[_NFILES] = { |
{ NULL, 0, NULL, _READ, 0, 0, 0 } /* stdin */ |
,{ NULL, 0, NULL, _WRITE, 1, 0, 0 } /* stdout */ |
,{ NULL, 0, NULL, _WRITE, 2, 0, 0 } /* stderr */ |
#if defined( __DOS__ ) || defined( __WINDOWS__ ) || defined( __OSI__ ) |
,{ NULL, 0, NULL, _READ|_WRITE, 3, 0, 0 } /* stdaux */ |
,{ NULL, 0, NULL, _WRITE, 4, 0, 0 } /* stdprn */ |
#endif |
}; |
__stream_link *__ClosedStreams; |
__stream_link *__OpenStreams; |
#if !defined( __UNIX__ ) |
_WCRTLINKD int _WCNEAR _fmode = O_TEXT; /* default file translation mode */ |
#endif |
extern void __InitFiles(); |
extern void __full_io_exit(); |
AXI(__InitFiles,INIT_PRIORITY_LIBRARY); |
AYI(__full_io_exit,INIT_PRIORITY_LIBRARY); |
/programs/develop/open watcom/trunk/clib/src/iobaddr.c |
---|
0,0 → 1,140 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Standard stream/file accessor routines. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "rtdata.h" |
#if !defined( __NETWARE__ ) && !defined( _THIN_LIB ) |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
if( handle > NUM_STD_STREAMS ) { |
return( NULL ); |
} else { |
return( &_RWD_iob[handle] ); |
} |
} |
_WCRTLINK FILE *__get_std_file( unsigned handle ) |
{ |
return( __get_std_stream( handle ) ); |
} |
#else |
#include <io.h> |
#if defined( _NETWARE_LIBC ) |
extern FILE **___stdin ( void ); |
extern FILE **___stdout( void ); |
extern FILE **___stderr( void ); |
extern FILE **___cin ( void ); |
extern FILE **___cout ( void ); |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
FILE *pFile = NULL; |
switch( handle ) { |
case STDIN_FILENO: |
pFile = *___stdin(); |
break; |
case STDOUT_FILENO: |
pFile = *___stdout(); |
break; |
case STDERR_FILENO: |
pFile = *___stderr(); |
break; |
default: |
break; |
} |
return( pFile ); |
} |
#elif defined( _NETWARE_CLIB ) |
extern FILE **__get_stdin ( void ); |
extern FILE **__get_stdout( void ); |
extern FILE **__get_stderr( void ); |
_WCRTLINK FILE *__get_std_stream( unsigned handle ) |
{ |
FILE *pFile = NULL; |
switch( handle ) { |
case STDIN_FILENO: |
pFile = *__get_stdin(); |
break; |
case STDOUT_FILENO: |
pFile = *__get_stdout(); |
break; |
case STDERR_FILENO: |
pFile = *__get_stderr(); |
break; |
default: |
break; |
} |
return( pFile ); |
} |
#endif |
#endif |
#if defined( __NETWARE__ ) && !defined( _THIN_LIB ) |
#include <io.h> |
FILE **__get_stdin( void ) |
{ |
static FILE *stdin_ptr; |
stdin_ptr = __get_std_stream( STDIN_FILENO ); |
return( &stdin_ptr ); |
} |
FILE **__get_stdout( void ) |
{ |
static FILE *stdout_ptr; |
stdout_ptr = __get_std_stream( STDOUT_FILENO ); |
return( &stdout_ptr ); |
} |
FILE **__get_stderr( void ) |
{ |
static FILE *stderr_ptr; |
stderr_ptr = __get_std_stream( STDERR_FILENO ); |
return( &stderr_ptr ); |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/ioexit.c |
---|
0,0 → 1,84 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: I/O streams shutdown. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "rtdata.h" |
extern void __purgefp(void); |
extern int __shutdown_stream( FILE *fp, int ); |
static int docloseall( unsigned dont_close ) |
{ |
FILE *fp; |
int number_of_files_closed; |
__stream_link *link; |
__stream_link *next; |
FILE *bottom; |
FILE *standards; |
int close_handle; |
bottom = &_RWD_iob[dont_close]; |
standards = &_RWD_iob[NUM_STD_STREAMS]; |
number_of_files_closed = 0; |
for( link = _RWD_ostream; link != NULL; link = next ) { |
next = link->next; |
fp = link->stream; |
close_handle = 1; |
if ((fp->_flag & _DYNAMIC) || (fp->_flag & _TMPFIL)) |
{ |
__shutdown_stream( fp, close_handle ); |
++number_of_files_closed; |
} |
else if( fp >= bottom ) { |
#ifndef __NETWARE__ |
/* close the file, but leave the handle open */ |
if( fp < standards ) { |
close_handle = 0; |
} |
#endif |
__shutdown_stream( fp, close_handle ); |
++number_of_files_closed; |
} |
} |
return( number_of_files_closed ); |
} |
_WCRTLINK int fcloseall( void ) |
{ |
return( docloseall( NUM_STD_STREAMS ) ); |
} |
void __full_io_exit( void ) |
{ |
docloseall( 0 ); |
__purgefp(); |
} |
/programs/develop/open watcom/trunk/clib/src/iomode.c |
---|
0,0 → 1,80 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: io_mode handle information array manipulation |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <string.h> |
#include <errno.h> |
#include "rtdata.h" |
//#include "liballoc.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "iomode.h" |
unsigned __NFiles = _NFILES; /* maximum # of files we can open */ |
#if defined(__NETWARE__) |
#error NO IO MODE MANAGER UNDER NETWARE |
#endif |
#if !defined(__UNIX__) |
unsigned _HUGEDATA __init_mode[_NFILES] = { /* file mode information (flags) */ |
_READ, /* stdin */ |
_WRITE, /* stdout */ |
_WRITE, /* stderr */ |
_READ|_WRITE, /* stdaux */ |
_WRITE /* stdprn */ |
}; |
unsigned *__io_mode = __init_mode; /* initially points to static array */ |
unsigned __GetIOMode( int handle ) |
{ |
if( handle >= __NFiles ) |
{ |
return( 0 ); |
} |
return( __io_mode[handle] ); |
} |
void __SetIOMode_nogrow( int handle, unsigned value ) |
{ |
if( handle < __NFiles ) |
{ |
__io_mode[handle] = value; /* we're closing it; smite _INITIALIZED */ |
} |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/iomodtty.c |
---|
0,0 → 1,59 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: check tty for standard handles in the iomode array |
* |
****************************************************************************/ |
#include "variety.h" |
#include <unistd.h> |
#include "rtdata.h" |
//#include "liballoc.h" |
#include "fileacc.h" |
#include "handleio.h" |
#include "iomode.h" |
#define _INITIALIZED _DYNAMIC |
void __ChkTTYIOMode( int handle ) |
{ |
if( handle < NUM_STD_STREAMS && !(__io_mode[handle] & _INITIALIZED) ) |
{ |
__io_mode[handle] |= _INITIALIZED; |
if( isatty( handle ) ) |
{ |
__io_mode[handle] |= _ISTTY; |
} |
} |
} |
// For F77 to call |
unsigned __IOMode( int handle ) |
{ |
__ChkTTYIOMode( handle ); |
return( __GetIOMode( handle ) ); |
} |
/programs/develop/open watcom/trunk/clib/src/isattwnt.c |
---|
0,0 → 1,54 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of isatty() for Win32. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <unistd.h> |
//#include <windows.h> |
//#include "defwin.h" |
#include "iomode.h" |
#include "fileacc.h" |
/* |
DWORD GetFileType( |
HANDLE hFile // handle to file |
); |
Return value can be: |
FILE_TYPE_CHAR The specified file is a character file, |
typically an LPT device or a console |
*/ |
_WCRTLINK int isatty( int hid ) |
{ |
// if( GetFileType( __getOSHandle( hid ) ) == FILE_TYPE_CHAR ) { |
// return( 1 ); |
// } |
return( 0 ); |
} |
/programs/develop/open watcom/trunk/clib/src/istable.c |
---|
0,0 → 1,295 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Character classification table. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <ctype.h> |
_WCRTLINKD const char _HUGEDATA _IsTable[257] = { |
#define ___0__ 0 |
/* -1,EOF */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 00,NUL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 01,SOH */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 02,STX */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 03,ETX */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 04,EOT */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 05,ENQ */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 06,NAK */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 07,BEL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 08,BS */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 09,TAB */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0A,LF */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0B,VT */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0C,FF */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0D,CR */ ___0__|___0__|___0__|___0__|___0__|___0__|_SPACE|_CNTRL, |
/* 0E,SI */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 0F,SO */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 10, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 11, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 12, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 13, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 14, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 15, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 16, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 17, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 18, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 19, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 1F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 20, */ ___0__|___0__|___0__|___0__|_PRINT|___0__|_SPACE|___0__, |
/* 21, ! */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 22, " */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 23, # */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 24, $ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 25, % */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 26, & */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 27, ' */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 28, ( */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 29, ) */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2A, * */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2B, + */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2C, , */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2D, - */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2E, . */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 2F, / */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 30, 0 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 31, 1 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 32, 2 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 33, 3 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 34, 4 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 35, 5 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 36, 6 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 37, 7 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 38, 8 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 39, 9 */ ___0__|___0__|_DIGIT|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 3A, : */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3B, ; */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3C, < */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3D, = */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3E, > */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 3F, ? */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 40, @ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 41, A */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 42, B */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 43, C */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 44, D */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 45, E */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 46, F */ ___0__|_UPPER|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 47, G */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 48, H */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 49, I */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4A, J */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4B, K */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4C, L */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4D, M */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4E, N */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 4F, O */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 50, P */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 51, Q */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 52, R */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 53, S */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 54, T */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 55, U */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 56, V */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 57, W */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 58, X */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 59, Y */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 5A, Z */ ___0__|_UPPER|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 5B, [ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5C, \ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5D, ] */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5E, ^ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 5F, _ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 60, ` */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 61, a */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 62, b */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 63, c */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 64, d */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 65, e */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 66, f */ _LOWER|___0__|___0__|_XDIGT|_PRINT|___0__|___0__|___0__, |
/* 67, g */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 68, h */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 69, i */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6A, j */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6B, k */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6C, l */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6D, m */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6E, n */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 6F, o */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 70, p */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 71, q */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 72, r */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 73, s */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 74, t */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 75, u */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 76, v */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 77, w */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 78, x */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 79, y */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 7A, z */ _LOWER|___0__|___0__|___0__|_PRINT|___0__|___0__|___0__, |
/* 7B, { */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7C, | */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7D, } */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7E, ~ */ ___0__|___0__|___0__|___0__|_PRINT|_PUNCT|___0__|___0__, |
/* 7F,DEL */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|_CNTRL, |
/* 80, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 81, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 82, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 83, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 84, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 85, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 86, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 87, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 88, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 89, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 8F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 90, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 91, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 92, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 93, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 94, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 95, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 96, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 97, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 98, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 99, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9A, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9B, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9C, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9D, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9E, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* 9F, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* A9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* AF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* B9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* BF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* C9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* CF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* D9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* DF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* E9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* ED, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* EF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F0, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F1, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F2, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F3, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F4, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F5, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F6, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F7, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F8, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* F9, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FA, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FB, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FC, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FD, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FE, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__, |
/* FF, */ ___0__|___0__|___0__|___0__|___0__|___0__|___0__|___0__ }; |
/programs/develop/open watcom/trunk/clib/src/mbinit.c |
---|
0,0 → 1,306 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <string.h> |
#include <mbstring.h> |
#include "mbchar.h" |
unsigned int __MBCodePage = 0; /* default code page */ |
static void set_dbcs_table( int low, int high ) |
{ |
memset( __MBCSIsTable + low + 1, _MB_LEAD, high - low + 1 ); |
} |
static void clear_dbcs_table( void ) |
{ |
__IsDBCS = 0; /* SBCS for now */ |
__MBCodePage = 0; |
memset( __MBCSIsTable, 0, 257 ); |
} |
/**** |
***** Initialize a multi-byte character set. Returns 0 on success. |
****/ |
int __mbinit( int codepage ) |
{ |
/*** Handle values from _setmbcp ***/ |
if( codepage == _MBINIT_CP_ANSI ) |
{ |
codepage = 0; |
} |
else |
if( codepage == _MBINIT_CP_OEM ) |
{ |
codepage = 0; |
} |
else |
if( codepage == _MBINIT_CP_SBCS ) |
{ |
clear_dbcs_table(); |
return( 0 ); |
} |
else |
if( codepage == _MBINIT_CP_932 ) |
{ |
clear_dbcs_table(); |
set_dbcs_table( 0x81, 0x9F ); |
set_dbcs_table( 0xE0, 0xFC ); |
__IsDBCS = 1; |
__MBCodePage = 932; |
return( 0 ); |
} |
return( 0 ); /* return success code */ |
} |
/**** |
***** Query DOS to find the valid lead byte ranges. |
****/ |
#if defined(__DOS__) && !defined(__OSI__) |
#ifndef __386__ |
// for some unknown reason NT DPMI returns for DOS service 6300h |
// Carry=0, odd SI value and DS stay unchanged |
// this case is also tested as wrong int 21h result |
#if 1 |
#pragma aux dos_get_dbcs_lead_table = \ |
"push ds" \ |
"xor ax,ax" \ |
"mov ds,ax" \ |
"mov ah,63h" /* get DBCS vector table */ \ |
"int 21h" \ |
"mov di,ds" \ |
"jnc label1" \ |
"xor di,di" \ |
"label1:" \ |
"test di,di" \ |
"jnz exit1" \ |
"mov si,di" \ |
"exit1:" \ |
"pop ds" \ |
value [di si] \ |
modify [ax bx cx dx si di es]; |
#else |
unsigned short _WCFAR *dos_get_dbcs_lead_table( void ) |
/****************************************************/ |
{ |
union REGS regs; |
struct SREGS sregs; |
regs.w.ax = 0x6300; /* get lead byte table code */ |
sregs.ds = 0; |
sregs.es = 0; |
intdosx( ®s, ®s, &sregs ); /* call DOS */ |
if( regs.w.cflag || ( sregs.ds == 0 )) /* ensure function succeeded */ |
return( NULL ); |
return( MK_FP( sregs.ds, regs.w.si ) ); /* return pointer to table */ |
} |
#endif |
#if 0 |
unsigned short dos_get_code_page( void ) |
/**************************************/ |
{ |
union REGS regs; |
struct SREGS sregs; |
unsigned char buf[7]; |
regs.w.ax = 0x6501; /* get international info */ |
regs.w.bx = 0xFFFF; /* global code page */ |
regs.w.cx = 7; /* buffer size */ |
regs.w.dx = 0xFFFF; /* current country */ |
regs.w.di = FP_OFF( (void __far*)buf ); /* buffer offset */ |
sregs.es = FP_SEG( (void __far*)buf ); /* buffer segment */ |
sregs.ds = 0; /* in protected mode (dos16m) DS must be initialized */ |
intdosx( ®s, ®s, &sregs ); /* call DOS */ |
if( regs.w.cflag ) return( 0 ); /* ensure function succeeded */ |
return( * (unsigned short*)(buf+5) ); /* return code page */ |
} |
#else |
#pragma aux dos_get_code_page = \ |
"push ds" \ |
"push bp" \ |
"mov bp,sp" \ |
"sub sp,8" \ |
"xor ax,ax" \ |
"mov ds,ax" \ |
"mov ax,6501h" /* get international info */ \ |
"mov bx,0ffffh" /* global code page */ \ |
"mov cx,0007h" /* buffer size */ \ |
"mov dx,0ffffh" /* current country */ \ |
"lea di,[bp-8]" /* buffer offset */ \ |
"push ss" \ |
"pop es" /* buffer segment */ \ |
"int 21h" /* call DOS */ \ |
"mov ax,[bp-8+5]" /* code page */ \ |
"jnc NoError" \ |
"xor ax,ax" \ |
"NoError:" \ |
"mov sp,bp" \ |
"pop bp" \ |
"pop ds" \ |
value [ax] \ |
modify [ax bx cx dx di es]; |
#endif |
#else |
#pragma pack(__push,1); |
typedef struct { |
unsigned short int_num; |
unsigned short real_ds; |
unsigned short real_es; |
unsigned short real_fs; |
unsigned short real_gs; |
unsigned long real_eax; |
unsigned long real_edx; |
} PHARLAP_block; |
#pragma pack(__pop); |
unsigned short _WCFAR *dos_get_dbcs_lead_table( void ) |
/****************************************************/ |
{ |
union REGPACK regs; |
if( _IsPharLap() ) { |
PHARLAP_block pblock; |
memset( &pblock, 0, sizeof( pblock ) ); |
memset( ®s, 0, sizeof( regs ) ); |
pblock.real_eax = 0x6300; /* get DBCS vector table */ |
pblock.int_num = 0x21; /* DOS call */ |
regs.x.eax = 0x2511; /* issue real-mode interrupt */ |
regs.x.edx = FP_OFF( &pblock ); /* DS:EDX -> parameter block */ |
regs.w.ds = FP_SEG( &pblock ); |
intr( 0x21, ®s ); |
if( pblock.real_ds != 0xFFFF ) { /* weird OS/2 value */ |
return( MK_FP( _ExtenderRealModeSelector, |
(((unsigned)pblock.real_ds)<<4) + regs.w.si ) ); |
} |
} else if( _IsRational() ) { |
rm_call_struct dblock; |
memset( &dblock, 0, sizeof( dblock ) ); |
dblock.eax = 0x6300; /* get DBCS vector table */ |
DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); |
if( (dblock.flags & 1) == 0 ) { |
return( MK_FP( _ExtenderRealModeSelector, |
(((unsigned)dblock.ds)<<4) + dblock.esi ) ); |
} |
} |
return( NULL ); |
} |
unsigned short dos_get_code_page( void ) |
/**************************************/ |
{ |
union REGPACK regs; |
unsigned short __far * temp; |
unsigned short real_seg; |
unsigned short codepage = 0; |
/*** Get the code page ***/ |
if( _IsPharLap() ) { |
union REGS r; |
PHARLAP_block pblock; |
/*** Alloc DOS Memory under Phar Lap ***/ |
memset( &r, 0, sizeof( r ) ); |
r.x.ebx = 1; |
r.x.eax = 0x25c0; |
intdos( &r, &r ); |
real_seg = r.w.ax; |
memset( &pblock, 0, sizeof( pblock ) ); |
memset( ®s, 0, sizeof( regs ) ); |
pblock.real_eax = 0x6501; /* get international info */ |
pblock.real_edx = 0xFFFF; /* current country */ |
pblock.real_es = real_seg; /* buffer segment */ |
regs.x.ebx = 0xFFFF; /* global code page */ |
regs.x.ecx = 7; /* buffer size */ |
regs.x.edi = 0; /* buffer offset */ |
pblock.int_num = 0x21; /* DOS call */ |
regs.x.eax = 0x2511; /* issue real-mode interrupt */ |
regs.x.edx = FP_OFF( &pblock ); /* DS:EDX -> parameter block */ |
regs.w.ds = FP_SEG( &pblock ); |
intr( 0x21, ®s ); |
if( pblock.real_ds != 0xFFFF ) { /* weird OS/2 value */ |
temp = MK_FP( _ExtenderRealModeSelector, (real_seg<<4) + 5 ); |
codepage = *temp; |
} |
/*** Free DOS Memory under Phar Lap ***/ |
r.x.ecx = real_seg; |
r.x.eax = 0x25c1; |
intdos( &r, &r ); |
} else if( _IsRational() ) { |
unsigned long dpmi_rc; |
unsigned short selector; |
rm_call_struct dblock; |
/*** Allocate some DOS memory with DPMI ***/ |
dpmi_rc = DPMIAllocateDOSMemoryBlock( 1 ); /* one paragraph is enough */ |
real_seg = (unsigned short) dpmi_rc; |
selector = (unsigned short) (dpmi_rc>>16); |
memset( &dblock, 0, sizeof( dblock ) ); |
dblock.eax = 0x6501; /* get international info */ |
dblock.ebx = 0xFFFF; /* global code page */ |
dblock.ecx = 7; /* buffer size */ |
dblock.edx = 0xFFFF; /* current country */ |
dblock.edi = 0; /* buffer offset */ |
dblock.es = real_seg; /* buffer segment */ |
DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); |
if( (dblock.flags & 1) == 0 ) { |
temp = MK_FP( _ExtenderRealModeSelector, (real_seg<<4) + 5 ); |
codepage = *temp; |
} |
/*** Free DOS memory with DPMI ***/ |
DPMIFreeDOSMemoryBlock( selector ); |
} |
return( codepage ); |
} |
#endif |
#endif |
/programs/develop/open watcom/trunk/clib/src/mbisdbcs.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <mbstring.h> |
#include "rtinit.h" |
_WCRTLINKD int __IsDBCS; |
/programs/develop/open watcom/trunk/clib/src/mbislead.c |
---|
0,0 → 1,59 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <mbstring.h> |
#include "mbchar.h" |
#include "rtinit.h" |
_WCRTLINKD unsigned char __MBCSIsTable[257]; |
/** |
* Determine whether or not the specified byte is a lead byte. |
*/ |
_WCRTLINK int (_ismbblead)( const unsigned int ch ) |
{ |
return( __MBCSIsTable[ch+1] & _MB_LEAD ); |
} |
/** |
* If this module is linked in, the startup code will call this function, |
* which will initialize the default multibyte code page. |
*/ |
static void __mbInitOnStartup( void ) |
{ |
__mbinit( 0 ); |
} |
AXI( __mbInitOnStartup, INIT_PRIORITY_LIBRARY ) |
/programs/develop/open watcom/trunk/clib/src/mbtowc.c |
---|
0,0 → 1,70 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <mbstring.h> |
#include "farfunc.h" |
/**** |
***** Convert a multibyte character to a wide character. |
****/ |
_WCRTLINK int _NEARFAR(mbtowc,_fmbtowc)( wchar_t _FFAR *pwc, const char _FFAR *ch, size_t n ) |
{ |
/*** Catch special cases ***/ |
if( ch == NULL ) return( 0 ); |
if( n == 0 ) return( -1 ); |
if( *ch == '\0' ) { |
if( pwc != NULL ) *pwc = L'\0'; |
return( 0 ); |
} |
if( _ismbblead( ch[0] ) && ch[1] == '\0' ) return( -1 ); /* invalid */ |
/*** Convert the character ***/ |
if( _ismbblead(*ch) && n>=2 ) { /* lead byte present? */ |
if( pwc != NULL ) { |
*pwc = (((wchar_t)ch[0])<<8) | /* convert to lead:trail */ |
(wchar_t)ch[1]; |
} |
return( 2 ); /* return char size */ |
} else if( !_ismbblead(*ch) ) { |
if( pwc != NULL ) { |
*pwc = (wchar_t)ch[0]; /* convert to 00:byte */ |
} |
return( 1 ); /* return char size */ |
} else { |
return( -1 ); /* n==1, but char 2 bytes */ |
} |
} |
/programs/develop/open watcom/trunk/clib/src/printf.c |
---|
0,0 → 1,73 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of printf() - formatted output. |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include "farsupp.h" |
#include "printf.h" |
#include "fprtf.h" |
void debug_out_str(const char* str); |
void _stdcall debug_out(int ch); |
static char _dest[512]; |
_WCRTLINK int __F_NAME(printf,wprintf)( const CHAR_TYPE *format, ... ) |
{ |
int retval; |
auto va_list args; |
va_start( args, format ); |
// return( __F_NAME(__fprtf,__fwprtf)( stdout, format, args ) ); |
va_start( args, format ); |
#ifdef __WIDECHAR__ |
retval = _vswprintf( _dest, format, args ); |
#else |
retval = vsprintf( _dest, format, args ); |
#endif |
debug_out_str(_dest); |
return retval; |
} |
void debug_out_str(const char* str) |
{ |
while (*str != 0) |
{ |
debug_out(*str); |
str++; |
} |
} |
/programs/develop/open watcom/trunk/clib/src/prtf.c |
---|
0,0 → 1,1100 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: __prtf() - low level string formatter. |
* |
****************************************************************************/ |
#define __LONG_LONG_SUPPORT__ |
#if !defined( __NETWARE__ ) && !defined( __UNIX__ ) |
#define USE_MBCS_TRANSLATION |
#endif |
#include "variety.h" |
#ifdef SAFE_PRINTF |
#include "saferlib.h" |
#endif |
#include "widechar.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdlib.h> |
#include <string.h> |
#include <ctype.h> |
#if defined( __WIDECHAR__ ) || defined( USE_MBCS_TRANSLATION ) |
#include <mbstring.h> |
#endif |
#include "ftos.h" |
#include "farsupp.h" |
#include "printf.h" |
#include "prtscncf.h" |
#include "fixpoint.h" |
#include "myvalist.h" |
#define BUF_SIZE 72 /* 64-bit ints formatted as binary can get big */ |
#define TRUE 1 |
#define FALSE 0 |
#define PASCAL_STRING 'S' /* for Novell */ |
#define WIDE_CHAR_STRING 'S' |
#if defined( __QNX_386__ ) |
/* for use in QNX 32-bit shared library */ |
#pragma aux __prtf "_sl_*" far; |
#endif |
#if defined( __QNX__ ) |
#define EFG_PRINTF __EFG_Format |
#else |
#define EFG_PRINTF (*__EFG_printf) |
#endif |
extern FAR_STRING EFG_PRINTF( char *buffer, my_va_list *args, _mbcs_SPECS __SLIB *specs ); |
#if defined( __WIDECHAR__ ) |
#define _FAR_OTHER_STRING FAR_ASCII_STRING |
#else |
#define _FAR_OTHER_STRING FAR_UNI_STRING |
#endif |
#if defined( __WINDOWS_386__ ) |
#ifdef __SW_3S |
#pragma aux slib_callback_t modify [eax edx ecx fs gs]; |
#else |
#pragma aux slib_callback_t modify [fs gs]; |
#endif |
#endif |
/* forward references */ |
static const CHAR_TYPE *evalflags( const CHAR_TYPE *, SPECS __SLIB * ); |
static FAR_STRING formstring( CHAR_TYPE *, my_va_list *, SPECS __SLIB *, CHAR_TYPE * ); |
static const CHAR_TYPE * getprintspecs( const CHAR_TYPE *, my_va_list *, SPECS __SLIB * ); |
#ifdef USE_MBCS_TRANSLATION |
static void write_wide_string( FAR_UNI_STRING str, SPECS *specs, |
slib_callback_t *out_putc ); |
static void write_skinny_string( FAR_ASCII_STRING str, SPECS *specs, |
slib_callback_t *out_putc ); |
#endif |
#ifdef SAFE_PRINTF |
int __F_NAME(__prtf_s,__wprtf_s) |
#else |
int __F_NAME(__prtf,__wprtf) |
#endif |
( void __SLIB *dest, /* parm for use by out_putc */ |
const CHAR_TYPE *format, /* pointer to format string */ |
va_list args, /* pointer to pointer to args*/ |
#ifdef SAFE_PRINTF |
const char **msg, /* rt-constraint message */ |
#endif |
slib_callback_t *out_putc ) /* char output routine */ |
{ |
CHAR_TYPE buffer[ BUF_SIZE ]; |
CHAR_TYPE null_char = '\0'; |
CHAR_TYPE *a; |
FAR_STRING arg; |
const CHAR_TYPE *ctl; |
SPECS specs; |
specs._dest = dest; |
specs._flags = 0; |
specs._version = SPECS_VERSION; |
specs._output_count = 0; |
ctl = format; |
while( *ctl != NULLCHAR ) { |
if( *ctl != '%' ) { |
(out_putc)( &specs, *ctl++ ); |
} else { |
++ctl; |
{ |
my_va_list pargs; |
pargs = MY_VA_LIST( args ); |
ctl = getprintspecs( ctl, &pargs, &specs ); |
MY_VA_LIST( args ) = pargs; |
} |
specs._character = *ctl++; |
if( specs._character == NULLCHAR ) |
break; /* 05-jan-89 */ |
if( specs._character == 'n' ) { |
#ifdef SAFE_PRINTF |
/* The %n specifier is not allowed - too dangerous. */ |
*msg = "%n"; |
break; |
#else |
FAR_INT iptr; |
#if defined( __FAR_SUPPORT__ ) |
if( specs._flags & SPF_FAR ) { |
iptr = va_arg( args, int _WCFAR * ); |
} else if( specs._flags & SPF_NEAR ) { |
iptr = va_arg( args, int _WCNEAR * ); |
} else { |
iptr = va_arg( args, int * ); |
} |
#else |
iptr = va_arg( args, int * ); |
#endif |
if( specs._flags & SPF_CHAR ) { |
*((FAR_CHAR)iptr) = specs._output_count; |
} else if( specs._flags & SPF_SHORT ) { |
*((FAR_SHORT)iptr) = specs._output_count; |
} else if( specs._flags & SPF_LONG ) { |
*((FAR_LONG)iptr) = specs._output_count; |
#if defined( __LONG_LONG_SUPPORT__ ) |
} else if( specs._flags & SPF_LONG_LONG ) { |
*((FAR_INT64)iptr) = specs._output_count; |
#endif |
} else { |
*iptr = specs._output_count; |
} |
#endif /* SAFE_PRINTF */ |
} else { |
#ifdef SAFE_PRINTF |
if( specs._character == 's' || specs._character == 'S' ) { |
FAR_STRING str; |
va_list args_copy; |
/* Make sure %s argument is not NULL. Note that near pointers |
* in segmented models need special handling because only |
* offset will be NULL, not segment. |
*/ |
va_copy( args_copy, args ); |
#if defined( __FAR_SUPPORT__ ) |
if( specs._flags & SPF_FAR ) { |
str = va_arg( args_copy, CHAR_TYPE _WCFAR * ); |
} else if( specs._flags & SPF_NEAR ) { |
CHAR_TYPE _WCNEAR *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE _WCNEAR * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} else { |
CHAR_TYPE *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} |
#else |
str = va_arg( args_copy, CHAR_TYPE * ); |
#endif |
va_end( args_copy ); |
if( str == NULL ) { |
*msg = "%s -> NULL"; |
break; /* bail out */ |
} |
} |
#endif /* SAFE_PRINTF */ |
{ |
my_va_list pargs; |
pargs = MY_VA_LIST( args ); |
arg = formstring( buffer, &pargs, &specs, &null_char ); |
MY_VA_LIST( args ) = pargs; |
} |
specs._fld_width -= specs._n0 + |
specs._nz0 + |
specs._n1 + |
specs._nz1 + |
specs._n2 + |
specs._nz2; |
if( !(specs._flags & SPF_LEFT_ADJUST) ) { |
if( specs._pad_char == ' ' ) { |
while( specs._fld_width > 0 ) { |
(out_putc)( &specs, ' ' ); |
--specs._fld_width; |
} |
} |
} |
a = buffer; |
while( specs._n0 > 0 ) { |
(out_putc)( &specs, *a ); |
++a; |
--specs._n0; |
} |
while( specs._nz0 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz0; |
} |
if( specs._character == 's' ) { |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs._flags & SPF_SHORT ) { |
write_skinny_string( (FAR_ASCII_STRING)arg, &specs, out_putc ); |
} else |
#elif !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs._flags & SPF_LONG ) { |
write_wide_string( (FAR_UNI_STRING)arg, &specs, out_putc ); |
} else |
#endif |
{ |
while( specs._n1 > 0 ) { |
(out_putc)( &specs, *arg++ ); |
--specs._n1; |
} |
} |
} |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
else if( specs._character == WIDE_CHAR_STRING ) { |
write_wide_string( (FAR_UNI_STRING)arg, &specs, out_putc ); |
} else |
#elif !defined( __WIDECHAR__ ) && defined( __NETWARE__ ) |
else if( specs._character == WIDE_CHAR_STRING ) { |
} else |
#endif |
{ |
while( specs._n1 > 0 ) { |
(out_putc)( &specs, *arg++ ); |
--specs._n1; |
} |
} |
while( specs._nz1 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz1; |
} |
while( specs._n2 > 0 ) { |
(out_putc)( &specs, *arg ); |
++arg; |
--specs._n2; |
} |
while( specs._nz2 > 0 ) { |
(out_putc)( &specs, '0' ); |
--specs._nz2; |
} |
if( specs._flags & SPF_LEFT_ADJUST ) { |
while( specs._fld_width > 0 ) { |
(out_putc)( &specs, ' ' ); |
--specs._fld_width; |
} |
} |
} |
} |
} |
return( specs._output_count ); |
} |
static const CHAR_TYPE * getprintspecs( const CHAR_TYPE *ctl, |
my_va_list *pargs, |
SPECS __SLIB *specs ) |
{ |
specs->_pad_char = ' '; |
ctl = evalflags( ctl, specs ); |
specs->_fld_width = 0; |
if( *ctl == '*' ) { |
specs->_fld_width = va_arg( pargs->v, int ); |
if( specs->_fld_width < 0 ) { |
specs->_fld_width = - specs->_fld_width; |
specs->_flags |= SPF_LEFT_ADJUST; |
} |
ctl++; |
} else { |
while(( *ctl >= '0' ) && ( *ctl <= '9' )) { |
specs->_fld_width = specs->_fld_width * 10 + ( *ctl++ - '0' ); |
} |
} |
specs->_prec = -1; |
if( *ctl == '.' ) { |
specs->_prec = 0; |
ctl++; |
if( *ctl == '*' ) { |
specs->_prec = va_arg( pargs->v, int ); |
if( specs->_prec < 0 ) |
specs->_prec = -1; /* 19-jul-90 */ |
ctl++; |
} else { |
while(( *ctl >= '0' ) && ( *ctl <= '9' )) { |
specs->_prec = specs->_prec * 10 + ( *ctl++ - '0' ); |
} |
} |
/* |
"For b, d, i, o, u, x, X, e, E, f, g and G conversions, leading |
zeros (following any indication of sign or base) are used to |
pad the field width; no space padding is performed. If the 0 |
or - flags both appear, the 0 flag is ignored. For b, d, i, o, |
u, x or X conversions, if a precision is specified, the 0 flag |
is ignored. For other conversions, the behaviour is undefined." |
*/ |
// if( specs->_prec != -1 ) specs->_pad_char = ' '; /* 30-jul-95 *//*removed by JBS*/ |
} |
switch( *ctl ) { |
case 'l': |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( ctl[1] == 'l' ) { |
specs->_flags |= SPF_LONG_LONG; |
ctl += 2; |
break; |
} |
#endif |
/* fall through */ |
ZSPEC_CASE_LONG |
TSPEC_CASE_LONG |
case 'w': |
specs->_flags |= SPF_LONG; |
ctl++; |
break; |
case 'h': |
if( ctl[1] == 'h' ) { |
specs->_flags |= SPF_CHAR; |
ctl += 2; |
break; |
} |
specs->_flags |= SPF_SHORT; |
ctl++; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
case 'I': |
if(( ctl[1] == '6' ) && ( ctl[2] == '4' )) { |
specs->_flags |= SPF_LONG_LONG; |
ctl += 3; |
} |
break; |
JSPEC_CASE_LLONG |
/* fall through */ |
#endif |
case 'L': |
specs->_flags |= SPF_LONG_DOUBLE | SPF_LONG_LONG; |
ctl++; |
break; |
#if defined( __FAR_SUPPORT__ ) |
case 'F': /* conflicts with ISO-defined 'F' conversion */ |
/* fall through */ |
#endif |
case 'W': /* 8086 specific flag for FAR pointer */ |
specs->_flags |= SPF_FAR; |
ctl++; |
break; |
case 'N': /* 8086 specific flag for NEAR pointer */ |
specs->_flags |= SPF_NEAR; |
ctl++; |
break; |
#if defined( TSPEC_IS_INT ) || defined( ZSPEC_IS_INT ) |
TSPEC_CASE_INT /* If either 't' or 'z' spec corresponds to 'int', */ |
ZSPEC_CASE_INT /* we need to parse and ignore the spec. */ |
ctl++; |
break; |
#endif |
} |
return( ctl ); |
} |
static const CHAR_TYPE *evalflags( const CHAR_TYPE *ctl, SPECS __SLIB *specs ) |
{ |
specs->_flags = 0; |
for( ; ; ctl++ ) { |
if( *ctl == '-' ) { |
specs->_flags |= SPF_LEFT_ADJUST; |
} else if( *ctl == '#' ) { |
specs->_flags |= SPF_ALT; |
} else if( *ctl == '+' ) { |
specs->_flags |= SPF_FORCE_SIGN; |
specs->_flags &= ~SPF_BLANK; |
} else if( *ctl == ' ' ) { |
if( ( specs->_flags & SPF_FORCE_SIGN ) == 0 ) { |
specs->_flags |= SPF_BLANK; |
} |
} else if( *ctl == '0' ) { |
specs->_pad_char = '0'; |
#ifdef __QNX__ |
specs->_flags |= SPF_ZERO_PAD; |
#endif |
} else { |
break; |
} |
} |
return( ctl ); |
} |
static int far_strlen( FAR_STRING s, int precision ) |
{ |
int len; |
len = 0; |
while(( len != precision ) && ( *s++ != NULLCHAR )) |
++len; |
return( len ); |
} |
/* |
* far_other_strlen - calculates the length of an ascii string |
* for the unicode version |
* - calculates the length of a unicode string for |
* the standard version |
*/ |
static int far_other_strlen( FAR_STRING s, int precision ) |
{ |
int len = 0; |
_FAR_OTHER_STRING ptr = (_FAR_OTHER_STRING)s; |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
char mbBuf[MB_CUR_MAX]; |
int chBytes; |
if( precision == -1 ) { |
while( *ptr ) { |
chBytes = wctomb( mbBuf, *ptr++ ); |
if( chBytes != -1 ) { |
len += chBytes; |
} |
} |
return( len ); |
} |
while( *ptr && ( len <= precision )) { |
chBytes = wctomb( mbBuf, *ptr++ ); |
if( chBytes != -1 ) { |
len += chBytes; |
} |
} |
return(( len <= precision ) ? len : precision ); |
#else |
while( *ptr++ && ( len != precision )) |
++len; |
return( len ); |
#endif |
} |
static void fmt4hex( unsigned value, CHAR_TYPE *buf, int maxlen ) |
{ |
int i, len; |
__F_NAME(itoa,_itow)( value, buf, 16 ); |
len = __F_NAME(strlen,wcslen)( buf ); |
for( i = maxlen - 1; len; --i ) { |
--len; |
buf[i] = buf[len]; |
} |
while( i >= 0 ) { |
buf[i] = '0'; |
--i; |
} |
buf[maxlen] = NULLCHAR; |
} |
static void FixedPoint_Format( CHAR_TYPE *buf, long value, SPECS __SLIB *specs ) |
{ |
T32 at; |
int i; |
CHAR_TYPE *bufp; |
at.sWhole = value; |
if( at.sWhole < 0 ) { |
at.sWhole = - at.sWhole; |
*buf++ = '-'; |
} |
if( specs->_prec == -1 ) |
specs->_prec = 4; |
__F_NAME(itoa,_itow)( at.wd.hi, buf, 10 ); |
bufp = buf; /* remember start address of buffer */ |
while( *buf ) |
++buf; |
if( specs->_prec != 0 ) { |
*buf++ = '.'; |
for( i = 0; i < specs->_prec; i++ ) { |
at.wd.hi = 0; |
at.uWhole *= 10; |
*buf++ = at.bite.b3 + '0'; |
} |
*buf = NULLCHAR; |
} |
if( at.wd.lo & 0x8000 ) { /* fraction >= .5, need to round */ |
for(;;) { /* 22-dec-91 */ |
if( buf == bufp ) { |
*buf++ = '1'; |
while( *buf == '0' ) |
++buf; |
if( *buf == '.' ) { |
*buf++ = '0'; |
*buf++ = '.'; |
while( *buf == '0' ) { |
++buf; |
} |
} |
*buf++ = '0'; |
*buf = NULLCHAR; |
break; |
} |
--buf; |
if( *buf == '.' ) |
--buf; |
if( *buf != '9' ) { |
++ *buf; |
break; |
} |
*buf = '0'; |
} |
} |
} |
static void float_format( CHAR_TYPE *buffer, my_va_list *pargs, SPECS __SLIB *specs ) |
{ |
#ifdef __WIDECHAR__ |
char mbBuffer[BUF_SIZE*MB_CUR_MAX]; |
_mbcs_SPECS mbSpecs; |
int count; |
size_t rc; |
char *p; |
#endif // __WIDECHAR__ |
#ifdef __WIDECHAR__ |
/* |
* EFG_PRINTF can only handle MBCS buffers and the MBCS version of the |
* SPECS structure. So, make a _mbcs_SPECS structure equivalent to the |
* _wide_SPECS one, and use that instead. Note that we can't use |
* memcpy() because some field sizes are different. |
*/ |
mbSpecs._dest = NULL; /* this field isn't actually used */ |
mbSpecs._flags = specs->_flags; |
mbSpecs._version = specs->_version; |
mbSpecs._fld_width = specs->_fld_width; |
mbSpecs._prec = specs->_prec; |
mbSpecs._output_count = specs->_output_count; |
mbSpecs._n0 = specs->_n0; |
mbSpecs._nz0 = specs->_nz0; |
mbSpecs._n1 = specs->_n1; |
mbSpecs._nz1 = specs->_nz1; |
mbSpecs._n2 = specs->_n2; |
mbSpecs._nz2 = specs->_nz2; |
mbSpecs._character = (char)specs->_character; |
mbSpecs._pad_char = (char)specs->_pad_char; |
#endif |
#ifdef __WIDECHAR__ |
EFG_PRINTF( mbBuffer, pargs, &mbSpecs ); |
#else |
EFG_PRINTF( buffer, pargs, specs ); |
#endif |
#ifdef __WIDECHAR__ |
/* |
* Now convert the returned information back into our _wide_SPECS |
* structure. We can't just use mbstowcs because it's an array of |
* characters, not a string. |
*/ |
p = mbBuffer; |
for( count = 0; count < BUF_SIZE; count++ ) { |
rc = mbtowc( &(buffer[count]), p, MB_CUR_MAX ); |
if( rc == -1 ) { |
buffer[count] = L'?'; |
} |
p = _mbsinc( p ); |
} |
specs->_flags = mbSpecs._flags; |
specs->_version = mbSpecs._version; |
specs->_fld_width = mbSpecs._fld_width; |
specs->_prec = mbSpecs._prec; |
specs->_output_count = mbSpecs._output_count; |
specs->_n0 = mbSpecs._n0; |
specs->_nz0 = mbSpecs._nz0; |
specs->_n1 = mbSpecs._n1; |
specs->_nz1 = mbSpecs._nz1; |
specs->_n2 = mbSpecs._n2; |
specs->_nz2 = mbSpecs._nz2; |
specs->_character = (wchar_t) mbSpecs._character; |
specs->_pad_char = (wchar_t) mbSpecs._pad_char; |
#endif |
} |
static void SetZeroPad( SPECS __SLIB *specs ) |
{ |
int n; |
if( !(specs->_flags & SPF_LEFT_ADJUST) ) { |
if( specs->_pad_char == '0' ) { |
n = specs->_fld_width - specs->_n0 - specs->_nz0 - |
specs->_n1 - specs->_nz1 - specs->_n2 - specs->_nz2; |
if( n > 0 ) { |
specs->_nz0 += n; |
} |
} |
} |
} |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
static void write_wide_string( FAR_UNI_STRING str, SPECS *specs, |
slib_callback_t *out_putc ) |
{ |
int bytes; |
char mbBuf[MB_CUR_MAX]; |
char *mbBufPtr; |
while( specs->_n1 > 0 ) { |
bytes = wctomb( mbBuf, *str++ ); |
if( bytes != -1 ) { |
if( bytes <= specs->_n1 ) { |
mbBufPtr = mbBuf; |
while( bytes-- ) { |
(out_putc)( specs, *mbBufPtr++ ); |
--specs->_n1; |
} |
} else { |
specs->_n1 = 0; |
} |
} |
} |
} |
#endif |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
static void write_skinny_string( FAR_ASCII_STRING str, SPECS *specs, |
slib_callback_t *out_putc ) |
{ |
int bytes; |
wchar_t wc; |
FAR_ASCII_STRING mbPtr = str; |
char mbBuf[MB_CUR_MAX]; |
while( specs->_n1 > 0 ) { |
mbBuf[0] = *mbPtr++; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = *mbPtr++; |
bytes = mbtowc( &wc, mbBuf, MB_CUR_MAX ); |
if( bytes <= specs->_n1 ) { |
if( bytes != -1 ) { |
(out_putc)( specs, wc ); |
specs->_n1 -= bytes; |
} |
} else { |
specs->_n1 = 0; |
} |
} |
} |
#endif |
static FAR_STRING formstring( CHAR_TYPE *buffer, my_va_list *pargs, |
SPECS __SLIB *specs, CHAR_TYPE *null_string ) |
{ |
FAR_STRING arg; |
int length; |
int radix; |
#if defined( __LONG_LONG_SUPPORT__ ) |
unsigned long long long_long_value; |
#endif |
unsigned long long_value; |
unsigned int int_value; |
#if defined( __FAR_SUPPORT__ ) |
unsigned int seg_value; |
#endif |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
int bytes; |
#endif |
arg = buffer; |
specs->_n0 = specs->_nz0 = |
specs->_n1 = specs->_nz1 = |
specs->_n2 = specs->_nz2 = 0; |
if( ( specs->_character == 'b' ) || |
( specs->_character == 'o' ) || |
( specs->_character == 'u' ) || |
( specs->_character == 'x' ) || |
( specs->_character == 'X' ) ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = va_arg( pargs->v, unsigned long long ); |
} else |
#endif |
if( specs->_flags & SPF_LONG ) { |
long_value = va_arg( pargs->v, unsigned long ); |
} else { |
long_value = va_arg( pargs->v, unsigned ); |
if( specs->_flags & SPF_SHORT ) { /* JBS 92/02/12 */ |
long_value = (unsigned short) long_value; |
} else if( specs->_flags & SPF_CHAR ) { |
long_value = (unsigned char)long_value; |
} |
} |
} else |
if( ( specs->_character == 'd' ) || |
( specs->_character == 'i' ) ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = va_arg( pargs->v, long long ); |
} else |
#endif |
if( specs->_flags & SPF_LONG ) { |
long_value = va_arg( pargs->v, long ); |
} else { |
long_value = va_arg( pargs->v, int ); |
if( specs->_flags & SPF_SHORT ) { /* JBS 92/02/12 */ |
long_value = (short) long_value; |
} else if( specs->_flags & SPF_CHAR ) { |
long_value = (signed char)long_value; |
} |
} |
{ |
int negative = FALSE; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if( (long long)long_long_value < 0 ) { |
negative = TRUE; |
} |
} else |
#endif |
if( (long)long_value < 0 ) { |
negative = TRUE; |
} |
if( negative ) { |
buffer[specs->_n0++] = '-'; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
long_long_value = -long_long_value; |
} else |
#endif |
long_value = - long_value; |
} else if( specs->_flags & SPF_FORCE_SIGN ) { |
buffer[specs->_n0++] = '+'; |
} else if( specs->_flags & SPF_BLANK ) { |
buffer[specs->_n0++] = ' '; |
} |
} |
} |
radix = 10; /* base 10 for 'd', 'i' and 'u' */ |
switch( specs->_character ) { |
case 'f': |
case 'F': |
if( specs->_flags & SPF_SHORT ) { /* "%hf" 13-jun-91 */ |
long_value = va_arg( pargs->v, long ); |
FixedPoint_Format( buffer, long_value, specs ); |
specs->_n1 = far_strlen( buffer, -1 ); |
break; |
} |
/* types f & F fall through */ |
case 'g': |
case 'G': |
case 'e': |
case 'E': |
float_format( buffer, pargs, specs ); |
SetZeroPad( specs ); |
arg++; // = &buffer[1]; |
break; |
case 's': |
#ifndef __NETWARE__ |
case WIDE_CHAR_STRING: |
#else |
case PASCAL_STRING: |
#endif |
// arg has been initialized to point to buffer |
// set buffer[0] to a null character assuming pointer will be NULL |
// If pointer is not null, then arg will be assigned the pointer |
buffer[0] = '\0'; // assume null pointer |
#if defined( __FAR_SUPPORT__ ) |
if( specs->_flags & SPF_FAR ) { |
CHAR_TYPE _WCFAR *temp = va_arg( pargs->v, CHAR_TYPE _WCFAR * ); |
if( temp ) { |
arg = temp; |
} |
} else if( specs->_flags & SPF_NEAR ) { |
CHAR_TYPE _WCNEAR *temp = va_arg( pargs->v, CHAR_TYPE _WCNEAR * ); |
if( temp ) { |
arg = (void *)temp; |
} |
} else { |
CHAR_TYPE *temp = va_arg( pargs->v, CHAR_TYPE * ); |
if( temp ) { |
arg = temp; |
} |
} |
#else |
{ |
CHAR_TYPE *temp = va_arg( pargs->v, CHAR_TYPE * ); |
if( temp ) { |
arg = temp; |
} |
} |
#endif |
#ifdef __NETWARE__ |
if( specs->_character == PASCAL_STRING ) { |
#ifdef __WIDECHAR__ |
if( specs->_flags & SPF_SHORT ) |
#else |
if( specs->_flags & SPF_LONG ) |
#endif |
{ |
length = *( (_FAR_OTHER_STRING)arg ); |
arg = (FAR_STRING)( (_FAR_OTHER_STRING)arg + 1 ); |
} else { |
length = *arg++; |
} |
} else |
#elif !defined( __NETWARE__ ) && !defined( __WIDECHAR__ ) |
if( specs->_character == WIDE_CHAR_STRING ) { |
if( specs->_flags & SPF_SHORT ) { |
length = far_strlen( arg, specs->_prec ); |
} else { |
length = far_other_strlen( arg, specs->_prec ); |
} |
} else |
#endif |
#ifdef __WIDECHAR__ |
if( specs->_flags & SPF_SHORT ) { |
#else |
if( specs->_flags & SPF_LONG ) { |
#endif |
length = far_other_strlen( arg, specs->_prec ); |
} else { |
length = far_strlen( arg, specs->_prec ); |
} |
specs->_n1 = length; |
if(( specs->_prec >= 0 ) && ( specs->_prec < length )) { |
specs->_n1 = specs->_prec; |
} |
break; |
case 'x': |
case 'X': |
if( specs->_flags & SPF_ALT ) { |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if( long_long_value != 0 ) { |
buffer[specs->_n0++] = '0'; |
buffer[specs->_n0++] = specs->_character; |
} |
} else |
#endif |
if( long_value != 0 ) { |
buffer[specs->_n0++] = '0'; |
buffer[specs->_n0++] = specs->_character; |
} |
} |
radix = 16; /* base 16 */ |
goto processNumericTypes; |
case 'b': /* CDH 2003 Apr 23 *//* Add binary mode */ |
radix = 2; /* base 2 */ |
goto processNumericTypes; |
case 'o': |
radix = 8; /* base 8 */ |
/* 'o' conversion falls through */ |
case 'd': |
case 'i': |
case 'u': |
// 'x' and 'X' jumps here |
processNumericTypes: |
if( specs->_prec != -1 ) |
specs->_pad_char = ' '; /* 30-jul-95, 11-may-99 */ |
/* radix contains the base; 8 for 'o', 10 for 'd' and 'i' and 'u', |
16 for 'x' and 'X', and 2 for 'b' */ |
arg = &buffer[ specs->_n0 ]; |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->_flags & SPF_LONG_LONG ) { |
if(( specs->_prec == 0 ) && ( long_long_value == 0 )) { |
*arg = '\0'; |
length = 0; |
} else { |
__F_NAME(ulltoa,_ulltow)( long_long_value, &buffer[specs->_n0], radix ); |
if( specs->_character == 'X' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
length = far_strlen( arg, -1 ); |
} |
} else |
#endif |
if(( specs->_prec == 0 ) && ( long_value == 0 )) { |
*arg = '\0'; |
length = 0; |
} else { |
__F_NAME(ultoa,_ultow)( long_value, &buffer[specs->_n0], radix ); |
if( specs->_character == 'X' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
length = far_strlen( arg, -1 ); |
} |
specs->_n1 = length; |
if( specs->_n1 < specs->_prec ) { |
specs->_nz0 = specs->_prec - specs->_n1; |
} else if( specs->_flags & SPF_ALT && radix < 10 |
&& (!length || (arg[0] != '0')) ) { |
/* For 'b' and 'o' conversions, alternate format forces the number to |
* start with a zero (effectively increases precision by one), but |
* only if it doesn't start with a zero already. |
*/ |
++specs->_nz0; |
} |
if( specs->_prec == -1 ) { |
SetZeroPad( specs ); |
} |
break; |
case 'p': |
case 'P': |
#if defined( __FAR_SUPPORT__ ) |
#if defined( __BIG_DATA__ ) |
if( !( specs->_flags & (SPF_NEAR|SPF_FAR) ) ) { |
specs->_flags |= SPF_FAR; |
} |
if( specs->_fld_width == 0 ) { |
if( specs->_flags & SPF_NEAR ) { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} else { |
specs->_fld_width = sizeof( CHAR_TYPE _WCFAR * ) * 2 + 1; |
} |
} |
#else |
if( specs->_fld_width == 0 ) { |
if( specs->_flags & SPF_FAR ) { |
specs->_fld_width = sizeof( CHAR_TYPE _WCFAR * ) * 2 + 1; |
} else { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} |
} |
#endif |
#else |
if( specs->_fld_width == 0 ) { |
specs->_fld_width = sizeof( unsigned ) * 2; |
} |
#endif |
specs->_flags &= ~( SPF_BLANK | SPF_FORCE_SIGN ); |
int_value = va_arg( pargs->v, unsigned ); /* offset */ |
#if defined( __FAR_SUPPORT__ ) |
if( specs->_flags & SPF_FAR ) { |
seg_value = va_arg( pargs->v, unsigned ) & 0xFFFF; /* segment */ |
/* use "unsigned short" for 386 instead of "unsigned" 21-jul-89 */ |
fmt4hex( seg_value, buffer, sizeof( unsigned short ) * 2 ); |
buffer[sizeof(unsigned short)*2] = ':'; |
fmt4hex( int_value, buffer + sizeof( unsigned short ) * 2 + 1, |
sizeof( unsigned ) * 2 ); |
} else { |
fmt4hex( int_value, buffer, sizeof( unsigned ) * 2 ); |
} |
#else |
fmt4hex( int_value, buffer, sizeof( unsigned ) * 2 ); |
#endif |
if( specs->_character == 'P' ) { |
__F_NAME(strupr,_wcsupr)( buffer ); |
} |
specs->_n0 = far_strlen( arg, -1 ); |
break; |
case 'c': |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs->_flags & SPF_SHORT ) { |
char * mbPtr; |
char mbBuf[MB_CUR_MAX]; |
wchar_t wc; |
mbPtr = va_arg( pargs->v, char* ); |
mbBuf[0] = mbPtr[0]; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = mbPtr[1]; |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
buffer[0] = wc; |
} |
} else { |
buffer[0] = va_arg( pargs->v, int ); |
} |
specs->_n0 = 1; |
#elif !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
specs->_n0 = 1; |
if( specs->_flags & SPF_LONG ) { |
char mbBuf[MB_CUR_MAX]; |
wchar_t wc; |
wc = va_arg( pargs->v, int ); |
if( wctomb( mbBuf, wc ) != -1 ) { |
buffer[0] = mbBuf[0]; |
if( _ismbblead( mbBuf[0] ) ) { |
buffer[1] = mbBuf[1]; |
specs->_n0++; |
} |
} |
} else { |
buffer[0] = va_arg( pargs->v, int ); |
} |
#else |
specs->_n0 = 1; |
buffer[0] = va_arg( pargs->v, int ); |
#endif |
break; |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
case 'C': |
bytes = wctomb( buffer, va_arg( pargs->v, int ) ); |
// if( bytes != -1 && bytes <= specs->_prec ) { |
if( bytes != -1 ) { /* Normative Addendum 4.5.3.3.1: no precision */ |
specs->_n0 = bytes; |
} else { |
specs->_n0 = 0; |
} |
break; |
#endif |
default: |
specs->_fld_width = 0; |
buffer[ 0 ] = specs->_character; |
specs->_n0 = 1; |
break; |
} |
return( arg ); |
} |
/programs/develop/open watcom/trunk/clib/src/scnf.c |
---|
0,0 → 1,1116 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Platform independent worker routines for scanf(). |
* |
****************************************************************************/ |
#define __LONG_LONG_SUPPORT__ |
#if !defined( __NETWARE__ ) && !defined( __UNIX__ ) |
#define USE_MBCS_TRANSLATION |
#endif |
#include "variety.h" |
#ifdef SAFE_SCANF |
#include "saferlib.h" |
#endif |
#include "widechar.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#ifdef __WIDECHAR__ |
#include <wctype.h> |
#else |
#include <ctype.h> |
#endif |
#include <stdarg.h> |
#include "scanf.h" |
#include "prtscncf.h" |
#include "fixpoint.h" |
#include "ftos.h" |
#include "farsupp.h" |
#include "myvalist.h" |
#if defined( __WIDECHAR__ ) || defined( USE_MBCS_TRANSLATION ) |
#include <mbstring.h> |
#endif |
#define TRUE 1 |
#define FALSE 0 |
#define STOP_CHR 0xFFFFFFFF |
#define EFG_SCANF (*__EFG_scanf) |
/* internal file/string get, unget routines */ |
#ifdef __WINDOWS_386__ |
#ifdef __SW_3S |
#pragma aux cget modify [eax edx ecx fs gs] |
#pragma aux uncget modify [eax edx ecx fs gs] |
#else |
#pragma aux cget modify [fs gs] |
#pragma aux uncget modify [fs gs] |
#endif |
#endif |
#if defined(__HUGE__) |
#define SCNF_FAR _WCFAR |
#else |
#define SCNF_FAR |
#endif |
/* Macros to reduce the already large number of ifdefs in the code */ |
#ifdef SAFE_SCANF |
#define GET_MAXELEM(x) x = va_arg( arg->v, size_t ) |
#define DEFINE_VARS(x,y) size_t x, y = 0 |
#define CHECK_ELEMS(x,y,z) if( x < ++y ) return( z ) |
#else |
#define GET_MAXELEM(x) |
#define DEFINE_VARS(x,y) |
#define CHECK_ELEMS(x,y,z) |
#endif |
static int cget( PTR_SCNF_SPECS specs ) |
{ |
return( (*((specs)->cget_rtn))( specs ) ); |
} |
static void uncget( int c, PTR_SCNF_SPECS specs ) |
{ |
((*((specs)->uncget_rtn))( c, specs )); |
} |
/* |
* get_opt -- get option string for current conversion directive |
* and fills in the SCNF_SPECS structure. |
* returns advanced format string pointer. |
*/ |
static const CHAR_TYPE *get_opt( const CHAR_TYPE *opt_str, PTR_SCNF_SPECS specs ) |
{ |
int c, width; |
specs->assign = TRUE; |
specs->far_ptr = 0; |
specs->near_ptr = 0; |
specs->char_var = 0; |
specs->short_var = 0; |
specs->long_var = 0; |
specs->long_long_var = 0; |
specs->long_double_var = 0; |
specs->p_format = 0; /* 21-nov-89 */ |
specs->width = -1; |
if( *opt_str == '*' ) { |
specs->assign = FALSE; |
++opt_str; |
} |
c = *opt_str; |
if( __F_NAME(isdigit,iswdigit)( c ) ) { |
width = 0; |
do { |
width *= 10; |
width += ( c - '0' ); |
c = *++opt_str; |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
specs->width = width; |
} |
switch( *opt_str ) { |
case 'N': |
specs->near_ptr = 1; |
++opt_str; |
break; |
#if defined( __FAR_SUPPORT__ ) |
case 'F': /* conflicts with ISO-defined 'F' conversion */ |
/* fall through */ |
#endif |
case 'W': |
specs->far_ptr = 1; |
++opt_str; |
break; |
} |
switch( *opt_str ) { |
case 'h': |
if( opt_str[1] == 'h' ) { |
specs->char_var = 1; |
opt_str += 2; |
break; |
} |
specs->short_var = 1; |
++opt_str; |
break; |
case 'l': |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( opt_str[1] == 'l' ) { |
specs->long_long_var = 1; |
opt_str += 2; |
break; |
} |
#endif |
/* fall through */ |
ZSPEC_CASE_LONG |
TSPEC_CASE_LONG |
case 'w': |
specs->long_var = 1; |
++opt_str; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
JSPEC_CASE_LLONG |
/* fall through */ |
#endif |
case 'L': |
specs->long_double_var = 1; |
specs->long_long_var = 1; |
++opt_str; |
break; |
#if defined( __LONG_LONG_SUPPORT__ ) |
case 'I': |
if( opt_str[1] == '6' && opt_str[2] == '4' ) { |
specs->long_long_var = 1; |
opt_str += 3; |
} |
break; |
#endif |
#if defined( TSPEC_IS_INT ) || defined( ZSPEC_IS_INT ) |
TSPEC_CASE_INT /* If either 't' or 'z' spec corresponds to 'int', */ |
ZSPEC_CASE_INT /* we need to parse and ignore the spec. */ |
++opt_str; |
break; |
#endif |
} |
return( opt_str ); |
} |
/* |
* scan_white -- scan white space from input stream |
*/ |
static int scan_white( PTR_SCNF_SPECS specs ) |
{ |
int c, len; |
len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++len; |
} |
if( !specs->eoinp ) |
uncget( c, specs ); |
return( len ); |
} |
/* |
* scan_char -- handles %c and %C |
*/ |
static int scan_char( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
int len; |
int width; |
FAR_STRING str; |
int c; |
DEFINE_VARS( maxelem, nelem ); |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCNEAR * ); |
} else { |
str = va_arg( arg->v, CHAR_TYPE * ); |
} |
#else |
str = va_arg( arg->v, CHAR_TYPE * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
if( (width = specs->width) == -1 ) |
width = 1; |
while( width > 0 ) { |
c = cget( specs ); |
if( specs->eoinp ) |
break; |
++len; |
--width; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
if( specs->short_var ) { |
char mbBuf[MB_CUR_MAX]; |
if( wctomb( mbBuf, c ) != -1 ) { |
*(FAR_ASCII_STRING)str = mbBuf[0]; |
str = (FAR_STRING) ( (FAR_ASCII_STRING)str + 1 ); |
if( _ismbblead( mbBuf[0] ) ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*(FAR_ASCII_STRING)str = mbBuf[1]; |
str = (FAR_STRING) ( (FAR_ASCII_STRING)str + 1 ); |
} |
} else { |
return( 0 ); |
} |
} else { |
*str++ = c; |
} |
#elif defined( USE_MBCS_TRANSLATION ) |
if( specs->long_var ) { |
wchar_t wc; |
char mbBuf[MB_CUR_MAX]; |
mbBuf[0] = c; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = cget( specs ); |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
*(FAR_UNI_STRING)str = wc; |
str = (FAR_STRING) ( (FAR_UNI_STRING)str + 1 ); |
} else { |
return( 0 ); |
} |
} else { |
*str++ = c; |
} |
#else |
*str++ = c; |
#endif |
} |
} |
return( len ); |
} |
/* |
* cgetw -- cget which keeps track of field width. |
* returns STOP_CHR on end of field or end of file. |
*/ |
static long cgetw( PTR_SCNF_SPECS specs ) |
{ |
int c; |
if( specs->width-- == 0 ) |
return( STOP_CHR ); |
c = cget( specs ); |
return( !( specs->eoinp ) ? c : STOP_CHR ); |
} |
/* |
* scan_string -- handles %s and %S |
*/ |
static int scan_string( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
int c; |
int len; |
FAR_ASCII_STRING str; |
char chsize; |
DEFINE_VARS( maxelem, nelem ); |
if( specs->long_var ) { /* %ls or %ws */ |
chsize = sizeof( wchar_t ); |
} else if( specs->short_var ) { /* %hs */ |
chsize = 1; |
} else { /* %s */ |
chsize = CHARSIZE; |
} |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, char _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, char _WCNEAR * ); |
} else { |
str = va_arg( arg->v, char * ); |
} |
#else |
str = va_arg( arg->v, char * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++len; |
} |
if( specs->eoinp ) { |
len = 0; /* since this is eof, no input done */ |
goto done; |
} |
if( specs->width-- == 0 ) |
goto ugdone; |
do { |
++len; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
if( chsize == 1 ) { |
#if defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
char mbBuf[MB_CUR_MAX]; |
if( wctomb( mbBuf, c ) != -1 ) { |
*(FAR_ASCII_STRING)str = mbBuf[0]; |
if( _ismbblead( mbBuf[0] ) ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
str++; |
*(FAR_ASCII_STRING)str = mbBuf[1]; |
} |
} else { |
return( 0 ); |
} |
#else |
*str = c; |
#endif |
} else { |
#if !defined( __WIDECHAR__ ) && defined( USE_MBCS_TRANSLATION ) |
wchar_t wc; |
char mbBuf[MB_CUR_MAX]; |
mbBuf[0] = c; |
if( _ismbblead( mbBuf[0] ) ) |
mbBuf[1] = cget( specs ); |
if( mbtowc( &wc, mbBuf, MB_CUR_MAX ) != -1 ) { |
*(FAR_UNI_STRING)str = wc; |
} else { |
return( 0 ); |
} |
#else |
*(FAR_UNI_STRING)str = c; |
#endif |
} |
str += chsize; |
} |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( !__F_NAME(isspace,iswspace)( c ) ); |
ugdone: |
uncget( c, specs ); |
done: |
if( specs->assign && len > 0 ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
if( chsize == 1 ) { |
*str = '\0'; |
} else { |
*(FAR_UNI_STRING)str = 0; |
} |
} |
return( len ); |
} |
/* |
* report_scan -- handles %n |
*/ |
static void report_scan( PTR_SCNF_SPECS specs, my_va_list *arg, int match ) |
{ |
FAR_INT iptr; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
iptr = va_arg( arg->v, int _WCFAR * ); |
} else if( specs->near_ptr ) { |
iptr = va_arg( arg->v, int _WCNEAR * ); |
} else { |
iptr = va_arg( arg->v, int * ); |
} |
#else |
iptr = va_arg( arg->v, int * ); |
#endif |
if( specs->char_var ) { |
*((FAR_CHAR)iptr) = match; |
} else if( specs->short_var ) { |
*((FAR_SHORT)iptr) = match; |
} else if( specs->long_var ) { |
*((FAR_LONG)iptr) = match; |
#if defined( __LONG_LONG_SUPPORT__ ) |
} else if( specs->long_long_var ) { |
*((FAR_INT64)iptr) = match; |
#endif |
} else { |
*iptr = match; |
} |
} |
} |
#if !defined( __WIDECHAR__ ) |
#define SCANSET_LENGTH (256 / 8) |
static const char lst_mask[8] = { |
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 |
}; |
/* |
* makelist -- create scanset for %[ directive. |
* scanset is stored as 256 bit flags in a 32 byte array. |
*/ |
static const char *makelist( const char *format, char *scanset ) |
{ |
int lst_chr; |
memset( scanset, 0, SCANSET_LENGTH ); |
if( (lst_chr = *format++) == '\0' ) |
return( format ); |
do { |
scanset[lst_chr >> 3] |= lst_mask[lst_chr & 0x07]; |
if( (lst_chr = *format) == '\0' ) |
break; |
++format; |
} while( lst_chr != ']' ); |
return( format ); |
} |
#endif |
/* |
* scan_arb -- handles %[ |
*/ |
static int scan_arb( PTR_SCNF_SPECS specs, my_va_list *arg, const CHAR_TYPE **format ) |
{ |
unsigned width; |
FAR_STRING str; |
int len, c, not_flag; |
#if defined( __WIDECHAR__ ) |
const CHAR_TYPE *list; |
CHAR_TYPE ch; |
char in_list; |
#else |
char scanset[SCANSET_LENGTH]; |
#endif |
DEFINE_VARS( maxelem, nelem ); |
if( not_flag = (**format == '^') ) { |
++(*format); |
} |
#if !defined( __WIDECHAR__ ) |
*format = makelist( *format, scanset ); |
#endif |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
str = va_arg( arg->v, CHAR_TYPE _WCNEAR * ); |
} else { |
str = va_arg( arg->v, CHAR_TYPE * ); |
} |
#else |
str = va_arg( arg->v, CHAR_TYPE * ); |
#endif |
GET_MAXELEM( maxelem ); |
} |
len = 0; |
width = specs->width; |
while( width > 0 ) { |
c = cget( specs ); |
if( specs->eoinp ) |
break; |
#if defined( __WIDECHAR__ ) |
list = *format; |
ch = *list; |
in_list = TRUE; |
while( c != ch ) { |
list++; |
ch = *list; |
if( ch == ']' ) { |
in_list = FALSE; |
break; |
} |
} |
if( in_list == not_flag ) { |
uncget( c, specs ); |
break; |
} |
#else |
if( ((scanset[c >> 3] & lst_mask[c & 0x07]) == 0) != not_flag ) { |
uncget( c, specs ); |
break; |
} |
#endif |
++len; |
--width; |
if( specs->assign ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*str++ = c; |
} |
} |
if( specs->assign && len > 0 ) { |
CHECK_ELEMS( maxelem, nelem, -1 ); |
*str = '\0'; |
} |
#if defined( __WIDECHAR__ ) |
while( *(*format)++ != ']' ) /* skip past format specifier */ |
; |
#endif |
return( len ); |
} |
/* |
* scan_float -- handles floating point numerical conversion |
* *** should implement buffer overflow protection *** |
*/ |
static int scan_float( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
double value; |
char *num_str, buf[80]; |
int len; |
int pref_len; |
long c; |
int digit_found; |
FAR_FLOAT fptr; |
char *p; |
T32 at; |
T32 ft; |
num_str = buf; |
pref_len = len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++pref_len; |
} |
if( specs->eoinp ) |
goto done; |
if( specs->width-- == 0 ) |
goto ugdone; |
if( c == '+' || c == '-' ) { |
*num_str++ = c; |
++pref_len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( !__F_NAME(isdigit,iswdigit)( c ) && c != '.' ) |
goto ugdone; |
at.uWhole = 0; |
digit_found = FALSE; |
if( __F_NAME(isdigit,iswdigit)( c ) ) { |
digit_found = TRUE; |
do { |
*num_str++ = c; |
if( specs->short_var ) |
at.wd.hi = at.wd.hi * 10 + c - '0'; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
} |
if( c == '.' ) { |
*num_str++ = c; |
++len; /* account for the '.' */ |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( !digit_found && !__F_NAME(isdigit,iswdigit)(c) ) |
goto ugdone; |
while( __F_NAME(isdigit,iswdigit)( c ) ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
break; |
} |
} |
if( specs->short_var ) { /* %hf fixed-point format 05-feb-92 */ |
ft.uWhole = 0; |
p = num_str; |
for( ;; ) { |
--p; |
if( *p == '.' ) |
break; |
ft.bite.b3 = *p - '0'; |
ft.uWhole = ft.uWhole / 10; |
} |
at.wd.lo = ft.wd.lo; |
} |
if( c == STOP_CHR ) { |
goto done; |
} |
} |
if( specs->short_var == 0 && (c == 'e' || c == 'E') ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == '+' || c == '-' ) { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( !__F_NAME(isdigit,iswdigit)( c ) ) { |
len = 0; /* fast way to flag error */ |
} else { |
do { |
*num_str++ = c; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} while( __F_NAME(isdigit,iswdigit)( c ) ); |
} |
} |
ugdone: |
uncget( (int)c, specs ); |
done: |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
*num_str = NULLCHAR; |
if( specs->short_var ) { |
if( buf[0] == '-' ) { |
at.sWhole = - at.sWhole; |
} |
} else { |
EFG_SCANF( buf, (void *)&value ); /* 27-mar-90 */ |
} |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
fptr = va_arg( arg->v, float _WCFAR * ); |
} else if( specs->near_ptr ) { |
fptr = va_arg( arg->v, float _WCNEAR * ); |
} else { |
fptr = va_arg( arg->v, float * ); |
} |
#else |
fptr = va_arg( arg->v, float * ); |
#endif |
if( specs->short_var ) { /* 05-feb-92 */ |
*((FAR_LONG) fptr) = at.uWhole; |
} else if( specs->long_var || specs->long_double_var ) { |
*((FAR_DOUBLE) fptr) = value; |
} else { |
*fptr = value; |
} |
} |
} |
return( len ); |
} |
static int radix_value( int c ) |
{ |
if( c >= '0' && c <= '9' ) |
return( c - '0' ); |
c = __F_NAME(tolower,towlower)( c ); |
if( c >= 'a' && c <= 'f' ) |
return( c - 'a' + 10 ); |
return( 16 ); |
} |
/* |
* scan_int -- handles integer numeric conversion |
*/ |
static int scan_int( PTR_SCNF_SPECS specs, my_va_list *arg, int base, int sign_flag ) |
{ |
long value; |
int len; |
int pref_len; |
int c; |
int sign; |
int digit; |
FAR_INT iptr; |
#if defined( __LONG_LONG_SUPPORT__ ) |
unsigned long long long_value; |
FAR_INT64 llptr; |
long_value = 0; |
#endif |
value = 0; |
pref_len = len = 0; |
for( ;; ) { |
c = cget( specs ); |
if( !__F_NAME(isspace,iswspace)( c ) ) |
break; |
++pref_len; |
} |
if( specs->eoinp ) |
goto done; |
if( specs->width-- == 0 ) |
goto ugdone; |
sign = '+'; |
if( sign_flag && (c == '+' || c == '-') ) { |
sign = c; |
++pref_len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( base == 0 ) { |
if( c == '0' ) { |
len = 1; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == 'x' || c == 'X' ) { |
len = 0; |
++pref_len; /* for the '0' */ |
++pref_len; /* for the 'x' */ |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
base = 16; |
} else { |
base = 8; |
} |
} else { |
base = 10; |
} |
} else if( base == 16 ) { |
if( c == '0' ) { |
len = 1; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
if( c == 'x' || c == 'X' ) { |
len = 0; |
++pref_len; /* for the '0' */ |
++pref_len; /* for the 'x' */ |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
} |
} |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->long_long_var ) { |
for( ;; ) { |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
long_value = long_value * base + digit; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( c == ':' && specs->p_format ) { |
for( ;; ) { |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
long_value = long_value * base + digit; |
} |
} |
} else |
#endif |
{ |
for( ;; ) { |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
value = value * base + digit; |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) { |
goto done; |
} |
} |
if( c == ':' && specs->p_format ) { |
for( ;; ) { |
++len; |
if( (c = cgetw( specs )) == STOP_CHR ) |
goto done; |
digit = radix_value( c ); |
if( digit >= base ) |
break; |
value = value * base + digit; |
} |
} |
} |
ugdone: |
uncget( c, specs ); |
done: |
#if defined( __LONG_LONG_SUPPORT__ ) |
if( specs->long_long_var ) { |
if( sign == '-' ) { |
long_value =- long_value; |
} |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
llptr = va_arg( arg->v, unsigned long long _WCFAR * ); |
} else if( specs->near_ptr ) { |
llptr = va_arg( arg->v, unsigned long long _WCNEAR * ); |
} else { |
llptr = va_arg( arg->v, unsigned long long * ); |
} |
#else |
llptr = va_arg( arg->v, unsigned long long * ); |
#endif |
*llptr = long_value; |
} |
} |
} else |
#endif |
{ |
if( sign == '-' ) { |
value = -value; |
} |
if( len > 0 ) { |
len += pref_len; |
if( specs->assign ) { |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
iptr = va_arg( arg->v, int _WCFAR * ); |
} else if( specs->near_ptr ) { |
iptr = va_arg( arg->v, int _WCNEAR * ); |
} else { |
iptr = va_arg( arg->v, int * ); |
} |
#else |
iptr = va_arg( arg->v, int * ); |
#endif |
if( specs->char_var ) { |
*((FAR_CHAR)iptr) = value; |
} else if( specs->short_var ) { |
*((FAR_SHORT)iptr) = value; |
} else if( specs->long_var ) { |
*((FAR_LONG)iptr) = value; |
} else { |
*iptr = value; |
} |
} |
} |
} |
return( len ); |
} |
#ifdef SAFE_SCANF |
/* |
* null_arg -- check for a null pointer passed in arguments |
*/ |
static int null_arg( PTR_SCNF_SPECS specs, my_va_list *arg ) |
{ |
FAR_STRING str = NULL; |
va_list args_copy; |
va_copy( args_copy, arg->v ); |
#if defined( __FAR_SUPPORT__ ) |
if( specs->far_ptr ) { |
str = va_arg( args_copy, CHAR_TYPE _WCFAR * ); |
} else if( specs->near_ptr ) { |
CHAR_TYPE _WCNEAR *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE _WCNEAR * ); |
/* The following should work: |
* |
* str = (ptr == NULL) ? (void _WCFAR *)NULL : ptr; |
* |
* but doesn't due to a bug in C compiler introduced in |
* 11.0 and fixe in OW 1.4. Ternary operator may be used |
* when building with OW 1.5. See also similar code in prtf.c. |
*/ |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} else { |
CHAR_TYPE *ptr; |
ptr = va_arg( args_copy, CHAR_TYPE * ); |
if( ptr == NULL ) { |
str = NULL; |
} else { |
str = ptr; |
} |
} |
#else |
str = va_arg( args_copy, CHAR_TYPE * ); |
#endif |
va_end( args_copy ); |
return( str == NULL ? 1 : 0 ); |
} |
#endif |
#ifdef SAFE_SCANF |
int __F_NAME(__scnf_s,__wscnf_s)( PTR_SCNF_SPECS specs, const CHAR_TYPE *format, const char **msg, va_list args ) |
#else |
int __F_NAME(__scnf,__wscnf)( PTR_SCNF_SPECS specs, const CHAR_TYPE *format, va_list args ) |
#endif |
{ |
int char_match; |
int items_converted; |
int items_assigned; |
int match_len; |
int c; |
int fmt_chr; |
my_va_list margs; |
margs = MY_VA_LIST( args ); |
char_match = items_assigned = items_converted = 0; |
specs->eoinp = 0; |
while( (fmt_chr = *format++) != NULLCHAR ) { |
if( __F_NAME(isspace,iswspace)( fmt_chr ) ) { |
char_match += scan_white( specs ); |
} else if( fmt_chr != '%' ) { |
if( (c = cget( specs )) != fmt_chr ) { |
if( !specs->eoinp ) |
uncget( c, specs ); |
break; |
} |
++char_match; /* 27-oct-88 */ |
} else { /* fmt_chr == '%' */ |
format = get_opt( format, specs ); |
if( (fmt_chr = *format) != NULLCHAR ) |
++format; |
#ifdef SAFE_SCANF |
if( fmt_chr != '%' ) { |
/* The '%' specifier is the only one not expecting pointer arg */ |
if( specs->assign && null_arg( specs, &margs ) ) { |
*msg = "%ptr -> NULL"; |
return( __F_NAME(EOF,WEOF) ); |
} |
} |
#endif |
switch( fmt_chr ) { |
case 'd': |
match_len = scan_int( specs, &margs, 10, TRUE ); |
goto check_match; |
case 'i': |
match_len = scan_int( specs, &margs, 0, TRUE ); |
goto check_match; |
case 'o': |
match_len = scan_int( specs, &margs, 8, TRUE ); |
goto check_match; |
case 'u': |
match_len = scan_int( specs, &margs, 10, TRUE ); |
goto check_match; |
case 'p': |
#if defined( __BIG_DATA__ ) |
specs->long_var = 1; /* indicate far pointer */ |
specs->p_format = 1; /* ... */ |
#endif |
// fall through |
case 'x': |
case 'X': |
match_len = scan_int( specs, &margs, 16, TRUE ); |
goto check_match; |
case 'e': |
case 'E': |
case 'f': |
case 'F': |
case 'g': |
case 'G': |
match_len = scan_float( specs, &margs ); |
goto check_match; |
#if !defined(__WIDECHAR__) && !defined(__NETWARE__) |
case 'S': |
specs->long_var = 1; |
/* fall through to %s handler */ |
#endif |
case 's': |
match_len = scan_string( specs, &margs ); |
goto check_match; |
case '[': |
match_len = scan_arb( specs, &margs, &format ); |
goto check_match; |
#if !defined(__WIDECHAR__) && !defined(__NETWARE__) |
case 'C': |
specs->long_var = 1; |
/* fall through to %c handler */ |
#endif |
case 'c': |
match_len = scan_char( specs, &margs ); |
check_match: |
if( match_len > 0 ) { |
char_match += match_len; |
++items_converted; |
if( specs->assign ) { |
++items_assigned; |
} |
} else { |
#ifdef SAFE_SCANF |
if( match_len < 0 ) { |
/* Matching failure caused by insufficient space in output |
* is not input failure, hence we won't return EOF regardless |
* of specs->eoinp state. |
*/ |
++items_converted; |
} |
#endif |
goto fail; |
} |
break; |
case 'n': |
report_scan( specs, &margs, char_match ); |
break; |
case '%': |
if( (c = cget( specs )) != '%' ) { |
if( !specs->eoinp ) |
uncget( c, specs ); |
goto fail; |
} else { |
char_match += 1; |
} |
break; |
} |
} |
if( specs->eoinp ) { |
while( *format == '%' ) { |
++format; |
format = get_opt( format, specs ); |
if( *format == 'n' ) { |
++format; |
#ifdef SAFE_SCANF |
if( specs->assign && null_arg( specs, &margs ) ) { |
*msg = "%ptr -> NULL"; |
return( __F_NAME(EOF,WEOF) ); |
} |
#endif |
report_scan( specs, &margs, char_match ); |
} else { |
break; |
} |
} |
break; |
} |
} |
fail: |
if( items_converted == 0 && specs->eoinp ) |
return( __F_NAME(EOF,WEOF) ); |
return( items_assigned ); |
} |
/programs/develop/open watcom/trunk/clib/src/setefg.c |
---|
0,0 → 1,48 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Routine to bring in real floating-point formatting code. |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include "ftos.h" |
#include "farsupp.h" |
/* This routine will be called by cstart if "_fltused" is referenced. */ |
void __setEFGfmt( void ) |
{ |
#ifdef __SW_BR |
__EFG_printf = __get_EFG_Format(); |
__EFG_scanf = __get__cnvs2d(); /* 27-mar-90 */ |
#else |
__EFG_printf = _EFG_Format; |
__EFG_scanf = __cnvs2d; /* 27-mar-90 */ |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/seterrno.c |
---|
0,0 → 1,76 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: Implementation of __set_errno(). |
* |
****************************************************************************/ |
#ifdef __WATCOMC__ |
#include "variety.h" |
#include <stdlib.h> |
#include <errno.h> |
#include "rtdata.h" |
#include "seterrno.h" |
_WCRTLINK void __set_errno( unsigned int err ) |
{ |
_RWD_errno = err; |
} |
_WCRTLINK void __set_EDOM() |
{ |
__set_errno( EDOM ); |
} |
_WCRTLINK void __set_ERANGE() |
{ |
__set_errno( ERANGE ); |
} |
_WCRTLINK int __set_EINVAL() |
{ |
__set_errno( EINVAL ); |
return( -1 ); |
} |
//#if !defined(__UNIX__) && !defined(__NETWARE__) |
//_WCRTLINK void __set_doserrno( unsigned int err ) |
//{ |
// _RWD_doserrno = err; |
//} |
//#endif |
#else |
#include <errno.h> |
void __set_errno( unsigned int err ) |
{ |
errno = err; |
} |
#endif |
/programs/develop/open watcom/trunk/clib/src/stiomode.c |
---|
0,0 → 1,175 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <stdio.h> |
#include <unistd.h> |
#include <string.h> |
#include <errno.h> |
#include "rtdata.h" |
#include "liballoc.h" |
#include "fileacc.h" |
#include "rtinit.h" |
#include "seterrno.h" |
#include "iomode.h" |
#include "handleio.h" |
#ifdef DLHEAP |
void* _cdecl dlmalloc(size_t); |
void _cdecl dlfree(void*); |
void _cdecl mf_init(); |
#define malloc dlmalloc |
#define free dlfree |
#define realloc dlrealloc |
#define lib_malloc dlmalloc |
#define lib_free dlfree |
#define lib_realloc dlrealloc |
#endif |
#if defined(__NETWARE__) |
#error NO IO MODE MANAGER UNDER NETWARE |
#endif |
extern unsigned _HUGEDATA __init_mode[_NFILES]; |
extern unsigned __NFiles; /* maximum # of files we can open */ |
static unsigned _init_NFiles; // original __NFiles value; |
void __grow_iomode( int num ) |
{ |
unsigned *new; |
_AccessIOB(); |
if( __io_mode == __init_mode ) |
{ |
_init_NFiles = __NFiles; |
new = (unsigned *) lib_malloc( num * sizeof( unsigned ) ); |
if( new != NULL ) { |
memcpy( new, __init_mode, __NFiles * sizeof(unsigned) ); |
} |
} |
else |
{ |
#if defined(__NETWARE__) |
#else |
new = (unsigned *) lib_realloc( __io_mode, num * sizeof( unsigned ) ); |
#endif |
} |
if( new == NULL ) |
{ |
__set_errno( ENOMEM ); |
} |
else |
{ |
memset( &new[__NFiles], 0, (num-__NFiles)*sizeof(unsigned) ); |
__io_mode = new; |
__NFiles = num; |
} |
_ReleaseIOB(); |
} |
void __shrink_iomode( void ) |
{ |
_AccessIOB(); |
// free any malloc'd iomode array |
if( __io_mode != __init_mode ) |
{ |
lib_free( __io_mode ); |
__io_mode = __init_mode; |
__NFiles = _init_NFiles; |
} |
_ReleaseIOB(); |
} |
AYI(__shrink_iomode,INIT_PRIORITY_IOSTREAM); |
#if defined(__WARP__) |
extern unsigned __NHandles; |
static void __preinit_iomode_os2(void) |
{ |
LONG req_count; |
ULONG curr_max_fh; |
APIRET rc; |
// Ensure that the clib and OS file handle limits match |
req_count = 0; |
rc = DosSetRelMaxFH( &req_count, &curr_max_fh ); |
if( rc == 0 ) { |
__grow_iomode( curr_max_fh ); |
__NHandles = curr_max_fh; // same as __set_handles |
} |
} |
AXI( __preinit_iomode_os2, INIT_PRIORITY_RUNTIME ); |
#endif |
#define _INITIALIZED _DYNAMIC |
signed __SetIOMode( int handle, unsigned value ) |
{ |
int i; |
if( handle >= __NFiles ) |
{ |
i = __NFiles; // 20 -> (20+10+1) -> 31 |
// 31 -> (31+15+1) -> 47 |
// 47 -> (47+23+1) -> 71 |
__grow_iomode( i + (i > 1) + 1 ); |
} |
if( handle >= __NFiles ) |
{ |
// return an error indication (errno should be set to ENOMEM) |
return( -1 ); |
} |
else |
{ |
if( value != 0 ) |
{ |
__ChkTTYIOMode( handle ); |
__io_mode[handle] = value | _INITIALIZED; |
} |
else |
{ |
__io_mode[handle] = value; /* we're closing it; smite _INITIALIZED */ |
} |
return( handle ); |
} |
} |
/programs/develop/open watcom/trunk/clib/src/strcmp.c |
---|
0,0 → 1,58 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include "riscstr.h" |
#include "xstring.h" |
#undef strcmp |
/* return <0 if s<t, 0 if s==t, >0 if s>t */ |
#if defined(__RISCSTR__) && defined(__WIDECHAR__) |
_WCRTLINK int __simple_wcscmp( const CHAR_TYPE *s, const CHAR_TYPE *t ) |
#else |
_WCRTLINK int __F_NAME(strcmp,wcscmp)( const CHAR_TYPE *s, const CHAR_TYPE *t ) |
#endif |
{ |
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86) |
return( _inline_strcmp( s, t ) ); |
#else |
for( ; *s == *t; s++, t++ ) |
if( *s == NULLCHAR ) |
return( 0 ); |
return( *s - *t ); |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/ulltoa.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
// this file should remain an indirected file |
// it is done this way to support the reuse of the source file |
#define __WIDECHAR__ |
#undef __INLINE_FUNCTIONS__ |
#include "lltoa.c" |
/programs/develop/open watcom/trunk/clib/src/ultoa.c |
---|
0,0 → 1,37 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
// this file should remain an indirected file |
// it is done this way to support the reuse of the source file |
#define __WIDECHAR__ |
#undef __INLINE_FUNCTIONS__ |
#include "ltoa.c" |
/programs/develop/open watcom/trunk/clib/src/vsprintf.c |
---|
0,0 → 1,127 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include "widechar.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include <limits.h> |
#include "printf.h" |
/* |
* mem_putc -- append a character to a string in memory |
*/ |
#ifdef __WIDECHAR__ |
struct vswprtf_buf { |
CHAR_TYPE *bufptr; |
int chars_output; |
int max_chars; |
}; |
static slib_callback_t mem_putc; // setup calling convention |
static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char ) |
{ |
struct vswprtf_buf *info; |
info = (struct vswprtf_buf*) specs->_dest; |
if( info->chars_output + 1 <= info->max_chars ) { |
*( info->bufptr++ ) = op_char; |
specs->_output_count++; |
info->chars_output++; |
} |
} |
#else |
static slib_callback_t mem_putc; // setup calling convention |
static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char ) |
{ |
*( specs->_dest++ ) = op_char; |
specs->_output_count++; |
} |
#endif |
#ifdef __WIDECHAR__ |
_WCRTLINK int vswprintf( CHAR_TYPE *dest, size_t n, const CHAR_TYPE *format, va_list arg ) |
{ |
slib_callback_t *tmp; |
auto struct vswprtf_buf info; |
#if defined( __386__ ) && defined( __QNX__ ) |
/* avoid some segment relocations for 32-bit QNX */ |
tmp = (void (*)())mem_putc; |
#else |
tmp = mem_putc; |
#endif |
if( n != 0 ) { |
info.bufptr = dest; |
info.chars_output = 0; |
info.max_chars = n - 1; |
__wprtf( &info, format, arg, tmp ); |
dest[info.chars_output] = NULLCHAR; |
} |
return( info.chars_output ); |
} |
#endif |
_WCRTLINK int __F_NAME(vsprintf,_vswprintf) ( CHAR_TYPE *dest, const CHAR_TYPE *format, va_list arg ) |
{ |
slib_callback_t *tmp; |
#ifndef __WIDECHAR__ |
register int len; |
#else |
auto struct vswprtf_buf info; |
#endif |
#if defined( __386__ ) && defined( __QNX__ ) |
/* avoid some segment relocations for 32-bit QNX */ |
tmp = (void (*)())mem_putc; |
#else |
tmp = mem_putc; |
#endif |
#ifdef __WIDECHAR__ |
info.bufptr = dest; |
info.chars_output = 0; |
info.max_chars = INT_MAX; |
__wprtf( &info, format, arg, tmp ); |
dest[info.chars_output] = NULLCHAR; |
return( info.chars_output ); |
#else |
len = __prtf( dest, format, arg, tmp ); |
dest[len] = NULLCHAR; |
return( len ); |
#endif |
} |
/programs/develop/open watcom/trunk/clib/src/wctomb.c |
---|
0,0 → 1,61 |
/**************************************************************************** |
* |
* Open Watcom Project |
* |
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
* |
* ======================================================================== |
* |
* This file contains Original Code and/or Modifications of Original |
* Code as defined in and that are subject to the Sybase Open Watcom |
* Public License version 1.0 (the 'License'). You may not use this file |
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
* provided with the Original Code and Modifications, and is also |
* available at www.sybase.com/developer/opensource. |
* |
* The Original Code and all software distributed under the License are |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
* NON-INFRINGEMENT. Please see the License for the specific language |
* governing rights and limitations under the License. |
* |
* ======================================================================== |
* |
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
* DESCRIBE IT HERE! |
* |
****************************************************************************/ |
#include "variety.h" |
#include <mbstring.h> |
#include "farfunc.h" |
/**** |
***** Convert a wide character to a multibyte character. |
****/ |
_WCRTLINK int _NEARFAR(wctomb,_fwctomb)( char _FFAR *ch, wchar_t wchar ) |
{ |
/*** Catch special cases ***/ |
if( ch == 0 ) return( 0 ); |
/*** Convert the character ***/ |
if( wchar & 0xFF00 ) |
{ |
ch[0] = (wchar&0xFF00) >> 8; /* store lead byte */ |
ch[1] = wchar & 0x00FF; /* store trail byte */ |
return( 2 ); /* return size in bytes */ |
} |
else |
{ |
ch[0] = wchar & 0x00FF; /* store char byte */ |
return( 1 ); /* return size in bytes */ |
} |
} |
/programs/develop/open watcom/trunk/clib/h/_comdef.h |
---|
File deleted |