//x.real <= y.real bool _RatSmallerOrEqual(const ComplexRational &x, const ComplexRational &y) { #ifdef __DEBUG_MODE_ON_ if (!_IsRational(x) || !_IsRational(y)) throw Debugger::DebugMessage("In _RatSmallerOrEqual(C,C),\nParameter Mismatch\n"); #endif return (RatSmallerOrEqual(x.real, y.real)); }
void WriteComplexRational(const ComplexRational &x) { WriteRational(x.real); if (!_IsRational(x)) { if (RatBigger(x.image, Rational("0", "1"))) std::cout << "+"; WriteRational(x.image); std::cout << "i"; } }
// abs(x) ComplexRational _RatAbs(const ComplexRational &x) { #ifdef __DEBUG_MODE_ON_ if (!_IsRational(x)) throw Debugger::DebugMessage("In _RatAbs(C),\nParameter Mismatch\n"); #endif return ComplexRational(RatAbs(x.real), RatZero); }
static unsigned short dos_get_code_page( void ) /*********************************************/ { if( _IsPharLap() ) { union REGPACK regs; memset( ®s, 0, sizeof( regs ) ); regs.w.ax = 0x6601; /* get extended country info */ intr( 0x21, ®s ); if( (regs.w.flags & 1) == 0 ) { return( regs.w.bx ); /* return active code page */ } } else if( _IsRational() ) { rm_call_struct dblock; memset( &dblock, 0, sizeof( dblock ) ); dblock.eax = 0x6601; /* get extended country info */ DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); if( (dblock.flags & 1) == 0 ) { return( (unsigned short)dblock.ebx ); } } return( 437 ); /* return default */ }
_WCRTLINK void _WCNEAR *_nrealloc( void _WCI86NEAR *stg, size_t req_size ) { void _WCNEAR *p; size_t old_size; if( stg == NULL ) { return( _nmalloc( req_size ) ); } if( req_size == 0 ) { _nfree( stg ); return( (void _WCNEAR *) NULL ); } old_size = _nmsize( stg ); p = _nexpand( stg, req_size ); /* try to expand it in place */ if( p == NULL ) { /* if couldn't be expanded in place */ #if defined(__DOS_EXT__) if( _IsRational() ) { frlptr flp, newflp; flp = (frlptr) ((PTR)stg - TAG_SIZE); newflp = __ReAllocDPMIBlock( flp, req_size + TAG_SIZE ); if( newflp ) { return( (void _WCNEAR *)((PTR)newflp + TAG_SIZE) ); } } #endif p = _nmalloc( req_size ); /* - allocate a new block */ if( p != NULL ) { /* - if we got one */ memcpy( p, stg, old_size ); /* copy it */ _nfree( stg ); /* and free old one */ } else { _nexpand( stg, old_size ); /* reset back to old size */ } } return( p ); }
static int __CreateNewNHeap( unsigned amount ) { mheapptr p1; frlptr flp; unsigned brk_value; #if defined(__WARP__) ULONG os2_alloc_flags; #endif if( !__heap_enabled ) return( 0 ); if( _curbrk == ~1u ) return( 0 ); if( __AdjustAmount( &amount ) == 0 ) return( 0 ); #if defined(__WINDOWS_286__) brk_value = (unsigned)LocalAlloc( LMEM_FIXED, amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__WINDOWS_386__) brk_value = (unsigned)DPMIAlloc( amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__WARP__) { PBYTE p; APIRET apiret; os2_alloc_flags = PAG_COMMIT | PAG_READ | PAG_WRITE; if( _os2_obj_any_supported && _os2_use_obj_any ) { os2_alloc_flags |= OBJ_ANY; } apiret = DosAllocMem( (PPVOID)&p, amount, os2_alloc_flags ); if( apiret ) return( 0 ); brk_value = (unsigned)p; } #elif defined(__NT__) brk_value = (unsigned)VirtualAlloc( NULL, amount, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); //brk_value = (unsigned) LocalAlloc( LMEM_FIXED, amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__CALL21__) { tag _WCNEAR *tmp_tag; tmp_tag = (tag _WCNEAR *)TinyMemAlloc( amount ); if( tmp_tag == NULL ) { return( 0 ); } /* make sure it will not look like the end of a heap */ tmp_tag[0] = ! END_TAG; brk_value = (unsigned)&tmp_tag[2]; amount -= 2 * TAG_SIZE; // 11-jun-95, subtract extra tag } #elif defined(__DOS_EXT__) // if( !__IsCtsNHeap() ) { { tag *tmp_tag; if( _IsRational() ) { tmp_tag = RationalAlloc( amount ); if( tmp_tag ) { amount = *tmp_tag; } } else { /* CodeBuilder */ tmp_tag = TinyCBAlloc( amount ); amount -= TAG_SIZE; } if( tmp_tag == NULL ) { return( 0 ); } brk_value = (unsigned)tmp_tag; } // Pharlap, RSI/non-zero can never call this function #elif defined(__RDOS__) brk_value = (unsigned)RdosAllocateMem( amount ); if( brk_value == 0 ) { return( 0 ); } #endif if( amount - TAG_SIZE > amount ) { return( 0 ); } else { amount -= TAG_SIZE; } if( amount < sizeof( miniheapblkp ) + sizeof( frl ) ) { /* there isn't enough for a heap block (struct miniheapblkp) and one free block (frl) */ return( 0 ); } /* we've got a new heap block */ p1 = (mheapptr)brk_value; p1->len = amount; #if defined(__WARP__) // Remeber if block was allocated with OBJ_ANY - may be in high memory p1->used_obj_any = ( _os2_obj_any_supported && _os2_use_obj_any ); #endif // Now link it up flp = __LinkUpNewMHeap( p1 ); amount = flp->len; /* build a block for _nfree() */ SET_MEMBLK_SIZE_USED( flp, amount ); ++p1->numalloc; p1->largest_blk = 0; _nfree( (PTR)flp + TAG_SIZE ); return( 1 ); }
static int __F_NAME(__sopen,__wsopen)( const CHAR_TYPE *name, int mode, int shflag, va_list args ) { int rwmode; int handle; int attr; int permission; unsigned iomode_flags; tiny_ret_t rc; char dummy; #ifdef __WIDECHAR__ char mbName[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */ #endif handle = -1; rc = 0; while( *name == STRING( ' ' ) ) ++name; #ifdef __WIDECHAR__ /*** If necessary, convert the wide filename to multibyte form ***/ if( wcstombs( mbName, name, sizeof( mbName ) ) == -1 ) { mbName[0] = '\0'; } #endif rwmode = mode & ( O_RDONLY | O_WRONLY | O_RDWR | O_NOINHERIT ); if( _dos_open( __F_NAME(name,mbName), rwmode | shflag, &handle ) == 0 ) { if( handle >= __NFiles ) { TinyClose( handle ); __set_errno( EMFILE ); return( -1 ); } } /* 17-apr-90 05-sep-91 */ if( (mode & (O_RDONLY | O_WRONLY | O_RDWR)) != O_RDONLY ) { if( handle != -1 ) { if( ! isatty( handle ) ) { /* if not a device */ #if 0 rc = TinyAccess( name, 0 ); /* check for existence */ if( TINY_ERROR( rc ) ) { /* file does not exist */ TinyClose( handle ); /* close whatever file we got */ handle = -1; } else if( mode & O_EXCL ) { /* must not exist */ #else /* Don't need to do the access check, since the file was opened and therefore must exist (TinyOpen can't create a file). We don't want to do the check because there are classes of items in the file system namespace that are not devices, but the TinyAccess will fail on (e.g. named pipes). */ /* must not exist if O_CREAT specified */ if( (mode & O_EXCL) && (mode & O_CREAT) ) { #endif TinyClose( handle ); __set_errno( EEXIST ); return( -1 ); } else if( mode & O_TRUNC ) { /* truncate file */ rc = TinyWrite( handle, &dummy, 0 ); if( TINY_ERROR( rc ) ) { TinyClose( handle ); return( __set_errno_dos( TINY_INFO( rc ) ) ); } } } } } if( handle == -1 ) { /* could not open */ if( (mode & O_CREAT) == 0 || _RWD_doserrno != E_nofile ) { return( -1 ); } /* creating the file */ permission = va_arg( args, int ); va_end( args ); if( permission == 0 ) permission = S_IWRITE | S_IREAD; permission &= ~_RWD_umaskval; /* 05-jan-95 */ attr = 0; if(( permission & S_IWRITE) == 0 ) attr = _A_RDONLY; #if 0 /* remove this support because it is not consistently available */ if( _RWD_osmajor >= 5 #ifdef __DOS_EXT__ && !_IsFlashTek() && !_IsRational() #endif ) { /* this function is only available in version DOS 5 and up */ /* this new way was added to handle the case of creating a */ /* new file with read-only access, but with a writeable */ /* file handle */ #ifdef __WIDECHAR__ rc = TinyCreateEx( mbName, rwmode|shflag, attr, TIO_OPEN ); #else rc = TinyCreateEx( name, rwmode|shflag, attr, TIO_OPEN ); #endif if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } handle = TINY_INFO( rc ); } else #endif { /* do it the old way */ if( _dos_creat( __F_NAME(name,mbName), attr, &handle ) ) { return( -1 ); } if( handle >= __NFiles ) { TinyClose( handle ); __set_errno( EMFILE ); return( -1 ); } /* 21-nov-90 AFS: the file is created so now the file must be */ /* opened with the correct share permissions */ if( shflag != 0 ) { rc = TinyClose( handle ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } if( _dos_open( __F_NAME(name,mbName), rwmode | shflag, &handle ) ) { return( -1 ); } /* handle does not equal -1 now */ } } } iomode_flags = __GetIOMode( handle ); iomode_flags &= ~(_READ|_WRITE|_APPEND|_BINARY); /* 11-aug-88 */ if( isatty( handle ) ) iomode_flags |= _ISTTY; rwmode &= ~O_NOINHERIT; if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; if( rwmode == O_RDONLY) iomode_flags |= _READ; 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( handle, iomode_flags ); #ifdef DEFAULT_WINDOWING if( _WindowsNewWindow != 0 ) { if( !__F_NAME(stricmp,wcscmp)( name, STRING( "con" ) ) ) { _WindowsNewWindow( NULL, handle, -1 ); } } #endif return( handle ); } #if 0 /* couldn't find any user; please re-enable if it's necessary */ #ifndef __WIDECHAR__ /* compile one version only */ int __set_binary( int handle ) { unsigned iomode_flags; __ChkTTYIOMode( handle ); iomode_flags = __GetIOMode( handle ); iomode_flags |= _BINARY; __SetIOMode( handle, iomode_flags ); if( iomode_flags & _ISTTY ) { tiny_ret_t rc; rc = TinyGetDeviceInfo( handle ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } rc = TinySetDeviceInfo( handle, TINY_INFO(rc) | TIO_CTL_RAW ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } } return( 0 ); }
static int __AdjustAmount( unsigned *amount ) { unsigned old_amount = *amount; unsigned amt; #if ! ( defined(__WINDOWS_286__) || \ defined(__WINDOWS_386__) || \ defined(__WARP__) || \ defined(__NT__) \ ) unsigned last_free_amt; #endif amt = old_amount; amt = ( amt + TAG_SIZE + ROUND_SIZE) & ~ROUND_SIZE; if( amt < old_amount ) { return( 0 ); } #if ! ( defined(__WINDOWS_286__) || \ defined(__WINDOWS_386__) || \ defined(__WARP__) || \ defined(__NT__) \ ) #if defined(__DOS_EXT__) if( _IsRationalZeroBase() || _IsCodeBuilder() ) { // Allocating extra to identify the dpmi block amt += sizeof(struct dpmi_hdr); } else { #else { #endif last_free_amt = __LastFree(); /* adjust for last free block */ if( last_free_amt >= amt ) { amt = 0; } else { amt -= last_free_amt; } } #endif /* amount is even here */ /* extra amounts (22-feb-91 AFS) (1) adding a new heap needs: frl free block req'd for _nmalloc request (frl is the MINIMUM because the block may be freed) tag end of miniheap descriptor struct miniheapblkp start of miniheap descriptor (2) extending heap needs: tag free block req'd for _nmalloc request */ *amount = amt; amt += ( (TAG_SIZE) + sizeof(frl) + sizeof(struct miniheapblkp) ); if( amt < *amount ) return( 0 ); if( amt < _amblksiz ) { /* _amblksiz may not be even so round down to an even number nb. pathological case: where _amblksiz == 0xffff, we don't want the usual round up to even */ amt = _amblksiz & ~1u; } #if defined(__WINDOWS_386__) || \ defined(__WARP__) || \ defined(__NT__) || \ defined(__CALL21__) || \ defined(__DOS_EXT__) || \ defined(__RDOS__) /* make sure amount is a multiple of 4k */ *amount = amt; amt += 0x0fff; if( amt < *amount ) return( 0 ); amt &= ~0x0fff; #endif *amount = amt; return( *amount != 0 ); } #if defined(__WINDOWS_286__) || \ defined(__WINDOWS_386__) || \ defined(__WARP__) || \ defined(__NT__) || \ defined(__CALL21__) || \ defined(__DOS_EXT__) || \ defined(__RDOS__) static int __CreateNewNHeap( unsigned amount ) { mheapptr p1; frlptr flp; unsigned brk_value; if( !__heap_enabled ) return( 0 ); if( _curbrk == ~1u ) return( 0 ); if( __AdjustAmount( &amount ) == 0 ) return( 0 ); #if defined(__WINDOWS_286__) brk_value = (unsigned) LocalAlloc( LMEM_FIXED, amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__WINDOWS_386__) brk_value = (unsigned) DPMIAlloc( amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__WARP__) { PBYTE p; if( DosAllocMem( (PPVOID)&p, amount, PAG_COMMIT|PAG_READ|PAG_WRITE ) ) { return( 0 ); } brk_value = (unsigned)p; } #elif defined(__NT__) brk_value = (unsigned) VirtualAlloc( NULL, amount, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); //brk_value = (unsigned) LocalAlloc( LMEM_FIXED, amount ); if( brk_value == 0 ) { return( 0 ); } #elif defined(__CALL21__) { tag _WCNEAR *tmp_tag; tmp_tag = (tag _WCNEAR *)TinyMemAlloc( amount ); if( tmp_tag == NULL ) { return( 0 ); } /* make sure it will not look like the end of a heap */ tmp_tag[0] = ! END_TAG; brk_value = (unsigned) &tmp_tag[2]; amount -= 2 * TAG_SIZE; // 11-jun-95, subtract extra tag } #elif defined(__DOS_EXT__) // if( _IsRationalZeroBase() || _IsCodeBuilder() ) { { tag *tmp_tag; if( _IsRational() ) { tmp_tag = RationalAlloc( amount ); if( tmp_tag ) amount = *tmp_tag; } else { /* CodeBuilder */ tmp_tag = TinyCBAlloc( amount ); amount -= TAG_SIZE; } if( tmp_tag == NULL ) { return( 0 ); } brk_value = (unsigned) tmp_tag; } // Pharlap, RSI/non-zero can never call this function #elif defined(__RDOS__) brk_value = (unsigned) RdosAllocateMem( amount ); if( brk_value == 0 ) { return( 0 ); } #endif if( amount - TAG_SIZE > amount ) { return( 0 ); } else { amount -= TAG_SIZE; } if( amount < sizeof( struct miniheapblkp ) + sizeof( frl ) ) { /* there isn't enough for a heap block (struct miniheapblkp) and one free block (frl) */ return( 0 ); } /* we've got a new heap block */ p1 = (mheapptr) brk_value; p1->len = amount; // Now link it up flp = __LinkUpNewMHeap( p1 ); amount = flp->len; /* build a block for _nfree() */ flp->len = amount | 1; ++p1->numalloc; /* 28-dec-90 */ p1->largest_blk = 0; _nfree( (PTR)flp + TAG_SIZE ); return( 1 ); }
void _InitSegments( void ) //======================== { unsigned short seg; unsigned char os_major; dbcs_pair *p; dbcs_pair __far *s; _StackSeg = FP_SEG( &seg ); // point to stack segment #if defined( __386__ ) if( _IsRational() || _IsCodeBuilder() ) { seg = FP_SEG( &_BiosSeg ); } else if( __X32VM != 0 ) { // FlashTek seg = __x386_zero_base_selector; } else { // variables already initialized to PharLap defaults seg = 0; } if( seg != 0 ) { _BiosSeg = seg; _MonoSeg = seg; _CgaSeg = seg; _EgaSeg = seg; _RomSeg = seg; _BiosOff = 0x00000400; _MonoOff = 0x000B0000; _CgaOff = 0x000B8000; _EgaOff = 0x000A0000; _RomOff = 0x000C0000; } #endif // check for DBCS _IsDBCS = FALSE; #if !defined( __386__ ) os_major = (unsigned char) os_version(); #else os_major = _RMInterrupt( 0x21, 0x3000, 0x0, 0x0, 0x0, 0x0, 0x0 ); #endif if( os_major >= 5 ) { // The DBCS vector table call is not supported in earlier versions #if !defined( __386__ ) s = dbcs_vector_table(); #else s = MK_FP( _BiosSeg, _RMInterrupt2( 0x21, 0x6300 ) ); #endif p = _DBCSPairs; while( s->start_range != 0 ) { p->start_range = s->start_range; p->end_range = s->end_range; ++p; ++s; } p->start_range = 0; p->end_range = 0; if( _DBCSPairs[ 0 ].start_range != 0 ) { _IsDBCS = TRUE; } } }