Initial commit.
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
|
||||
#ifdef DEMO
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <windows.h>
|
||||
#include "shareprot.h"
|
||||
#include "stdutil.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef PRO //Blitz3D?
|
||||
#define PRODUCT 0xce57abd1
|
||||
#else
|
||||
#ifdef PLUS //BlitzPlus?
|
||||
#define PRODUCT 0x7abd57ec
|
||||
#else //Blitz2D!
|
||||
#define PRODUCT 0x4feb9567
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DEMO_RUNS 30
|
||||
|
||||
#define REG_MUNG (PRODUCT^0xce57abd7)
|
||||
#define SYS_MUNG (PRODUCT^0x7adb57ec)
|
||||
|
||||
#define REG_PRODUCT (PRODUCT^0x677fcb37)
|
||||
#define SYS_PRODUCT (PRODUCT^0x4feba567)
|
||||
|
||||
static void expired(){
|
||||
MessageBox( 0,
|
||||
|
||||
"This demo verson has expired!\n\n"
|
||||
"Please visit www.blitzbasic.com to buy the full version.",
|
||||
|
||||
"Demo expired",MB_OK );
|
||||
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
static int tohex( int n ){
|
||||
return n<10 ? n+'0' : n+'a'-10;
|
||||
}
|
||||
|
||||
static string getSysFileName(){
|
||||
//get system file...
|
||||
char dir[MAX_PATH];
|
||||
GetSystemDirectory( dir,MAX_PATH );
|
||||
char file[128];
|
||||
char *p=file,t=(char)0xbd;
|
||||
*p++='\\'^t;
|
||||
*p++='m'^t;
|
||||
*p++='s'^t;
|
||||
*p++='v'^t;
|
||||
*p++='c'^t;
|
||||
*p++=tohex((SYS_PRODUCT)&0xf)^t;
|
||||
*p++=tohex((SYS_PRODUCT>>8)&0xf)^t;
|
||||
*p++=tohex((SYS_PRODUCT>>16)&0xf)^t;
|
||||
*p++=tohex((SYS_PRODUCT>>24)&0xf)^t;
|
||||
*p++='.'^t;
|
||||
*p++='s'^t;
|
||||
*p++='y'^t;
|
||||
*p++='s'^t;
|
||||
*p++=0;
|
||||
for( p=file;*p;++p ) *p^=t;
|
||||
return string( dir )+string( file );
|
||||
}
|
||||
|
||||
static string getRegKeyName(){
|
||||
return string( "software\\Brlconfig\\"+itoa(REG_PRODUCT) );
|
||||
}
|
||||
|
||||
static bool setCount( int cnt ){
|
||||
|
||||
HKEY hkey;
|
||||
if( RegCreateKey( HKEY_LOCAL_MACHINE,getRegKeyName().c_str(),&hkey )==ERROR_SUCCESS ){
|
||||
int val=cnt^REG_MUNG;
|
||||
LONG n=RegSetValueEx( hkey,0,0,REG_DWORD,(const BYTE*)&val,4 );
|
||||
RegCloseKey( hkey );
|
||||
if( n!=ERROR_SUCCESS ) return false;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( FILE *f=fopen( getSysFileName().c_str(),"wb" ) ){
|
||||
int val=cnt^SYS_MUNG;
|
||||
int n=fwrite( &val,4,1,f );
|
||||
fclose(f);
|
||||
if( n!=1 ) return false;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int getCount(){
|
||||
|
||||
int reg_cnt=DEMO_RUNS+1,sys_cnt=DEMO_RUNS+1;
|
||||
|
||||
HKEY hkey;
|
||||
if( RegOpenKey( HKEY_LOCAL_MACHINE,getRegKeyName().c_str(),&hkey )==ERROR_SUCCESS ){
|
||||
int ty=0,sz=4;
|
||||
RegQueryValueEx( hkey,0,0,(DWORD*)&ty,(BYTE*)®_cnt,(DWORD*)&sz );
|
||||
if( ty!=REG_DWORD ) reg_cnt=0;
|
||||
else{
|
||||
reg_cnt^=REG_MUNG;
|
||||
if( reg_cnt<0 || reg_cnt>DEMO_RUNS ) reg_cnt=0;
|
||||
}
|
||||
RegCloseKey( hkey );
|
||||
}
|
||||
|
||||
if( FILE *f=fopen( getSysFileName().c_str(),"rb" ) ){
|
||||
if( fread( &sys_cnt,4,1,f )!=1 ) sys_cnt=0;
|
||||
else{
|
||||
sys_cnt^=SYS_MUNG;
|
||||
if( sys_cnt<0 || sys_cnt>DEMO_RUNS ) sys_cnt=0;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return sys_cnt==reg_cnt ? sys_cnt : 0;
|
||||
}
|
||||
|
||||
void shareProtStart(){
|
||||
|
||||
if( int cnt=getCount() ) setCount( cnt-1 );
|
||||
}
|
||||
|
||||
int shareProtCheck(){
|
||||
|
||||
return getCount();
|
||||
}
|
||||
|
||||
void shareProtAssert(){
|
||||
|
||||
if( !getCount() ) shareProtJump( expired );
|
||||
}
|
||||
|
||||
_declspec(naked) void _stdcall shareProtJump( void(*target)() ){
|
||||
_asm{
|
||||
mov eax,4[esp]
|
||||
mov [esp],0x12345678 ;return
|
||||
mov 4[esp],0x12345678 ;param
|
||||
mov 8[esp],0x12345678 ;more...
|
||||
call eax
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
#ifndef SHAREPROT_H
|
||||
#define SHAREPROT_H
|
||||
|
||||
//bump counter
|
||||
void shareProtStart();
|
||||
|
||||
//return counter
|
||||
int shareProtCheck();
|
||||
|
||||
//error if counter==0
|
||||
void shareProtAssert();
|
||||
|
||||
//clean stack then jump! Never returns!
|
||||
void _stdcall shareProtJump( void(*target)() );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,362 @@
|
||||
|
||||
#include "stdutil.h"
|
||||
|
||||
#include <set>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef MEMDEBUG
|
||||
|
||||
struct Mem{
|
||||
Mem *next,*prev;
|
||||
const char *file;
|
||||
int line,size,tag;
|
||||
};
|
||||
|
||||
static bool track;
|
||||
|
||||
static Mem head,tail;
|
||||
static Mem x_head,x_tail;
|
||||
|
||||
static void remove( Mem *m ){
|
||||
m->next->prev=m->prev;
|
||||
m->prev->next=m->next;
|
||||
}
|
||||
|
||||
static void insert( Mem *m,Mem *next ){
|
||||
m->next=next;
|
||||
m->prev=next->prev;
|
||||
next->prev->next=m;
|
||||
next->prev=m;
|
||||
}
|
||||
|
||||
static void init(){
|
||||
if( head.next ) return;
|
||||
head.next=head.prev=&tail;head.tag='HEAD';
|
||||
tail.next=tail.prev=&head;tail.tag='TAIL';
|
||||
x_head.next=x_head.prev=&x_tail;x_head.tag='HEAD';
|
||||
x_tail.next=x_tail.prev=&x_head;x_tail.tag='TAIL';
|
||||
}
|
||||
|
||||
static void check( Mem *m ){
|
||||
if( m->tag!='DNEW' ){
|
||||
MessageBox( GetDesktopWindow(),"mem_check: pre_tag!='DNEW'","Memory error",MB_OK|MB_ICONWARNING );
|
||||
if( m->tag=='NDWE' ){
|
||||
string t="Probable double delete";
|
||||
t+="- d_new file: "+string(m->file)+" line:"+itoa(m->line);
|
||||
MessageBox( GetDesktopWindow(),t.c_str(),"Memory error",MB_OK|MB_ICONWARNING );
|
||||
}
|
||||
ExitProcess( 0 );
|
||||
}
|
||||
int *t=(int*)( (char*)(m+1)+m->size );
|
||||
if( *t!='dnew' ){
|
||||
MessageBox( GetDesktopWindow(),"mem_check: post_tag!='dnew'","Memory error",MB_OK|MB_ICONWARNING );
|
||||
string t="Probable memory overwrite - d_new file: "+string(m->file)+" line:"+itoa(m->line);
|
||||
MessageBox( GetDesktopWindow(),t.c_str(),"Memory error",MB_OK|MB_ICONWARNING );
|
||||
ExitProcess( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
static void *op_new( size_t size,const char *file="<unknown>",int line=0 ){
|
||||
init();
|
||||
Mem *m=(Mem*)malloc( sizeof(Mem)+size+sizeof(int) );
|
||||
memset( m+1,0xcc,size );
|
||||
m->file=file;m->line=line;m->size=size;m->tag='DNEW';
|
||||
int *t=(int*)( (char*)(m+1)+size );*t='dnew';
|
||||
if( track ) insert( m,head.next );
|
||||
else insert( m,x_head.next );
|
||||
return m+1;
|
||||
}
|
||||
|
||||
static void op_delete( void *q ){
|
||||
init();
|
||||
if( !q ) return;
|
||||
Mem *m=(Mem*)q-1;
|
||||
check( m );
|
||||
remove( m );
|
||||
m->tag='NDWE';
|
||||
*(int*)( (char*)(m+1)+m->size )='ndwe';
|
||||
free( m );
|
||||
}
|
||||
|
||||
void trackmem( bool enable ){
|
||||
init();
|
||||
if( track==enable ) return;
|
||||
track=enable;
|
||||
Mem *m;
|
||||
while( (m=head.next)!=&tail ){
|
||||
remove( m );insert( m,x_head.next );
|
||||
}
|
||||
}
|
||||
|
||||
void checkmem( ostream &out ){
|
||||
init();
|
||||
Mem *m,*next;
|
||||
int sum=0,usum=0,xsum=0;
|
||||
for( m=head.next;m!=&tail;m=next ){
|
||||
check( m );
|
||||
next=m->next;
|
||||
if( m->line ){
|
||||
out<<m->file<<" line:"<<m->line<<" "<<m->size<<" bytes"<<endl;
|
||||
sum+=m->size;
|
||||
}else{
|
||||
usum+=m->size;
|
||||
}
|
||||
}
|
||||
for( m=x_head.next;m!=&x_tail;m=m->next ){
|
||||
check( m );
|
||||
xsum+=m->size;
|
||||
}
|
||||
out<<"Tracked blitz mem in use:"<<sum<<endl;
|
||||
out<<"Tracked other mem in use:"<<usum<<endl;
|
||||
out<<"Untracked mem in use:"<<xsum<<endl;
|
||||
out<<"Total mem in use:"<<(sum+usum+xsum)<<endl;
|
||||
}
|
||||
|
||||
void * _cdecl operator new( size_t size ){ return op_new( size ); }
|
||||
void * _cdecl operator new[]( size_t size ){ return op_new( size ); }
|
||||
void * _cdecl operator new( size_t size,const char *file,int line ){ return op_new( size,file,line ); }
|
||||
void * _cdecl operator new[]( size_t size,const char *file,int line ){ return op_new( size,file,line ); }
|
||||
void _cdecl operator delete( void *q ){ op_delete( q ); }
|
||||
void _cdecl operator delete[]( void *q ){ op_delete( q ); }
|
||||
void _cdecl operator delete( void *q,const char *file,int line ){ op_delete( q ); }
|
||||
void _cdecl operator delete[]( void *q,const char *file,int line ){ op_delete( q ); }
|
||||
|
||||
#else
|
||||
|
||||
void trackmem( bool enable ){
|
||||
}
|
||||
|
||||
void checkmem( ostream &out ){
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int atoi( const string &s ){
|
||||
return atoi( s.c_str() );
|
||||
}
|
||||
|
||||
double atof( const string &s ){
|
||||
return atof( s.c_str() );
|
||||
}
|
||||
|
||||
string itoa( int n ){
|
||||
char buff[32];itoa( n,buff,10 );
|
||||
return string( buff );
|
||||
}
|
||||
|
||||
static int _finite( double n ){ // definition: exponent anything but 2047.
|
||||
|
||||
int e; // 11 bit exponent
|
||||
const int eMax = 2047; // 0x7ff, all bits = 1
|
||||
|
||||
int *pn = (int *) &n;
|
||||
|
||||
e = *++pn; // Intel order!
|
||||
e = ( e >> 20 ) & eMax;
|
||||
|
||||
return e != eMax;
|
||||
}
|
||||
|
||||
static int _isnan( double n ){ // definition: exponent 2047, nonzero fraction.
|
||||
|
||||
int e; // 11 bit exponent
|
||||
const int eMax = 2047; // 0x7ff, all bits = 1
|
||||
|
||||
int *pn = (int *) &n;
|
||||
|
||||
e = *++pn; // Intel order!
|
||||
e = ( e >> 20 ) & eMax;
|
||||
|
||||
if ( e != 2047 ) return 0; // almost always return here
|
||||
|
||||
int fHi, fLo; // 52 bit fraction
|
||||
|
||||
fHi = ( *pn ) & 0xfffff; // first 20 bits
|
||||
fLo = *--pn; // last 32 bits
|
||||
|
||||
return ( fHi | fLo ) != 0; // returns 0,1 not just 0,nonzero
|
||||
}
|
||||
|
||||
/////////////
|
||||
//By FLOYD!//
|
||||
/////////////
|
||||
string ftoa( float n ){
|
||||
|
||||
static const int digits=6;
|
||||
|
||||
int eNeg = -4, ePos = 8; // limits for e notation.
|
||||
|
||||
char buffer[50]; // from MSDN example, 25 would probably suffice
|
||||
string t;
|
||||
int dec, sign;
|
||||
|
||||
if ( _finite( n ) ){
|
||||
|
||||
// if ( digits < 1 ) digits = 1; // less than one digit is nonsense
|
||||
// if ( digits > 8 ) digits = 8; // practical maximum for float
|
||||
|
||||
t = _ecvt( n, digits, &dec, &sign );
|
||||
|
||||
if ( dec <= eNeg + 1 || dec > ePos ){
|
||||
|
||||
_gcvt( n, digits, buffer );
|
||||
t = buffer;
|
||||
return t;
|
||||
}
|
||||
|
||||
// Here is the tricky case. We want a nicely formatted
|
||||
// number with no e-notation or multiple trailing zeroes.
|
||||
|
||||
if ( dec <= 0 ){
|
||||
|
||||
t = "0." + string( -dec, '0' ) + t;
|
||||
dec = 1; // new location for decimal point
|
||||
|
||||
}
|
||||
else if( dec < digits ){
|
||||
|
||||
t = t.substr( 0, dec ) + "." + t.substr( dec );
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
t = t + string( dec - digits, '0' ) + ".0";
|
||||
dec += dec - digits;
|
||||
|
||||
}
|
||||
|
||||
// Finally, trim off excess zeroes.
|
||||
|
||||
int dp1 = dec + 1, p = t.length();
|
||||
while( --p > dp1 && t[p] == '0' );
|
||||
t = string( t, 0, ++p );
|
||||
|
||||
return sign ? "-" + t : t;
|
||||
|
||||
} // end of finite case
|
||||
|
||||
if ( _isnan( n ) ) return "NaN";
|
||||
if ( n > 0.0 ) return "Infinity";
|
||||
if ( n < 0.0 ) return "-Infinity";
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
/*
|
||||
string ftoa( float n ){
|
||||
|
||||
static const float min=.000001f,max=9999999.0f;
|
||||
|
||||
int i=*(int*)&n;
|
||||
int e=(i>>23)&0xff;
|
||||
int f=i&0x007fffff;
|
||||
|
||||
if( e==0xff && f ) return "NAN";
|
||||
|
||||
string t;
|
||||
int s=(i>>31)&0x01;
|
||||
|
||||
if( e==0xff ){
|
||||
t="INFINITY";
|
||||
}else if( !e && !f ){
|
||||
t="0.000000";
|
||||
}else if( n>=min && n<=max ){
|
||||
int dec,sgn;
|
||||
t=_fcvt( fabs(n),6,&dec,&sgn );
|
||||
if( dec<=0 ){
|
||||
t="0."+string( -dec,'0' )+t;
|
||||
}else if( dec<t.size() ){
|
||||
t=t.substr( 0,dec )+"."+t.substr( dec );
|
||||
}else{
|
||||
t=t+string( '0',dec-t.size() )+".000000";
|
||||
}
|
||||
}else{
|
||||
char buff[32];
|
||||
_gcvt( fabs(n),7,buff );
|
||||
t=buff;
|
||||
}
|
||||
return s ? "-"+t : t;
|
||||
}
|
||||
*/
|
||||
|
||||
string tolower( const string &s ){
|
||||
string t=s;
|
||||
for( int k=0;k<t.size();++k ) t[k]=tolower(t[k]);
|
||||
return t;
|
||||
}
|
||||
|
||||
string toupper( const string &s ){
|
||||
string t=s;
|
||||
for( int k=0;k<t.size();++k ) t[k]=toupper(t[k]);
|
||||
return t;
|
||||
}
|
||||
|
||||
string fullfilename( const string &t ){
|
||||
char buff[MAX_PATH+1],*p;
|
||||
GetFullPathName( t.c_str(),MAX_PATH,buff,&p );
|
||||
return string(buff);
|
||||
}
|
||||
|
||||
string filenamepath( const string &t ){
|
||||
char buff[MAX_PATH+1],*p;
|
||||
GetFullPathName( t.c_str(),MAX_PATH,buff,&p );
|
||||
if( !p ) return "";
|
||||
*p=0;return string(buff);
|
||||
}
|
||||
|
||||
string filenamefile( const string &t ){
|
||||
char buff[MAX_PATH+1],*p;
|
||||
GetFullPathName( t.c_str(),MAX_PATH,buff,&p );
|
||||
if( !p ) return "";
|
||||
return string( p );
|
||||
}
|
||||
|
||||
const int MIN_SIZE=256;
|
||||
|
||||
qstreambuf::qstreambuf(){
|
||||
buf=d_new char[MIN_SIZE];
|
||||
setg( buf,buf,buf );
|
||||
setp( buf,buf,buf+MIN_SIZE );
|
||||
}
|
||||
|
||||
qstreambuf::~qstreambuf(){
|
||||
delete buf;
|
||||
}
|
||||
|
||||
int qstreambuf::size(){
|
||||
return pptr()-gptr();
|
||||
}
|
||||
|
||||
char *qstreambuf::data(){
|
||||
return gptr();
|
||||
}
|
||||
|
||||
qstreambuf::int_type qstreambuf::underflow(){
|
||||
if( gptr()==egptr() ){
|
||||
if( gptr()==pptr() ) return traits_type::eof();
|
||||
setg( gptr(),gptr(),pptr() );
|
||||
}
|
||||
|
||||
return traits_type::to_int_type( *gptr() );
|
||||
}
|
||||
|
||||
qstreambuf::int_type qstreambuf::overflow( qstreambuf::int_type c ){
|
||||
if( c==traits_type::eof() ) return c;
|
||||
|
||||
if( pptr()==epptr() ){
|
||||
int sz=size();
|
||||
int n_sz=sz*2;if( n_sz<MIN_SIZE ) n_sz=MIN_SIZE;
|
||||
char *n_buf=d_new char[ n_sz ];
|
||||
memcpy( n_buf,gptr(),sz );
|
||||
delete buf;buf=n_buf;
|
||||
setg( buf,buf,buf+sz );
|
||||
setp( buf+sz,buf+sz,buf+n_sz );
|
||||
}
|
||||
|
||||
*pptr()=traits_type::to_char_type( c );
|
||||
pbump( 1 );return traits_type::not_eof( c );
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
# Microsoft Developer Studio Project File - Name="stdutil" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=stdutil - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "stdutil.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "stdutil.mak" CFG="stdutil - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "stdutil - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "stdutil - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "stdutil - Win32 Blitz3DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "stdutil - Win32 Blitz2DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "stdutil - Win32 Blitz3DEdu" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "stdutil - Win32 Blitz3DDemo" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "stdutil - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "stdutil - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# SUBTRACT CPP /Gy
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "stdutil - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "stdutil___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "stdutil___Win32_Blitz3DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "stdutil___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "stdutil___Win32_Blitz3DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "stdutil - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "stdutil___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "stdutil___Win32_Blitz2DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "stdutil___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "stdutil___Win32_Blitz2DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "stdutil - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "stdutil___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "stdutil___Win32_Blitz3DEdu"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "stdutil___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "stdutil___Win32_Blitz3DEdu"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /FD /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "stdutil - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "stdutil___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "stdutil___Win32_Blitz3DDemo"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "stdutil___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "stdutil___Win32_Blitz3DDemo"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /FD /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "stdutil - Win32 Release"
|
||||
# Name "stdutil - Win32 Debug"
|
||||
# Name "stdutil - Win32 Blitz3DRelease"
|
||||
# Name "stdutil - Win32 Blitz2DRelease"
|
||||
# Name "stdutil - Win32 Blitz3DEdu"
|
||||
# Name "stdutil - Win32 Blitz3DDemo"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\shareprot.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\shareprot.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\stdutil.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\stdutil.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
#ifndef STDUTIL_H
|
||||
#define STDUTIL_H
|
||||
|
||||
#pragma warning(disable:4786)
|
||||
|
||||
#include "../config/config.h"
|
||||
|
||||
/*
|
||||
#ifdef DEMO
|
||||
#include "shareprot.h"
|
||||
#endif
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef MEMDEBUG
|
||||
|
||||
void * _cdecl operator new( size_t size );
|
||||
void * _cdecl operator new[]( size_t size );
|
||||
void * _cdecl operator new( size_t size,const char *file,int line );
|
||||
void * _cdecl operator new[]( size_t size,const char *file,int line );
|
||||
void _cdecl operator delete( void *q );
|
||||
void _cdecl operator delete[]( void *q );
|
||||
void _cdecl operator delete( void *q,const char *file,int line );
|
||||
void _cdecl operator delete[]( void *q,const char *file,int line );
|
||||
#define d_new new( __FILE__,__LINE__ )
|
||||
|
||||
#else
|
||||
|
||||
#define d_new new
|
||||
|
||||
#endif
|
||||
|
||||
void trackmem( bool enable );
|
||||
void checkmem( std::ostream &out );
|
||||
|
||||
//some stuff that should be in std libs
|
||||
int atoi( const std::string &s );
|
||||
double atof( const std::string &s );
|
||||
std::string itoa( int n );
|
||||
std::string ftoa( float n );
|
||||
std::string tolower( const std::string &s );
|
||||
std::string toupper( const std::string &s );
|
||||
std::string fullfilename( const std::string &t );
|
||||
std::string filenamepath( const std::string &t );
|
||||
std::string filenamefile( const std::string &t );
|
||||
|
||||
//lazy version of auto_ptr
|
||||
template<class T>
|
||||
class a_ptr{
|
||||
public:
|
||||
a_ptr(T *t=0):t(t){}
|
||||
~a_ptr(){delete t;}
|
||||
a_ptr &operator=(T *t){this->t=t;return *this;}
|
||||
T &operator*()const{return *t;}
|
||||
T *operator->()const{return t;}
|
||||
operator T&()const{return *t;}
|
||||
operator T*()const{return t;}
|
||||
T *release(){ T *tt=t;t=0;return tt; }
|
||||
private:
|
||||
T *t;
|
||||
};
|
||||
|
||||
//Speed-up for SLOW sstream
|
||||
class qstreambuf : public std::streambuf{
|
||||
public:
|
||||
qstreambuf();
|
||||
~qstreambuf();
|
||||
int size(); //bytes unread
|
||||
char *data(); //start of bytes unread
|
||||
private:
|
||||
char *buf;
|
||||
int_type underflow();
|
||||
int_type overflow( int_type c );
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class pool{
|
||||
T *free;
|
||||
enum{ N=512 };
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef T value_type;
|
||||
pointer address( reference q )const{ return &q; }
|
||||
const_pointer address( const_reference q )const{ return &q; }
|
||||
pool():free(0){}
|
||||
pointer allocate( size_type n,const void *){
|
||||
clog<<"Allocating "<<n<<endl;
|
||||
if( n>1 ) return d_new T[n];
|
||||
if( !free ){
|
||||
free=(T*)d_new char[sizeof(T)*N];
|
||||
for( int k=0;k<N-1;++k ) *(T**)(free+k)=free+k+1;
|
||||
*(T**)(free+N-1)=0;
|
||||
}
|
||||
T *t=free;
|
||||
free=*(T**)t;
|
||||
return t;
|
||||
}
|
||||
void deallocate( pointer q,size_type n ){
|
||||
clog<<"Deallocating "<<n<<endl;
|
||||
while( n-->0 ){
|
||||
*(T**)q=free;
|
||||
*(T**)free=q;
|
||||
++q;
|
||||
}
|
||||
}
|
||||
void construct( pointer p,const T &q ){ new(p)T(q); }
|
||||
void destroy( pointer p ){ p->~T(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user