SIBCUtil.h

Go to the documentation of this file.
00001 //***************************************************************************************
00002 // File supervisor: Crosswalk team
00018 //***************************************************************************************
00019 
00020 //**************************************************************************************
00021 // Defines
00022 //**************************************************************************************
00023 #ifndef __CSIBCUtil_H__
00024 #define __CSIBCUtil_H__
00025 
00026 #if defined(unix) && (defined(WIN64) || defined(_WIN64) || defined(__x86_64))
00027 typedef unsigned int ULONG;
00028 typedef int LONG;
00029 #else
00030 typedef unsigned long ULONG;
00031 typedef long LONG;
00032 #endif
00033 
00034 #ifdef unix
00035   #include <string.h>
00036   #ifdef __APPLE__
00037     #include <math.h>
00038   #endif
00039 #endif
00040 
00041 #include <SIBCMath.h>
00042 
00043 #ifdef _WIN32
00044 #ifndef _XBOX
00045 #include <windows.h>
00046 #include <winuser.h>
00047 #else
00048 #include <xtl.h>
00049 #endif
00050 #endif
00051 
00052 //**************************************************************************************
00053 // Includes
00054 //**************************************************************************************
00055 #ifndef _WIN32_WCE
00056 #include <assert.h>
00057 #else
00058 #endif
00059 
00060 
00061 //**************************************************************************************
00062 // Typedefs
00063 //**************************************************************************************
00073 #ifndef _CUS_DLL
00074 typedef enum {
00075 
00076 
00077     SI_SUCCESS      =   0,      
00078 
00079     // general errors //
00080     SI_ERR_NONE     =   0,      
00081     SI_ERR_STATUS_MSG,          
00082     SI_ERR_MESSAGE_MSG,         
00083     SI_ERR_WARNING_MSG,         
00084     SI_ERR_ERROR_MSG,           
00085     SI_ERR_MODE_MSG,            
00086     SI_ERR_INTERNAL,            
00087     SI_ERR_NOTYETIMPLEMENTED,   
00088     SI_ERR_NOTSUPPORTED,        
00089 
00090     // argument check //
00091     SI_ERR_BAD_MDLTYPE,     
00092     SI_ERR_BAD_CHAPID,      
00093     SI_ERR_BAD_GROUPID,     
00094     SI_ERR_BAD_GROUPLIST,   
00095     SI_ERR_BAD_ELEMENT,     
00096     SI_ERR_BAD_DICTIONARY,  
00097     SI_ERR_BAD_RELID,       
00098     SI_ERR_BAD_ARGUMENT,    
00099     SI_ERR_BAD_DATABASE,    
00100     SI_ERR_BAD_RELNDX,      
00101     SI_ERR_BAD_MSMSH,       
00102     SI_ERR_BAD_MFACE,       
00103     SI_ERR_BAD_MPTCH,       
00104     SI_ERR_BAD_MSPLN,       
00105     SI_ERR_BAD_PARAM,       
00106     SI_ERR_BAD_NBPARAM,     
00107     SI_ERR_BAD_NOPARAM,     
00108     SI_ERR_BAD_CHP4REL,     
00109     SI_ERR_BAD_SHAPEID,     
00110     SI_ERR_CLS_NOMODEL,     
00111     SI_ERR_LAT_NOMODEL,     
00112 
00113     // relations & rel resources //
00114     SI_ERR_RELRSRC_CANTOPEN,    
00115     SI_ERR_RELRSRC_INVGRP,      
00116     SI_ERR_RELRSRC_INVCHP,      
00117     SI_ERR_RELPAIR_CANTADD,     
00118     SI_ERR_RELPAIR_CANTDEL,     
00119     SI_ERR_REL_CANTDEL,         
00120 
00121     // dictionary //
00122     SI_ERR_ELEM_NOTFOUND,   
00123     SI_ERR_NAME_DUPL,       
00124     SI_ERR_NAME_FORMAT,     
00125 
00126     // file access //
00127     SI_ERR_DB_NOTFOUND,     
00128     SI_ERR_DB_INVALID,      
00129     SI_ERR_DB_CANTCREATE,   
00130     SI_ERR_DB_CANTDELETE,   
00131     SI_ERR_DBDELETE,        
00132     SI_ERR_ACCESS_CANTSET,  
00133     SI_ERR_SCENE_CANTREAD,  
00134     SI_ERR_SCENE_CANTWRITE, 
00135     SI_ERR_SCENE_CANTDEL,   
00136     SI_ERR_ELEM_CANTREAD,   
00137     SI_ERR_ELEM_CANTWRITE,  
00138     SI_ERR_SAVE_NOTROOT,    
00139     SI_ERR_NOVERS_FOUND,    
00140 
00141     // Data access and Conversion //
00142     SI_ERR_NUM_VERTICES,        
00143     SI_ERR_SHAPE_VERTICES,      
00144     SI_ERR_TOO_FEW_VERTICES,    
00145     SI_ERR_TOO_MANY_VERTICES,   
00146     SI_ERR_NULL_TRANSFO,        
00147     SI_ERR_NULL_VECTOR,         
00148     SI_ERR_BAD_COORDSYS,        
00149     SI_ERR_BAD_VNDX,            
00150     SI_ERR_CHAPNOTFOUND,        
00151     SI_ERR_FCVNOTFOUND,         
00152     SI_ERR_NOT_TRIANGULATED,    
00153 
00154     // Update list and animation //
00155     SI_ERR_CYCLE_DETECTED,      
00156 
00157     // Dynalink library //
00158     SI_ERR_DYNALINK_NOT_LOADED,     
00159     SI_ERR_DYNALINK_NOT_RESOLVED,   
00160     SI_ERR_DYNALINK_NOT_UNLOADED,   
00161 
00162     // Custom Value //
00163     SI_ERR_CUSVAL_SYMBOL_NOT_FOUND, 
00164     SI_ERR_CUSVAL_INCORRECT_TYPE,   
00165     SI_ERR_CUSVAL_BUFFER_TOO_SMALL, 
00166 
00167     // SAAPHIRE stuff //
00168     SI_ERR_ALLOC_PROBLEM,       
00169     SI_ERR_INVALID_SCENE,       
00170     SI_ERR_ELEM_UNSCENE,        
00171     SI_ERR_ELEM_TYPE,           
00172     SI_ERR_ELEM_ROOT,           
00173     SI_ERR_WRONG_COUNT,         
00174     SI_ERR_INVALID_LTYPE,       
00175     SI_ERR_NO_RESET,            
00176     SI_ERR_INVALID_SELEM,       
00177     SI_ERR_BAD_MATERIAL,        
00178     SI_ERR_INVALID_TESSELATION, 
00179     SI_ERR_NON_TESSELATABLE,    
00180     SI_ERR_INVALID_MODEL_DATA,  
00181     SI_ERR_NO_MATERIAL,         
00182     SI_ERR_NO_TEXTURE,          
00183     SI_ERR_ELEM_NOT_LEAF_NODE,  
00184     SI_ERR_ELEM_CANTDEL,        
00185     SI_ERR_FCURVE_EXISTS,       
00186     SI_ERR_ELEM_CHNROOT,        
00187     SI_ERR_ELEM_EFFECTOR,       
00188     SI_ERR_GOAL_NOT_SET,        
00189     SI_ERR_USERDATA_EXISTS,     
00190     SI_ERR_INVALID_INDEX,       
00191 
00192     // Opensyst //
00193     SI_ERR_CUS_SECOND_SYMBOL,   
00194     SI_ERR_CUS_NO_SYMBOL_NAME,  
00195 
00196     // DSO's //
00197     SI_ERR_CUSTOM_FATAL,        
00198 
00199     // DLL's //
00200     SI_ERR_UNFOUND_GLBSYMB_TAB, 
00201 
00202     // Graphic //
00203     SI_ERR_STOP,        
00204     SI_ERR_TXT_NAME,    
00205     SI_ERR_NO_CAM,      
00206 
00207     // Reason why a transformation is not applicable to a model //
00208     SI_ERR_TRANSFO_METASYSTEM,      
00209     SI_ERR_TRANSFO_PATCHDEFORM,     
00210     SI_ERR_TRANSFO_SPLINEDEFORM,    
00211     SI_ERR_SCAL_CHAIN,              
00212     SI_ERR_SCAL_CNSSCL,             
00213     SI_ERR_ROT_JOINT,               
00214     SI_ERR_ROT_CHNROOT,             
00215     SI_ERR_ROT_CNSORI,              
00216     SI_ERR_TRANS_CHNROOT,           
00217     SI_ERR_TRANS_JOINT,             
00218     SI_ERR_TRANS_DYNLEAF,           
00219     SI_ERR_TRANS_MAINGLOBENV,       
00220     SI_ERR_TRANS_CONSTRAINT,        
00221 
00222     // Additional SAAPHIRE error codes //
00223     SI_ERR_SUBELEM_TOTAL_FAILURE,   
00224     SI_ERR_SOFTIMAGE_TOO_OLD,       
00225     SI_ERR_SAAPHIRE_TOO_OLD,        
00226     SI_ERR_SAA_TOO_OLD_FOR_EFFECT,  
00227     SI_ERR_FILE_EXISTS,             
00228     SI_ERR_UNRELATED_T2D,           
00229     SI_ERR_INCOMPATIBLE_T2DMAP,     
00230     SI_ERR_SHADER_EXISTS,           
00231     SI_ERR_INCOMPAT_MAP_METHOD,     
00232     SI_ERR_MODEL_NO_SHAPES,         
00233     SI_ERR_CLUSTER_NO_KEYS,         
00234 
00235     // DSO's (no status bar message) //
00236     SI_ERR_CUSTOM_FATAL_NOMSG,      
00237     SI_ERR_NO_FCV_EDITOR,           
00238 
00239     // Render errors //
00240     SI_ERR_RENDER_WARNING,          
00241     SI_ERR_RENDER_ERROR,            
00242 
00243     // physical property Error //
00244     SI_ERR_MODEL_NO_PHYSPROPS,      
00245 
00246     // dialog errors //
00247     SI_ERR_EFFECT_NODG,     
00248     SI_ERR_DG_NOTFOUND,     
00249 
00250     // more render errors //
00251     SI_ERR_RENDER_VOLUNTARYEXIT,    
00252 
00253     // Audio support //
00254     SI_ERR_AUDIO_DEVICEINUSE,   
00255     SI_ERR_AUDIO_INVALIDFORMAT, 
00256     SI_ERR_AUDIO_INACTIVE,      
00257     SI_ERR_FILENOTFOUND,        
00258     SI_ERR_AUDIO_INVALIDTRACK,  
00259     SI_ERR_FILEPASSEDEOF,       
00260 
00261     // Action Support //
00262     SI_ERR_NO_ACTION,               
00263     SI_ERR_MARKER_NOTFOUND,         
00264     SI_ERR_ACTIONMARKERS_OVERLAP,   
00265 
00266     // More audio errors //
00267     SI_ERR_AUDIO_FILENOTSET,        
00268     SI_ERR_AUDIO_FILEALREADYSET,    
00269     SI_ERR_AUDIO_MIXINGNOTENABLED,  
00270 
00271     // Licensing //
00272     SI_ERR_LIC_INVALID_HANDLE,  
00273     SI_ERR_LIC_INVALID_ARGS,    
00274     SI_ERR_LIC_CHECKOUT,        
00275     SI_ERR_NUM,                 
00276 
00277     // Softimage specific
00278     SI_FILE_NOT_FOUND,          
00279     SI_NO_AVAILABLE_DRIVER,     
00280     //Image Lib error
00281     SI_IMAGE_BAD_FORMAT     
00282 
00283 } eSI_Error;
00284 
00288 typedef int SI_Error;
00292 #else
00293 
00294 //To be cross compatible with SAAphire
00295 #include <saa.h>
00296 
00297 #define SI_FILE_NOT_FOUND (SI_ERR_NUM + 1)
00298 #define SI_NO_AVAILABLE_DRIVER (SI_FILE_NOT_FOUND + 1)
00299 #endif
00300 
00301 
00306 #ifndef TRUE
00307 #define TRUE        1       
00308 #endif
00309 
00310 #ifndef FALSE
00311 #define FALSE       0       
00312 #endif
00313 
00314 #define SI_TRUE TRUE        
00315 #define SI_FALSE FALSE      
00317 // Already documented in SIBCMathLib.h
00318 #ifndef NULL
00319 #define NULL 0  
00320 #endif
00321 
00329 #define SI_Bool     unsigned short      
00330 #define SI_Byte     char                
00331 #define SI_UByte    unsigned char       
00332 #define SI_Short    short               
00333 #define SI_UShort   unsigned short      
00334 #define SI_Int      int                 
00335 #define SI_UInt     unsigned int        
00336 #define SI_Float    float               
00337 #define SI_Double   double              
00338 #define SI_Long     int                 
00339 #define SI_Void     void                
00340 #define SI_ULong    unsigned int        
00341 typedef SI_Float    SI_Matrix[4][4];    
00345 // CustomPset Data Type String. These are not used in the FTK.
00346 #define SI_CUSTOMPSET_PCHAR "Text"
00347 #define SI_CUSTOMPSET_BOOL  "Boolean"
00348 #define SI_CUSTOMPSET_INT   "Integer"
00349 #define SI_CUSTOMPSET_UBYTE "Small Integer Number"
00350 #define SI_CUSTOMPSET_DOUBLE    "Floating Point Number"
00351 
00352 
00358 #define SI_VT_BOOL      0   
00359 #define SI_VT_BYTE      1   
00360 #define SI_VT_UBYTE     2   
00361 #define SI_VT_SHORT     3   
00362 #define SI_VT_USHORT    4   
00363 #define SI_VT_INT       5   
00364 #define SI_VT_UINT      6   
00365 #define SI_VT_FLOAT     7   
00366 #define SI_VT_DOUBLE    8   
00367 #define SI_VT_LONG      9   
00368 #define SI_VT_ULONG     10  
00370 #define SI_VT_PBOOL     11  
00371 #define SI_VT_PBYTE     12  
00372 #define SI_VT_PUBYTE    13  
00373 #define SI_VT_PSHORT    14  
00374 #define SI_VT_PUSHORT   15  
00375 #define SI_VT_PINT      16  
00376 #define SI_VT_PUINT     17  
00377 #define SI_VT_PFLOAT    18  
00378 #define SI_VT_PDOUBLE   19  
00379 #define SI_VT_PLONG     20  
00380 #define SI_VT_PULONG    21  
00382 #define SI_VT_PCHAR     22  
00383 #define SI_VT_PPCHAR    23  
00385 #define SI_VT_PVOID     24  
00395 #define SI_TT_NONE      0   
00396 #define SI_TT_POSITION  1   
00397 #define SI_TT_NORMAL    2   
00398 #define SI_TT_TEXCOORD  3   
00399 #define SI_TT_COLOR     4   
00400 #define SI_TT_TRANSFO   5   
00401 #define SI_TT_INTEGER   6   
00402 #define SI_TT_FLOAT     7   
00403 #define SI_TT_TINYFLOAT 8   
00412 struct TinyVariant {
00413 
00414     TinyVariant() { memset(this,0,sizeof(TinyVariant));};
00415     TinyVariant(SI_Int v,SI_Int t,SI_Int e )
00416     {
00417         variantType = v;
00418         tweakType = t;
00419         numElems = e;
00420     };
00421 
00422     SI_Int          variantType;    
00423     SI_Int          tweakType;      
00424     SI_Int          numElems;       
00429     union {
00430         SI_Bool     boolVal;    
00431         SI_Byte     bVal;       
00432         SI_UByte    ubVal;      
00433         SI_Short    sVal;       
00434         SI_UShort   usVal;      
00435         SI_Int      nVal;       
00436         SI_UInt     unVal;      
00437         SI_Float    fVal;       
00438         SI_Double   dVal;       
00439         SI_Long     lVal;       
00440         SI_ULong    ulVal;      
00442         SI_Bool     *p_boolVal; 
00443         SI_Byte     *p_bVal;    
00444         SI_UByte    *p_ubVal;   
00445         SI_Short    *p_sVal;    
00446         SI_UShort   *p_usVal;   
00447         SI_Int      *p_nVal;    
00448         SI_UInt     *p_unVal;   
00449         SI_Float    *p_fVal;    
00450         SI_Double   *p_dVal;    
00451         SI_Long     *p_lVal;    
00452         SI_ULong    *p_ulVal;   
00454         // We used char instead of SI_Char because SI_Char is plateform dependant.
00455         char        *p_cVal;    
00456         char        **pp_cVal;  
00458         SI_Void     *p_voidVal; 
00459     };
00460 };
00461 
00462 typedef TinyVariant SI_TinyVariant; 
00465 //**************************************************************************************
00466 // Macros
00467 //**************************************************************************************
00469 //
00470 #if defined(unix)
00471 
00472 #include <stdio.h>
00473 #include <stdlib.h>
00474 #include <stdarg.h>
00475 #ifndef __APPLE__
00476 #include <malloc.h>
00477 #else
00478 #include <sys/malloc.h>
00479 #endif
00480 
00481 #ifdef __XSI_MAINLIB_
00482 #define XSIEXPORT
00483 #define XSITEMPLATEEXP
00484 #endif
00485 
00486 #ifdef __XSI_PLUGIN_
00487 #define XSIEXPORT
00488 #define XSITEMPLATEEXP
00489 #endif
00490 
00491 #ifdef __XSI_APPLICATION_
00492 #ifdef XSI_STATIC_LINK
00493 #define XSIEXPORT
00494 #define XSITEMPLATEEXP
00495 #else
00496 #define XSIEXPORT
00497 #define XSITEMPLATEEXP
00498 #endif
00499 #endif
00500 
00501 #define XSICOREEXPORT
00502 
00503 #define _SI_INITCORE
00504 #define _SI_EXITCORE
00505 
00506 // Memory stuff
00507 #define _SI_MSIZE( x )          0
00508 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00509 
00510 // character string format
00511 #define SI_Char         char
00512 #define _SI_STRCMP      strcmp
00513 #define _SI_STRNCMP     strncmp
00514 #define _SI_STRICMP     strcasecmp
00515 #define _SI_STRDUP      si_strdup
00516 #define _SI_BSTRDUP     si_bstrdup
00517 #define _SI_STRCPY      strcpy
00518 #define _SI_STRNCPY     strncpy
00519 #define _SI_STRCAT      strcat
00520 #define _SI_SPRINTF     sprintf
00521 #define _SI_STRLEN      strlen
00522 #define _SI_TEXT(quote) quote
00523 #define _SI_PRINTF      CSIBCUtil::printf
00524 #define _SI_RAND()      rand()
00525 #define _SI_STRTOK      strtok
00526 #define _SI_STRSTR      strstr
00527 #define _SI_STRCHR      strchr
00528 #define _SI_STRRCHR     strrchr
00529 #define _SI_SPLITPATH   si_splitpath
00530 #define _SI_ATOI        atoi
00531 #define _SI_ATOF        atof
00532 
00533 #ifndef __APPLE__
00534 //Math Stuff
00535 #define _SI_SQRT        sqrt
00536 #define _SI_SQRTF       sqrtf
00537 #define _SI_ASIN        asin
00538 #define _SI_ASINF       asinf
00539 #define _SI_ACOS        acos
00540 #define _SI_ACOSF       acosf
00541 #define _SI_FLOOR       floor
00542 #define _SI_FLOORF      floorf
00543 #define _SI_COS         cos
00544 #define _SI_COSF        cosf
00545 #define _SI_SIN         sin
00546 #define _SI_SINF        sinf
00547 #define _SI_TAN         tan
00548 #define _SI_TANF        tanf
00549 #define _SI_ATANF       atanf
00550 #define _SI_ATAN        atan
00551 #else
00552 //Math Stuff
00553 #define _SI_SQRT                sqrt
00554 #define _SI_SQRTF               sqrt
00555 #define _SI_ASIN                asin
00556 #define _SI_ASINF               asin
00557 #define _SI_ACOS                acos
00558 #define _SI_ACOSF               acos
00559 #define _SI_FLOOR               floor
00560 #define _SI_FLOORF              floor
00561 #define _SI_COS                 cos
00562 #define _SI_COSF                cos
00563 #define _SI_SIN                 sin
00564 #define _SI_SINF                sin
00565 #define _SI_TAN                 tan
00566 #define _SI_TANF                tan
00567 #define _SI_ATANF               atan
00568 #define _SI_ATAN                atan
00569 #endif
00570 
00571 
00572 //File stuff
00573 #define __SI_FILE       FILE *
00574 #define __SI_FILE_MODE  SI_Char *
00575 #define __SI_FILE_NULL  (NULL)
00576 #define __SI_FILE_READ_TEXT "r"
00577 #define __SI_FILE_READ_BINARY "rb"
00578 #define __SI_FILE_WRITE_TEXT    "w"
00579 #define __SI_FILE_WRITE_BINARY "wb"
00580 #define __SI_FILE_SET SEEK_SET
00581 #define __SI_FILE_CUR SEEK_CUR
00582 #define __SI_FILE_END SEEK_END
00583 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00584 #define __SI_FOPEN( name, mode )        fopen( name, mode )
00585 #define __SI_FCLOSE( x )        fclose( x )
00586 #define __SI_FREAD( a, b, c, d ) fread( a, b, c, d )
00587 #define __SI_FWRITE( a, b, c, d ) fwrite( a, b, c, d )
00588 #define __SI_FPRINTF( a, b ) fprintf( a, b )
00589 #define __SI_FSEEK( ptr, count, type ) fseek( ptr, count, type )
00590 #define __SI_FTELL( ptr ) ftell( ptr )
00591 #define __SI_FGETC( fp ) ::fgetc(fp)
00592 #define __SI_FEOF( x )   feof(x)
00593 #define __SI_FERROR( x ) (ferror(x))
00594 #define __SI_FFLUSH( x ) (fflush(x))
00595 #define __SI_UNGETC( ch, fp )  (ungetc(ch,fp))
00596 
00597 //Assertion
00598 #ifdef _DEBUG
00599 #define _SI_ASSERT(x) assert(x)
00600 #else
00601 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
00602 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
00603 #define _SI_ASSERT(exp)
00604 #endif
00605 
00606 //Loadable module
00607 #define _SI_LIBHANDLE int
00608 
00609 // Local Memory Allocators
00610 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
00611 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
00612 
00613 #if !defined(MAX_PATH)
00614 #define MAX_PATH PATH_MAX
00615 #endif
00616 
00617 #endif
00618 
00619 //
00621 //
00622 //
00624 //
00625 
00626 #if ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX)
00627 
00628 #include <string.h>
00629 #include <stdio.h>
00630 #include <stdlib.h>
00631 #include <stdarg.h>
00632 #include <malloc.h>
00633 
00634 #ifdef __XSI_MAINLIB_
00635 #define XSIEXPORT _declspec(dllexport)
00636 #define XSITEMPLATEEXP
00637 #endif
00638 
00639 #ifdef __XSI_PLUGIN_
00640 #define XSIEXPORT _declspec(dllexport)
00641 #define XSITEMPLATEEXP
00642 #endif
00643 
00644 #ifdef __XSI_APPLICATION_
00645 #ifdef XSI_STATIC_LINK
00646 #define XSIEXPORT
00647 #define XSITEMPLATEEXP
00648 #else
00649 #define XSIEXPORT _declspec(dllimport)
00650 #define XSITEMPLATEEXP extern
00651 #endif
00652 #endif
00653 
00654 #ifndef XSICOREEXPORT
00655 # if ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX)
00656 #  ifdef XSICORE_IMPL
00657 #   define XSICOREEXPORT __declspec(dllexport)
00658 #  elif defined(XSICORE_STATIC)
00659 #   define XSICOREEXPORT
00660 #  else
00661 #   define XSICOREEXPORT __declspec(dllimport)
00662 #  endif
00663 # else
00664 #  define XSICOREEXPORT
00665 # endif
00666 #endif
00667 
00668 #define _SI_INITCORE
00669 #define _SI_EXITCORE
00670 
00671 // Memory stuff
00672 #define _SI_MSIZE( x )          _msize( x )
00673 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00674 
00675 // character string format
00676 #define SI_Char         char
00677 #define _SI_STRCMP      strcmp
00678 #define _SI_STRNCMP     strncmp
00679 #define _SI_STRICMP     stricmp
00680 #define _SI_STRDUP      si_strdup
00681 #define _SI_BSTRDUP     si_bstrdup
00682 #define _SI_STRCPY      strcpy
00683 #define _SI_STRNCPY     strncpy
00684 #define _SI_STRCAT      strcat
00685 #define _SI_SPRINTF     sprintf
00686 #define _SI_STRLEN      strlen
00687 #define _SI_TEXT(quote) quote
00688 #define _SI_PRINTF      CSIBCUtil::printf
00689 #define _SI_RAND()      rand()
00690 #define _SI_STRTOK      strtok
00691 #define _SI_STRSTR      strstr
00692 #define _SI_STRCHR      strchr
00693 #define _SI_STRRCHR     strrchr
00694 #define _SI_SPLITPATH   _splitpath
00695 #define _SI_ATOI        atoi
00696 #define _SI_ATOF        atof
00697 
00698 
00699 //Math Stuff
00700 #define _SI_SQRT        sqrt
00701 #define _SI_SQRTF       sqrtf
00702 #define _SI_ASIN        asin
00703 #define _SI_ASINF       asinf
00704 #define _SI_ACOS        acos
00705 #define _SI_ACOSF       acosf
00706 #define _SI_FLOOR       floor
00707 #define _SI_FLOORF      floorf
00708 #define _SI_COS         cos
00709 #define _SI_COSF        cosf
00710 #define _SI_SIN         sin
00711 #define _SI_SINF        sinf
00712 #define _SI_TAN         tan
00713 #define _SI_TANF        tanf
00714 #define _SI_ATANF       atanf
00715 #define _SI_ATAN        atan
00716 
00717 //File stuff
00718 #define __SI_FILE       FILE *
00719 #define __SI_FILE_MODE  SI_Char *
00720 #define __SI_FILE_NULL  (NULL)
00721 #define __SI_FILE_READ_TEXT "r"
00722 #define __SI_FILE_READ_BINARY "rb"
00723 #define __SI_FILE_WRITE_TEXT    "w"
00724 #define __SI_FILE_WRITE_BINARY "wb"
00725 #define __SI_FILE_SET SEEK_SET
00726 #define __SI_FILE_CUR SEEK_CUR
00727 #define __SI_FILE_END SEEK_END
00728 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00729 #define __SI_FOPEN( name, mode )        fopen( name, mode )
00730 #define __SI_FCLOSE( x )        fclose( x )
00731 #define __SI_FREAD( a, b, c, d ) fread( a, b, c, d )
00732 #define __SI_FWRITE( a, b, c, d ) fwrite( a, b, c, d )
00733 #define __SI_FPRINTF( a, b ) fprintf( a, b )
00734 #define __SI_FSEEK( ptr, count, type ) fseek( ptr, count, type )
00735 #define __SI_FTELL( ptr ) ftell( ptr )
00736 #define __SI_FGETC( fp ) ::fgetc(fp)
00737 #define __SI_FEOF( x )   feof( x )
00738 #define __SI_FERROR( x ) (ferror(x))
00739 #define __SI_FFLUSH( x ) (fflush(x))
00740 #define __SI_UNGETC( ch, fp )  (ungetc(ch,fp))
00741 
00742 
00743 //Assertion
00744 #ifdef _DEBUG
00745 #define _SI_ASSERT(x) assert(x)
00746 #else
00747 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
00748 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
00749 #define _SI_ASSERT(exp)
00750 #endif
00751 
00752 //Loadable module
00753 #define SI_INVALID_LIB_HANDLE NULL
00754 #define _SI_LIBHANDLE   HMODULE
00755 #define _SI_LOADMODULE  LoadLibrary
00756 #define _SI_UNLOADMODULE( x )  FreeLibrary( x )
00757 #define _SI_LOADFUNCTION( HAND, NAME ) GetProcAddress( HAND, NAME )
00758 
00759 // Local Memory Allocators
00760 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
00761 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
00762 
00763 #endif
00764 
00765 //
00767 //
00768 
00769 //
00771 //
00772 #ifdef _WIN32_WCE
00773 
00774 #include <string.h>
00775 #include <stdio.h>
00776 #include <stdlib.h>
00777 #include <stdarg.h>
00778 
00779 //WINDOWS CE
00780 #define _SI_ASSERT(x)
00781 #include <tchar.h>
00782 #include <winbase.h>
00783 
00784 // Memory stuff
00785 #define _SI_MSIZE( x )          0
00786 #define _SI_MEMCPY( x, y, z )   0
00787 
00788 // character string format
00789 #define SI_Char         wchar_t
00790 #define _SI_STRCMP      wcscmp
00791 #define _SI_STRNCMP     wcsncmp
00792 #define _SI_STRICMP     wcsicmp
00793 #define _SI_STRCPY      lstrcpy
00794 #define _SI_STRNCPY     wsncpy
00795 #define _SI_STRDUP      si_strdup
00796 #define _SI_BSTRDUP     si_bstrdup
00797 #define _SI_STRCAT      wcscat
00798 #define _SI_SPRINTF     swprintf
00799 #define _SI_FPRINTF     fprintf
00800 #define _SI_STRLEN      wcslen
00801 #define _SI_TEXT(quote) __TEXT(quote)
00802 #define _SI_ATOI        _wtoi
00803 
00804 #define _SI_PRINTF      NKDbgPrintfW
00805 #define _SI_RAND()      rand()
00806 #define _SI_STRTOK      wcstok
00807 #define _SI_STRSTR      wcsstr
00808 #define _SI_STRCHR      wcschr
00809 #define _SI_STRRCHR     wcsrchr
00810 #define _SI_SPLITPATH   _wsplitpath
00811 
00812 extern  SI_Char         *_SI_ENDCHAR;
00813 #define _SI_ATOF(x)     wcstod(x, &_SI_ENDCHAR)
00814 
00815 #define _SI_SQRT        sqrt
00816 #define _SI_SQRTF       (SI_Float)sqrt
00817 #define _SI_ASIN        asin
00818 #define _SI_ASINF       (SI_Float)asin
00819 #define _SI_ACOS        acos
00820 #define _SI_ACOSF       (SI_Float)acos
00821 #define _SI_FLOOR       floor
00822 #define _SI_FLOORF      (SI_Float)floor
00823 #define _SI_COS         cos
00824 #define _SI_COSF        (SI_Float)cos
00825 #define _SI_SIN         sin
00826 #define _SI_SINF        (SI_Float)sin
00827 #define _SI_TAN         tan
00828 #define _SI_TANF        (SI_Float)tan
00829 
00830 // Some PPSH helper functions.
00831 extern "C"
00832 {
00833     int U_ropen(const WCHAR *, UINT);
00834     int U_rread(int, BYTE *, int);
00835     int U_rclose(int);
00836 }
00837 
00838 
00839 #define __SI_FILE               int
00840 #define __SI_FILE_MODE          int
00841 #define __SI_FILE_NULL          0
00842 #define __SI_FILE_READ_TEXT     0x00010002
00843 #define __SI_FILE_READ_BINARY   0x00010002
00844 #define __SI_FOPEN( name, mode )    U_ropen( name, mode)
00845 #define __SI_FCLOSE( x )            U_rclose( x )
00846 #define __SI_FREAD(a,b,c,d)     U_rread( d, (BYTE *) a, b * c)
00847 #define __SI_FEOF( x )           0
00848 #define __SI_IS_FILE_MODE( a, b ) a == b
00849 
00850 #endif
00851 
00852 //
00854 //
00855 
00856 //
00858 //
00859 #ifdef  _XBOX
00860 #include <string.h>
00861 #include <stdio.h>
00862 #include <stdlib.h>
00863 #include <stdarg.h>
00864 #include <malloc.h>
00865 
00866 
00867 #ifdef __XSI_MAINLIB_
00868 #define XSIEXPORT       _declspec(dllexport)
00869 #endif
00870 
00871 #ifdef __XSI_PLUGIN_
00872 #define XSIEXPORT _declspec(dllexport)
00873 #define XSITEMPLATEEXP
00874 #endif
00875 
00876 #ifdef __XSI_APPLICATION_
00877 #ifdef XSI_STATIC_LINK
00878 #define XSIEXPORT
00879 #undef XSICOREEXPORT
00880 #define XSICOREEXPORT
00881 #define XSITEMPLATEEXP
00882 #else
00883 #define XSIEXPORT _declspec(dllimport)
00884 #define XSICOREEXPORT   _declspec(dllimport)
00885 #define XSITEMPLATEEXP extern
00886 #endif
00887 #endif
00888 
00889 #define _SI_INITCORE
00890 #define _SI_EXITCORE
00891 
00892 // Memory stuff
00893 #define _SI_MSIZE( x )          _msize( x )
00894 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00895 
00896 // character string format
00897 #define SI_Char         char
00898 #define _SI_STRCMP      strcmp
00899 #define _SI_STRNCMP     strncmp
00900 #define _SI_STRICMP     stricmp
00901 #define _SI_STRDUP      si_strdup
00902 #define _SI_BSTRDUP     si_bstrdup
00903 #define _SI_STRCPY      strcpy
00904 #define _SI_STRNCPY     strncpy
00905 #define _SI_STRCAT      strcat
00906 #define _SI_SPRINTF     sprintf
00907 #define _SI_STRLEN      strlen
00908 #define _SI_TEXT(quote) quote
00909 #define _SI_PRINTF      CSIBCUtil::printf
00910 #define _SI_RAND()      rand()
00911 #define _SI_STRTOK      strtok
00912 #define _SI_STRSTR      strstr
00913 #define _SI_STRCHR      strchr
00914 #define _SI_STRRCHR     strrchr
00915 #define _SI_SPLITPATH   _splitpath
00916 #define _SI_ATOI        atoi
00917 #define _SI_ATOF        atof
00918 
00919 //Math Stuff
00920 #define _SI_SQRT        sqrt
00921 #define _SI_SQRTF       sqrtf
00922 #define _SI_ASIN        asin
00923 #define _SI_ASINF       asinf
00924 #define _SI_ACOS        acos
00925 #define _SI_ACOSF       acosf
00926 #define _SI_FLOOR       floor
00927 #define _SI_FLOORF      floorf
00928 #define _SI_COS         cos
00929 #define _SI_COSF        cosf
00930 #define _SI_SIN         sin
00931 #define _SI_SINF        sinf
00932 #define _SI_TAN         tan
00933 #define _SI_TANF        tanf
00934 #define _SI_ATANF       atanf
00935 #define _SI_ATAN        atan
00936 
00937 typedef FILE* (*_XBOX_FOPEN_FNC)    ( char * filename, char* mode );
00938 typedef int (*_XBOX_FCLOSE_FNC) ( FILE* fdesc );
00939 typedef int (*_XBOX_FREAD_FNC)  ( void *result, int size, int count, FILE* );
00940 typedef int (*_XBOX_FWRITE_FNC) ( void *data, int size, int count, FILE* );
00941 typedef int (*_XBOX_FSEEK_FNC)  ( FILE*, LONG count, int mode );
00942 typedef int (*_XBOX_FTELL_FNC)  ( FILE* );
00943 typedef int (*_XBOX_FEOF_FNC)   ( FILE* );
00944 typedef int (*_XBOX_FGETC_FNC)  ( FILE* );
00945 
00946 
00947 FILE*   XBOXFileOpen ( char *filename , char* mode );
00948 int XBOXFileClose ( FILE* );
00949 int XBOXFileRead ( void *result, int size, int count, FILE* );
00950 int XBOXFileWrite ( void *data, int size, int count, FILE* );
00951 int XBOXFileSeek ( FILE*, LONG count, int mode );
00952 int XBOXFileTell ( FILE* );
00953 int XBOXFileEOF ( FILE* fdesc );
00954 int XBOXFileGETC ( FILE* fdesc );
00955 
00956 //File stuff
00957 #define __SI_FILE       FILE *
00958 #define __SI_FILE_MODE  SI_Char *
00959 #define __SI_FILE_NULL  (NULL)
00960 #define __SI_FILE_READ_TEXT "r"
00961 #define __SI_FILE_READ_BINARY "rb"
00962 #define __SI_FILE_WRITE_TEXT    "w"
00963 #define __SI_FILE_WRITE_BINARY "wb"
00964 #define __SI_FILE_SET SEEK_SET
00965 #define __SI_FILE_CUR SEEK_CUR
00966 #define __SI_FILE_END SEEK_END
00967 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00968 #define __SI_FOPEN( name, mode )    XBOXFileOpen( name, mode )
00969 #define __SI_FCLOSE( x )        XBOXFileClose( x )
00970 #define __SI_FREAD( a, b, c, d )    XBOXFileRead( a, b, c, d )
00971 #define __SI_FWRITE( a, b, c, d )   XBOXFileWrite( a, b, c, d )
00972 #define __SI_FPRINTF( a, b ) (0)
00973 #define __SI_FSEEK( ptr, count, type ) XBOXFileSeek( ptr, count, type )
00974 #define __SI_FTELL( ptr ) XBOXFileTell( ptr )
00975 #define __SI_FGETC( fp ) XBOXFileGETC(fp)
00976 #define __SI_FEOF( x )   XBOXFileEOF( x )
00977 #define __SI_FERROR( x ) (0)
00978 #define __SI_FFLUSH( x ) (0)
00979 
00980 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, __SI_FILE x );
00981 
00982 #define __SI_UNGETC( ch, fp )  (0)
00983 
00984 //Assertion
00985 #ifdef _DEBUG
00986 #define _SI_ASSERT(x) assert(x)
00987 #else
00988 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
00989 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
00990 #define _SI_ASSERT(exp)
00991 #endif
00992 
00993 //Loadable module
00994 #define SI_INVALID_LIB_HANDLE NULL
00995 #define _SI_LIBHANDLE   HMODULE
00996 #define _SI_LOADMODULE  LoadLibrary
00997 #define _SI_UNLOADMODULE( x )  FreeLibrary( x )
00998 #define _SI_LOADFUNCTION( HAND, NAME ) GetProcAddress( HAND, NAME )
00999 
01000 // Local Memory Allocators
01001 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
01002 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
01003 #endif
01004 
01005 
01006 //
01008 //
01009 #if defined( _PSX2 ) || defined( __MWERKS__ )
01010 
01011 #include <eekernel.h>
01012 #include <sifdev.h>
01013 #include <eeregs.h>
01014 #include <eetypes.h>
01015 #include <stdio.h>
01016 #include <string.h>
01017 #include <stdlib.h>
01018 #include <SIPS2Comm.h>
01019 
01020 //#include "SIPS2DisplayDriverSwitch.h"
01021 
01022 //#include <sys/types.h>
01023 //#include <fcntl.h>
01024 
01025 #ifdef __XSI_MAINLIB_
01026 #define XSIEXPORT
01027 #define XSITEMPLATEEXP
01028 #endif
01029 
01030 #ifdef __XSI_PLUGIN_
01031 #define XSIEXPORT
01032 #define XSITEMPLATEEXP
01033 #endif
01034 
01035 #ifdef __XSI_APPLICATION_
01036 #ifdef XSI_STATIC_LINK
01037 #define XSIEXPORT
01038 #define XSITEMPLATEEXP
01039 #else
01040 #define XSIEXPORT
01041 #define XSITEMPLATEEXP
01042 #endif
01043 #endif
01044 
01045 #ifndef XSICOREEXPORT
01046 #define XSICOREEXPORT
01047 #endif
01048 
01049 #ifndef XSIEXPORT
01050 #define XSIEXPORT
01051 #endif
01052 
01053 #ifndef min
01054 # define min(a,b) ((a) < (b) ? (a) : (b))
01055 #endif
01056 
01057 #ifndef max
01058 # define max(a,b) ((a) > (b) ? (a) : (b))
01059 #endif
01060 
01061 #ifndef _PSX2_FILEIO_NATIVE
01062 #define _PSX2_FILEIO_NATIVE
01063 #endif
01064 
01065 //predefinition
01066 #ifdef __cplusplus
01067 extern "C"
01068 {
01069 #endif
01070     int open( const char *, int );
01071     int close( int );
01072 //  off_t lseek( int fildes, off_t offset, int whence );
01073     char *strcat( char *dest, const char *src );
01074     int sprintf( char *str, const char *, ...);
01075     int printf( const char *, ... );
01076     int rand(void);
01077     int read( int , void*, int);
01078     int atoi( const char * );
01079     double atof( const char * );
01080     char * si_strchr( char *, int );
01081 
01082 #ifdef __cplusplus
01083 }
01084 #endif
01085 
01086 
01087 // Memory stuff
01088 #define _SI_MSIZE( x )          0
01089 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
01090 
01091 // character string format
01092 #define SI_Char         char
01093 #define _SI_STRCMP      strcmp
01094 #define _SI_STRNCMP     strncmp
01095 #define _SI_STRICMP     stricmp
01096 #define _SI_STRDUP      si_strdup
01097 #define _SI_BSTRDUP     si_bstrdup
01098 #define _SI_STRCPY      strcpy
01099 #define _SI_STRNCPY     strncpy
01100 #define _SI_STRCAT      strcat
01101 #define _SI_SPRINTF     sprintf
01102 #define _SI_STRLEN      strlen
01103 #define _SI_TEXT(quote) quote
01104 #define _SI_PRINTF      printf
01105 #define _SI_ATOI        atoi
01106 #define _SI_ATOF        atof
01107 
01108 // fprintf is not available and not needed on the PS2
01109 //#define _SI_FPRINTF
01110 
01111 #define _SI_RAND()      rand()
01112 #define _SI_STRTOK      strtok
01113 #define _SI_STRSTR      strstr
01114 #define _SI_STRCHR      si_strchr // MJD - Found a bug in strchr on GSCube
01115 #define _SI_STRRCHR     strrchr
01116 
01117 
01118 
01119 //Math Stuff
01120 #define _SI_SQRT        sqrt
01121 #define _SI_SQRTF       sqrtf
01122 #define _SI_ASIN        asin
01123 #define _SI_ASINF       asinf
01124 #define _SI_ACOS        acos
01125 #define _SI_ACOSF       acosf
01126 #define _SI_FLOOR       floor
01127 #define _SI_FLOORF      floorf
01128 #define _SI_TAN         tan
01129 #define _SI_TANF        tanf
01130 #define _SI_ATANF       atanf
01131 
01132 #ifdef _INLINETRIG_
01133 #define _SI_COS(x)      SI_CosineTable[((int)(x) * 10000) % 62831]
01134 #define _SI_COSF(x)     SI_CosineTable[((int)(x) * 10000) % 62831]
01135 #define _SI_SIN(x)      SI_SineTable[((int)(x) * 10000) % 62831]
01136 #define _SI_SINF(x)     SI_SineTable[((int)(x) * 10000) % 62831]
01137 #else
01138 #define _SI_COS         CSIBCUtil::cos
01139 #define _SI_COSF        CSIBCUtil::cos
01140 #define _SI_SIN         CSIBCUtil::sin
01141 #define _SI_SINF        CSIBCUtil::sin
01142 #endif
01143 
01144 
01145 
01146 
01147 
01148 
01149 
01150 // use only if files come from a DOS/Windows system (which is the case)
01151 #ifndef __APPLE__
01152 #define LITTLE_ENDIAN
01153 #endif
01154 
01155 //File stuff
01156 #define __SI_FILE               int
01157 #define __SI_FILE_MODE          int
01158 #define __SI_FILE_NULL          (int)(-1)
01159 #define __SI_FILE_READ_TEXT SCE_RDONLY
01160 #define __SI_FILE_READ_BINARY SCE_RDONLY
01161 #define __SI_FILE_WRITE_TEXT    SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01162 #define __SI_FILE_WRITE_BINARY SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01163 #define __SI_FILE_SET SCE_SEEK_SET
01164 #define __SI_FILE_CUR SCE_SEEK_CUR
01165 #define __SI_FILE_END SCE_SEEK_END
01166 #define __SI_IS_FILE_MODE( a, b ) ((a)==(b))
01167 #define __SI_FOPEN( NAME, MODE ) PS2FileOpen( NAME, MODE )
01168 #define __SI_FCLOSE( x ) PS2FileClose( x )
01169 #define __SI_FREAD( buf, size, count, fp ) PS2FileRead( fp, buf, size, count )
01170 #define __SI_FWRITE( buf, size, count, fp ) PS2FileWrite( fp, buf, size, count )
01171 // fprintf is not available and not needed on the PS2
01172 #define __SI_FSEEK( ptr, count, type ) PS2FileSeek( ptr, count, type )
01173 #define __SI_FTELL( ptr ) PS2FileTell( ptr )
01174 #define __SI_FGETC( fp ) PS2FileGetC( fp )
01175 #define __SI_FEOF( x )   PS2FileEOF( x )
01176 
01177 #define _SI_INITCORE SIPS2CommInit();
01178 #define _SI_EXITCORE SIPS2CommClose();
01179 
01180 #ifdef _DEBUG
01181 #define _SI_ASSERT(x) assert(x)
01182 #else
01183 void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
01184 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
01185 #define _SI_ASSERT(exp)
01186 #endif
01187 
01188 
01189 //Loadable module
01190 #define SI_INVALID_LIB_HANDLE -1
01191 #define _SI_LIBHANDLE   int
01192 
01193 #endif
01194 //
01196 //
01197 
01198 // Already documented in SIBCMath.h
01199 #ifndef M_PI
01200 #define M_PI        3.14159265358979323846  
01201 #endif
01202 
01208 #define _ERRMSG(x) _SI_PRINTF(_SI_TEXT("ERROR : %s\n"),x);
01209 
01211 #define _MSG(x)    _SI_PRINTF(_SI_TEXT("MSG   : %s\n"),x);
01212 
01214 #define _SI_NEW(x,y) {  x = new y; _SI_ASSERT( x != NULL ); }
01215 
01217 #define _SI_DELETE( ptr ) { if ( ptr != NULL ) { delete ptr; ptr = NULL; }  }
01218 
01220 #define _SI_DELETE_ARRAY( ptr ) {if ( ptr != NULL ) { delete [] ptr; ptr = NULL; }  }
01221 
01226 #define _SI_CALL(x,y) { if (result==SI_SUCCESS) { result = x;if(result != SI_SUCCESS){_ERRMSG(y);}}}
01227 
01230 #define _SI_CHKRESULT( RESULT, MESSAGE, ACTION ){if (RESULT != SI_SUCCESS){ _ERRMSG( MESSAGE ); ACTION; }   }
01231 
01232 XSICOREEXPORT SI_Char *  si_strdup( const SI_Char * );
01233 XSICOREEXPORT SI_Char *  si_bstrdup( const SI_Byte * );
01234 XSICOREEXPORT SI_Error si_bstringtostring( SI_Char *, const SI_Byte * );
01235 XSICOREEXPORT SI_Void si_splitpath(const SI_Char *, SI_Char *, SI_Char *, SI_Char *, SI_Char *);
01236 
01237 #define _SI_STRDUPL(D,S) { D = (char *) alloca(strlen(S)); strcpy(D,S); }
01238 
01239 #ifdef __cplusplus //If included by C-files this causes an error
01240 
01241 #ifdef _INLINETRIG_
01242 extern  float   SI_SineTable[62831];
01243 extern  float   SI_CosineTable[62831];
01244 #endif
01245 
01246 
01247 //**************************************************************************************
01248 // CSIBCUtil | Utility functions.
01249 //**************************************************************************************
01250 
01257 class XSICOREEXPORT CSIBCUtil
01258 {
01259 public:
01260 
01264     CSIBCUtil();
01265     ~CSIBCUtil();
01266 
01273     static  SI_Error    Open(SI_Char *in_pFilename);
01274 
01280     static  SI_Error    Close();
01281 
01285     static  void        SetToStderr();
01286 
01293     static  void        printf(SI_Char * str,...);
01294 
01295     // Fast lookup table for trigonometric functions
01296 
01301     static  void        InitializeTrigTables();
01302 
01309     static  float       cos(float x);
01310 
01317     static  float       sin(float x);
01318 
01319 protected:
01320     static SI_Char m_Filename[256];
01321 
01322 private:
01323     SI_Void             *m_pUnused;
01324 
01325 };
01326 
01327 #endif
01328 
01329 
01330 //
01331 // Inline code
01332 //
01333 
01334 /*  Calculates the cosine of an angle.
01335     \param[in] x Angle
01336     \return Result of the cosine operation.
01337 */
01338 inline float CSIBCUtil::cos(float x)
01339 {
01340 #ifdef _INLINETRIG_
01341     int     index = (int) ( x * 10000.0f);
01342 
01343     if (index < 0)
01344         index += 628310000;
01345 
01346     return SI_CosineTable[index % 62831];
01347 #else
01348     return _SI_COSF(x);
01349 #endif
01350 }
01351 
01352 /*  Calculates the sine of an angle.
01353     \param[in] x Angle
01354     \return Result of the sin operation.
01355 */
01356 inline float CSIBCUtil::sin(float x)
01357 {
01358 #ifdef _INLINETRIG_
01359     int     index = (int) ( x * 10000.0f);
01360 
01361     if (index < 0)
01362         index += 628310000;
01363 
01364     return SI_SineTable[index % 62831];
01365 #else
01366     return _SI_SINF(x);
01367 #endif
01368 }
01369 
01370 //**************************************************************************************
01371 // _SI_FILE macro definitions
01372 //
01373 //
01374 //**************************************************************************************
01375 
01376 // SIFILE things
01377 
01378 // No need to document this class, it is only used as a private member of SIFilePtr.
01379 class SIFileInterface
01380 {
01381 public:
01382     virtual ~SIFileInterface()
01383     {
01384     }
01385 
01386     // FUNCTIONS
01387     virtual int close() = 0;
01388 
01389     virtual size_t read( void *pbuffer, size_t size, size_t count ) = 0;
01390 
01391     virtual size_t write( const void *buffer, size_t size, size_t count ) = 0;
01392 
01393     virtual int printf( const char *format ) = 0;
01394 
01395     virtual int seek( LONG offset, int origin ) = 0;
01396 
01397     virtual LONG tell() = 0;
01398 
01399     virtual int fgetc() = 0;
01400 
01401     virtual int eof() = 0;
01402 
01403     virtual int error() = 0;
01404 
01405     virtual int flush() = 0;
01406 
01407     virtual int siungetc( int ch ) = 0;
01408 
01409     // OPERATORS
01410     virtual operator __SI_FILE() = 0;
01411 
01412     //virtual operator bool() const = 0;
01413 
01414     // you must define:  operator=( __SI_FILE const& other )
01415 };
01416 class SIFile: public SIFileInterface
01417 {
01418 private:
01419     __SI_FILE fp;
01420 
01421 public:
01422     enum openMode
01423     {
01424         Read_Text = 0,
01425         Read_Binary,
01426         Write_Text,
01427         Write_Binary,
01428     };
01429 
01430     enum seekDir
01431     {
01432 #ifdef __SI_FILE_SET
01433         sdSet = __SI_FILE_SET,
01434 #endif
01435 #ifdef __SI_FILE_CUR
01436         sdCur = __SI_FILE_CUR,
01437 #endif
01438 #ifdef __SI_FILE_END
01439         sdEnd = __SI_FILE_END,
01440 #endif
01441     };
01442 
01443     // CONSTRUCTORS
01444 
01445     SIFile(): fp( __SI_FILE_NULL ) {}
01446 
01447     SIFile( __SI_FILE file ): fp( file ) {}
01448 
01449     SIFile( const char *name, int mode )        // open
01450     {
01451 #ifdef __SI_FOPEN
01452         static __SI_FILE_MODE const mt[] =
01453         {
01454 #ifdef __SI_FILE_READ_TEXT
01455         __SI_FILE_READ_TEXT,
01456 #else
01457     #error you need to define this
01458 #endif
01459 #ifdef __SI_FILE_READ_BINARY
01460         __SI_FILE_READ_BINARY,
01461 #else
01462     #error you need to define this
01463 #endif
01464 #ifdef __SI_FILE_WRITE_TEXT
01465         __SI_FILE_WRITE_TEXT,
01466 #else
01467     #error you need to define this
01468 #endif
01469 #ifdef __SI_FILE_WRITE_BINARY
01470         __SI_FILE_WRITE_BINARY,
01471 #else
01472     #error you need to define this
01473 #endif
01474         };
01475         fp = __SI_FOPEN( (char*)name, mt[mode] );
01476 #else
01477     #error you need to define this
01478 #endif
01479     }
01480 
01481     // FUNCTIONS
01482     int close()
01483     {
01484 #ifdef __SI_FCLOSE
01485         int     temp = __SI_FCLOSE( fp );
01486         fp = __SI_FILE_NULL;                        // extra safety
01487         return temp;
01488 #else
01489         _SI_ASSERT( false );
01490         return 0;
01491 #endif
01492     }
01493 
01494     size_t read( void *buffer, size_t size, size_t count )
01495     {
01496 #ifdef __SI_FREAD
01497         return __SI_FREAD( buffer, size, count, fp );
01498 #else
01499         _SI_ASSERT( false );
01500         return 0;
01501 #endif
01502     }
01503 
01504     size_t write( const void *buffer, size_t size, size_t count )
01505     {
01506 #ifdef __SI_FWRITE
01507         return __SI_FWRITE( (void*)buffer, size, count, fp );
01508 #else
01509         _SI_ASSERT( false );
01510         return 0;
01511 #endif
01512     }
01513 
01514     int printf( const char *format )
01515     {
01516 #ifdef __SI_FPRINTF
01517         return __SI_FPRINTF( fp, format );
01518 #else
01519         _SI_ASSERT( false );
01520         return 0;
01521 #endif
01522     }
01523 
01524     int seek( LONG offset, int origin )
01525     {
01526 #ifdef __SI_FSEEK
01527         return __SI_FSEEK( fp, offset, origin );
01528 #else
01529         _SI_ASSERT( false );
01530         return 0;
01531 #endif
01532     }
01533 
01534     LONG tell()
01535     {
01536 #ifdef __SI_FTELL
01537         return __SI_FTELL( fp );
01538 #else
01539         _SI_ASSERT( false );
01540         return 0;
01541 #endif
01542     }
01543 
01544     int fgetc()
01545     {
01546 #ifdef __SI_FGETC
01547         return __SI_FGETC( fp );
01548 #else
01549         _SI_ASSERT( false );
01550         return 0;
01551 #endif
01552     }
01553 
01554     int eof()
01555     {
01556 #ifdef __SI_FEOF
01557         return __SI_FEOF( fp );
01558 #else
01559         _SI_ASSERT( false );
01560         return 0;
01561 #endif
01562     }
01563 
01564     int error()
01565     {
01566 #ifdef __SI_FERROR
01567         return __SI_FERROR( fp );
01568 #else
01569         _SI_ASSERT( false );
01570         return 0;
01571 #endif
01572     }
01573 
01574     int flush()
01575     {
01576 #ifdef __SI_FFLUSH
01577         return __SI_FFLUSH( fp );
01578 #else
01579         _SI_ASSERT( false );
01580         return 0;
01581 #endif
01582     }
01583 
01584     int siungetc( int ch )
01585     {
01586 #ifdef __SI_UNGETC
01587         return __SI_UNGETC( ch, fp );
01588 #else
01589         _SI_ASSERT( false );
01590         return 0;
01591 #endif
01592     }
01593 
01594     // OPERATORS
01595     operator __SI_FILE()
01596     {
01597         return fp;
01598     }
01599 
01600     /*operator bool() const
01601     {
01602         return fp == __SI_FILE_NULL;
01603     }*/
01604 
01605     SIFile operator=( __SI_FILE const& other )
01606     {
01607         fp = other;
01608         return *this;
01609     }
01610 
01611     SIFile operator=( SIFile const& other )
01612     {
01613         fp = other.fp;
01614         return *this;
01615     }
01616 };
01617 
01618 //***************************************************************************************
01619 //
01620 // Author  : Neil Girdhar / Softimage Games Team
01621 // Date    : July 8th 2002
01622 //
01623 // FILE STUFF
01624 //
01625 //***************************************************************************************
01626 
01627 // BUFFERED FILE
01628 
01629 #if defined( _XBOX ) || defined( _PSX2 )
01630 class BufferedFile: public SIFileInterface
01631 {
01632 private:
01633     char                *buffer;
01634     int                 goodBytes;          // bytes of the buffer that are good
01635     int                 position;           // position of next read in buffer
01636     unsigned int        bufferSize;
01637     SIFile              fp;
01638     /*
01639     our position in the underlying stream will always be goodBytes.
01640     to synchronise the surface stream, we would seek (position-goodBytes) (a negative number) bytes forward.
01641     */
01642 
01643 public:
01644     // CONSTRUCTORS
01645     BufferedFile(): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp()
01646     {
01647     }
01648 
01649     BufferedFile( __SI_FILE fpIn ): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp( fpIn )
01650     {
01651     }
01652 
01653     BufferedFile( const char *name, int mode, unsigned int bs ): buffer( new char[bs] ), goodBytes(0), position(0), bufferSize( bs ), fp()
01654     {
01655         fp = SIFile( name, mode );
01656     }
01657 
01658     virtual ~BufferedFile()
01659     {
01660         if( buffer!=NULL ) delete [] buffer;
01661     }
01662 
01663     // BUFFERING FUNCTIONS
01664     void clearBuffer()
01665     {
01666         goodBytes = 0;
01667     }
01668 
01669     void reseekBuffer()
01670     {
01671         int         seekdistance = position-goodBytes;      // see note above
01672         if( seekdistance==0 ) return;           // already seeked
01673         fp.seek( seekdistance, SIFile::sdCur ); // seek forward to where the user thinks we are  (room for optimization)
01674         position = 0;                           // set our position
01675         clearBuffer();                          // clear the buffer after reseek
01676     }
01677 
01678     unsigned int fillBuffer()
01679     {
01680         reseekBuffer();
01681         goodBytes = fp.read( buffer, 1, bufferSize );
01682 #ifdef  _PSX2
01683         if (goodBytes < 0)
01684             goodBytes = 0;
01685 #endif
01686         position = 0;
01687         return  goodBytes;
01688     }
01689 
01690     unsigned int remainingBytesInBuffer()
01691     {
01692         return goodBytes-position;
01693     }
01694 
01695     // FUNCTIONS
01696     int close()
01697     {
01698         clearBuffer();
01699         return fp.close();
01700     }
01701 
01702     size_t read( void *pbuffer, size_t size, size_t count )
01703     {
01704         if( size*count<=bufferSize )        // only cache for small reads
01705         //if( false )
01706         {
01707             char        *dest = (char*)pbuffer;
01708             int         copiedWords = 0;
01709 
01710             while( count>0 )
01711             {
01712                 if( remainingBytesInBuffer()<size )
01713                 {
01714                     if( fillBuffer()<size )
01715                     {
01716                         break;  // could not read at least one word/record
01717                     }
01718                 }
01719 
01720                 // buffer is not empty, so copy out good bytes
01721                 {
01722                     int         copyWords = min( remainingBytesInBuffer()/size, count );    // words to copy
01723                     int         copyBytes = copyWords * size;                   // bytes to copy
01724 
01725                     _SI_MEMCPY( dest, buffer+position, copyBytes );
01726 
01727                     dest += copyBytes;
01728                     position += copyBytes;
01729 
01730                     copiedWords += copyWords;
01731                     count -= copyWords;
01732                 }
01733             }
01734 
01735             return copiedWords;
01736         }
01737         else
01738         {
01739             reseekBuffer();
01740             clearBuffer();
01741             return fp.read( pbuffer, size, count );
01742         }
01743     }
01744 
01745     size_t write( const void *buffer, size_t size, size_t count )
01746     {
01747         reseekBuffer();
01748         clearBuffer();
01749         return fp.write( buffer, size, count );
01750     }
01751 
01752     int printf( const char *format )
01753     {
01754         reseekBuffer();
01755         clearBuffer();
01756         return fp.printf( format );
01757     }
01758 
01759     int seek( LONG offset, int origin )
01760     {
01761         if( origin==SIFile::sdCur )
01762         {
01763             offset+=position-goodBytes;             // collect position and offset together
01764         }
01765         position = 0;                       // after the seek, we will be at position 0
01766         clearBuffer();                      // buffer is invalid after seek; there is room for optimization here, but it shouldn't matter in general use
01767         return fp.seek( offset, origin );   // recurse
01768     }
01769 
01770     LONG tell()
01771     {
01772         return fp.tell() + position;        // user thinks we are position bytes ahead
01773     }
01774 
01775     int fgetc()
01776     {
01777         char retval;
01778         if( read( &retval, 1, 1 )==0 )
01779         {
01780             return fp.fgetc();              // same EOF/error characteristics
01781         }
01782         return retval;
01783     }
01784 
01785     int eof()
01786     {
01787         if( goodBytes > position ) return 0;
01788         reseekBuffer();
01789         return fp.eof();
01790     }
01791 
01792     int error()
01793     {
01794         reseekBuffer();
01795         return fp.error();
01796     }
01797 
01798     int flush()
01799     {
01800         // no need to reseek or clear buffer
01801         return fp.flush();
01802     }
01803 
01804     int siungetc( int ch )
01805     {
01806         reseekBuffer();
01807         clearBuffer();
01808         return fp.siungetc( ch );
01809     }
01810 
01811     // OPERATORS
01812     operator SIFile()
01813     {
01814         reseekBuffer();
01815         clearBuffer();
01816         return fp;
01817     }
01818 
01819     operator __SI_FILE()
01820     {
01821         reseekBuffer();
01822         clearBuffer();
01823         return fp;
01824     }
01825 
01826     /*operator bool() const
01827     {
01828         return (bool)fp;
01829     }*/
01830 };
01831 #endif
01832 
01833 class SIFilePtr
01834 {
01835 private:
01836     SIFileInterface     *fp;
01837 
01838 public:
01839     SIFilePtr()
01840     {
01841         fp = NULL;
01842     }
01843 
01844     SIFilePtr( __SI_FILE file )
01845     {
01846         fp = NULL;
01847         this->operator=( file );
01848     }
01849 
01850 
01851     SIFilePtr( const char *name, int mode )
01852     {
01853 #if (defined _XBOX) || (defined _PSX2)
01854         fp = (SIFileInterface*)new BufferedFile( name, mode, 2048 );        // bufferring
01855 #elif (defined unix) \
01856         || ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX) \
01857         || (defined _WIN32_WCE)
01858         fp = (SIFileInterface*)new SIFile( name, mode );                    // no bufferring
01859 #else
01860         // unknown platform
01861         fp = (SIFileInterface*)new SIFile( name, mode );                    // no bufferring
01862 #endif
01863     }
01864 
01865     ~SIFilePtr()
01866     {
01867     }
01868 
01869     // FUNCTIONS
01870     int close()
01871     {
01872         int retval = fp->close();
01873         delete fp;
01874         return retval;
01875     }
01876 
01877     size_t read( void *pbuffer, size_t size, size_t count )
01878     {
01879         return fp->read( pbuffer, size, count );
01880     }
01881 
01882     size_t write( const void *buffer, size_t size, size_t count )
01883     {
01884         return fp->write( buffer, size, count );
01885     }
01886 
01887     int printf( const char *format )
01888     {
01889         return fp->printf( format );
01890     }
01891 
01892     int seek( LONG offset, int origin )
01893     {
01894         return fp->seek( offset, origin );  // recurse
01895     }
01896 
01897     LONG tell()
01898     {
01899         return fp->tell();
01900     }
01901 
01902     int fgetc()
01903     {
01904         return fp->fgetc();
01905     }
01906 
01907     int eof()
01908     {
01909         return fp->eof();
01910     }
01911 
01912     int error()
01913     {
01914         return fp->error();
01915     }
01916 
01917     int flush()
01918     {
01919         return fp->flush();
01920     }
01921 
01922     int siungetc( int ch )
01923     {
01924         return fp->siungetc( ch );
01925     }
01926 
01927     // OPERATORS
01928 
01929     operator __SI_FILE()
01930     {
01931         if( fp==NULL ) return __SI_FILE_NULL;
01932         return (__SI_FILE)(*fp);
01933     }
01934 
01935     /*operator bool() const
01936     {
01937         if( fp==NULL ) return false;
01938         return fp->operator bool();
01939     }*/
01940 
01941     SIFilePtr& operator=( __SI_FILE const & other )
01942     {
01943         if( other == __SI_FILE_NULL )
01944         {
01945             fp = NULL;
01946         }
01947         else
01948         {
01949             fp = (SIFileInterface*)new SIFile( other );
01950         }
01951         return *this;
01952     }
01953 
01954     SIFilePtr& operator=( const SIFilePtr &other )
01955     {
01956         // check for equality (are we the same as what we're assigning to)
01957         if (this != &other) {
01958             fp = other.fp;
01959         }
01960         return *this;
01961     }
01962 };
01963 
01964 typedef SIFilePtr _SI_FILE;
01965 
01966 XSICOREEXPORT SI_Char si_getc( _SI_FILE x );
01967 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, _SI_FILE x );
01968 
01969 
01970 // FILE MACROS
01971 #define _SI_FILE_MODE   SIFile::openMode
01972 #define _SI_FILE_NULL   __SI_FILE_NULL
01973 #define _SI_FILE_READ_TEXT  (SIFile::Read_Text)
01974 #define _SI_FILE_READ_BINARY (SIFile::Read_Binary)
01975 #define _SI_FILE_WRITE_TEXT (SIFile::Write_Text)
01976 #define _SI_FILE_WRITE_BINARY (SIFile::Write_Binary)
01977 #define _SI_FILE_SET (SIFile::sdSet)
01978 #define _SI_FILE_CUR (SIFile::sdCur)
01979 #define _SI_FILE_END (SIFile::sdEnd)
01980 #define _SI_IS_FILE_MODE( a, b ) ((a)==(b))
01981 #define _SI_FOPEN( name, mode )     (_SI_FILE( name, mode ))
01982 #define _SI_FCLOSE( x )     ((x).close())
01983 #define _SI_FREAD( a, b, c, d ) ((d).read( a, b, c ))
01984 #define _SI_FWRITE( a, b, c, d ) ((d).write( a, b, c ))
01985 #define _SI_FPRINTF( a, b ) ((a).printf( b ))
01986 #define _SI_FSEEK( ptr, count, type ) ((ptr).seek( count, type ))
01987 #define _SI_FTELL( ptr ) ((ptr).tell())
01988 #define _SI_FGETC( fp ) ((fp).fgetc())
01989 #define _SI_FEOF( x ) ((x).eof())
01990 #define _SI_FERROR( x ) ((x).error())
01991 #define _SI_FFLUSH( fp ) ((fp).flush())
01992 #define _SI_UNGETC( fp ) ((fp).siungetc())
01993 
01994 //**************************************************************************************
01995 // WARNING CALLBACK FUNCTION
01996 //
01997 //
01998 //**************************************************************************************
01999 
02000 typedef SI_Void (*SI_WARNING_CALLBACK_FNC)  ( SI_Char*, SI_Int );
02001 #define SI_MESSAGE  0
02002 #define SI_WARNING  1
02003 #define SI_ERROR    2
02004 
02005 //
02006 // Allocation
02007 //
02008 
02009 XSICOREEXPORT void  *   FTK_calloc( size_t, size_t );
02010 XSICOREEXPORT void      FTK_free( void * );
02011 XSICOREEXPORT void      FTK_delete( void * );
02012 
02013 //**************************************************************************************
02014 // URL FUNCTIONS
02015 //
02016 //
02017 //**************************************************************************************
02018 
02019 class CSIBCString;
02020 SI_Error FTK_GetURLParts(char* in_pURL, CSIBCString* out_pScheme, CSIBCString* out_pAuthority, CSIBCString* out_pPath, CSIBCString* out_pQuery, CSIBCString* out_pFragment);
02021 void FTK_ConvertStringFromURL(CSIBCString &io_String);
02022 void FTK_ConvertStringToURL(CSIBCString &io_String);
02023 
02024 #endif // CSIBCUtil