00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __CSIBCUtil_H__
00016 #define __CSIBCUtil_H__
00017
00018 #if defined(unix) && (defined(WIN64) || defined(_WIN64) || defined(__x86_64))
00019 typedef unsigned int ULONG;
00020 typedef int LONG;
00021 #else
00022 typedef unsigned long ULONG;
00023 typedef long LONG;
00024 #endif
00025
00026 #ifdef unix
00027 #include <string.h>
00028 #ifdef __APPLE__
00029 #include <math.h>
00030 #endif
00031 #endif
00032
00033 #include <SIBCMath.h>
00034
00035 #ifdef _WIN32
00036 #ifndef _XBOX
00037 #include <windows.h>
00038 #include <winuser.h>
00039 #else
00040 #include <xtl.h>
00041 #endif
00042 #endif
00043
00044
00045
00046
00047 #ifndef _WIN32_WCE
00048 #include <assert.h>
00049 #else
00050 #endif
00051
00052
00053
00054
00055
00056 #ifndef _CUS_DLL
00057
00067 typedef enum {
00068
00069
00070 SI_SUCCESS = 0,
00071
00072
00073 SI_ERR_NONE = 0,
00074 SI_ERR_STATUS_MSG,
00075 SI_ERR_MESSAGE_MSG,
00076 SI_ERR_WARNING_MSG,
00077 SI_ERR_ERROR_MSG,
00078 SI_ERR_MODE_MSG,
00079 SI_ERR_INTERNAL,
00080 SI_ERR_NOTYETIMPLEMENTED,
00081 SI_ERR_NOTSUPPORTED,
00082
00083
00084 SI_ERR_BAD_MDLTYPE,
00085 SI_ERR_BAD_CHAPID,
00086 SI_ERR_BAD_GROUPID,
00087 SI_ERR_BAD_GROUPLIST,
00088 SI_ERR_BAD_ELEMENT,
00089 SI_ERR_BAD_DICTIONARY,
00090 SI_ERR_BAD_RELID,
00091 SI_ERR_BAD_ARGUMENT,
00092 SI_ERR_BAD_DATABASE,
00093 SI_ERR_BAD_RELNDX,
00094 SI_ERR_BAD_MSMSH,
00095 SI_ERR_BAD_MFACE,
00096 SI_ERR_BAD_MPTCH,
00097 SI_ERR_BAD_MSPLN,
00098 SI_ERR_BAD_PARAM,
00099 SI_ERR_BAD_NBPARAM,
00100 SI_ERR_BAD_NOPARAM,
00101 SI_ERR_BAD_CHP4REL,
00102 SI_ERR_BAD_SHAPEID,
00103 SI_ERR_CLS_NOMODEL,
00104 SI_ERR_LAT_NOMODEL,
00105
00106
00107 SI_ERR_RELRSRC_CANTOPEN,
00108 SI_ERR_RELRSRC_INVGRP,
00109 SI_ERR_RELRSRC_INVCHP,
00110 SI_ERR_RELPAIR_CANTADD,
00111 SI_ERR_RELPAIR_CANTDEL,
00112 SI_ERR_REL_CANTDEL,
00113
00114
00115 SI_ERR_ELEM_NOTFOUND,
00116 SI_ERR_NAME_DUPL,
00117 SI_ERR_NAME_FORMAT,
00118
00119
00120 SI_ERR_DB_NOTFOUND,
00121 SI_ERR_DB_INVALID,
00122 SI_ERR_DB_CANTCREATE,
00123 SI_ERR_DB_CANTDELETE,
00124 SI_ERR_DBDELETE,
00125 SI_ERR_ACCESS_CANTSET,
00126 SI_ERR_SCENE_CANTREAD,
00127 SI_ERR_SCENE_CANTWRITE,
00128 SI_ERR_SCENE_CANTDEL,
00129 SI_ERR_ELEM_CANTREAD,
00130 SI_ERR_ELEM_CANTWRITE,
00131 SI_ERR_SAVE_NOTROOT,
00132 SI_ERR_NOVERS_FOUND,
00133
00134
00135 SI_ERR_NUM_VERTICES,
00136 SI_ERR_SHAPE_VERTICES,
00137 SI_ERR_TOO_FEW_VERTICES,
00138 SI_ERR_TOO_MANY_VERTICES,
00139 SI_ERR_NULL_TRANSFO,
00140 SI_ERR_NULL_VECTOR,
00141 SI_ERR_BAD_COORDSYS,
00142 SI_ERR_BAD_VNDX,
00143 SI_ERR_CHAPNOTFOUND,
00144 SI_ERR_FCVNOTFOUND,
00145 SI_ERR_NOT_TRIANGULATED,
00146
00147
00148 SI_ERR_CYCLE_DETECTED,
00149
00150
00151 SI_ERR_DYNALINK_NOT_LOADED,
00152 SI_ERR_DYNALINK_NOT_RESOLVED,
00153 SI_ERR_DYNALINK_NOT_UNLOADED,
00154
00155
00156 SI_ERR_CUSVAL_SYMBOL_NOT_FOUND,
00157 SI_ERR_CUSVAL_INCORRECT_TYPE,
00158 SI_ERR_CUSVAL_BUFFER_TOO_SMALL,
00159
00160
00161 SI_ERR_ALLOC_PROBLEM,
00162 SI_ERR_INVALID_SCENE,
00163 SI_ERR_ELEM_UNSCENE,
00164 SI_ERR_ELEM_TYPE,
00165 SI_ERR_ELEM_ROOT,
00166 SI_ERR_WRONG_COUNT,
00167 SI_ERR_INVALID_LTYPE,
00168 SI_ERR_NO_RESET,
00169 SI_ERR_INVALID_SELEM,
00170 SI_ERR_BAD_MATERIAL,
00171 SI_ERR_INVALID_TESSELATION,
00172 SI_ERR_NON_TESSELATABLE,
00173 SI_ERR_INVALID_MODEL_DATA,
00174 SI_ERR_NO_MATERIAL,
00175 SI_ERR_NO_TEXTURE,
00176 SI_ERR_ELEM_NOT_LEAF_NODE,
00177 SI_ERR_ELEM_CANTDEL,
00178 SI_ERR_FCURVE_EXISTS,
00179 SI_ERR_ELEM_CHNROOT,
00180 SI_ERR_ELEM_EFFECTOR,
00181 SI_ERR_GOAL_NOT_SET,
00182 SI_ERR_USERDATA_EXISTS,
00183 SI_ERR_INVALID_INDEX,
00184
00185
00186 SI_ERR_CUS_SECOND_SYMBOL,
00187 SI_ERR_CUS_NO_SYMBOL_NAME,
00188
00189
00190 SI_ERR_CUSTOM_FATAL,
00191
00192
00193 SI_ERR_UNFOUND_GLBSYMB_TAB,
00194
00195
00196 SI_ERR_STOP,
00197 SI_ERR_TXT_NAME,
00198 SI_ERR_NO_CAM,
00199
00200
00201 SI_ERR_TRANSFO_METASYSTEM,
00202 SI_ERR_TRANSFO_PATCHDEFORM,
00203 SI_ERR_TRANSFO_SPLINEDEFORM,
00204 SI_ERR_SCAL_CHAIN,
00205 SI_ERR_SCAL_CNSSCL,
00206 SI_ERR_ROT_JOINT,
00207 SI_ERR_ROT_CHNROOT,
00208 SI_ERR_ROT_CNSORI,
00209 SI_ERR_TRANS_CHNROOT,
00210 SI_ERR_TRANS_JOINT,
00211 SI_ERR_TRANS_DYNLEAF,
00212 SI_ERR_TRANS_MAINGLOBENV,
00213 SI_ERR_TRANS_CONSTRAINT,
00214
00215
00216 SI_ERR_SUBELEM_TOTAL_FAILURE,
00217 SI_ERR_SOFTIMAGE_TOO_OLD,
00218 SI_ERR_SAAPHIRE_TOO_OLD,
00219 SI_ERR_SAA_TOO_OLD_FOR_EFFECT,
00220 SI_ERR_FILE_EXISTS,
00221 SI_ERR_UNRELATED_T2D,
00222 SI_ERR_INCOMPATIBLE_T2DMAP,
00223 SI_ERR_SHADER_EXISTS,
00224 SI_ERR_INCOMPAT_MAP_METHOD,
00225 SI_ERR_MODEL_NO_SHAPES,
00226 SI_ERR_CLUSTER_NO_KEYS,
00227
00228
00229 SI_ERR_CUSTOM_FATAL_NOMSG,
00230 SI_ERR_NO_FCV_EDITOR,
00231
00232
00233 SI_ERR_RENDER_WARNING,
00234 SI_ERR_RENDER_ERROR,
00235
00236
00237 SI_ERR_MODEL_NO_PHYSPROPS,
00238
00239
00240 SI_ERR_EFFECT_NODG,
00241 SI_ERR_DG_NOTFOUND,
00242
00243
00244 SI_ERR_RENDER_VOLUNTARYEXIT,
00245
00246
00247 SI_ERR_AUDIO_DEVICEINUSE,
00248 SI_ERR_AUDIO_INVALIDFORMAT,
00249 SI_ERR_AUDIO_INACTIVE,
00250 SI_ERR_FILENOTFOUND,
00251 SI_ERR_AUDIO_INVALIDTRACK,
00252 SI_ERR_FILEPASSEDEOF,
00253
00254
00255 SI_ERR_NO_ACTION,
00256 SI_ERR_MARKER_NOTFOUND,
00257 SI_ERR_ACTIONMARKERS_OVERLAP,
00258
00259
00260 SI_ERR_AUDIO_FILENOTSET,
00261 SI_ERR_AUDIO_FILEALREADYSET,
00262 SI_ERR_AUDIO_MIXINGNOTENABLED,
00263
00264
00265 SI_ERR_LIC_INVALID_HANDLE,
00266 SI_ERR_LIC_INVALID_ARGS,
00267 SI_ERR_LIC_CHECKOUT,
00268 SI_ERR_NUM,
00269
00270
00271 SI_FILE_NOT_FOUND,
00272 SI_NO_AVAILABLE_DRIVER,
00273
00274 SI_IMAGE_BAD_FORMAT
00275
00276 } eSI_Error;
00277
00280 typedef int SI_Error;
00281
00284 #else
00285
00286
00287 #include <saa.h>
00288
00289 #define SI_FILE_NOT_FOUND (SI_ERR_NUM + 1)
00290 #define SI_NO_AVAILABLE_DRIVER (SI_FILE_NOT_FOUND + 1)
00291 #endif
00292
00297 #ifndef TRUE
00298 #define TRUE 1
00299 #endif
00300
00301 #ifndef FALSE
00302 #define FALSE 0
00303 #endif
00304
00305 #define SI_TRUE TRUE
00306 #define SI_FALSE FALSE
00310 // Already documented in SIBCMathLib.h
00311 #ifndef NULL
00312 #define NULL 0
00313 #endif
00314
00322 #define SI_Bool unsigned short
00323 #define SI_Byte char
00324 #define SI_UByte unsigned char
00325 #define SI_Short short
00326 #define SI_UShort unsigned short
00327 #define SI_Int int
00328 #define SI_UInt unsigned int
00329 #define SI_Float float
00330 #define SI_Double double
00331 #define SI_Long int
00332 #define SI_Void void
00333 #define SI_ULong unsigned int
00334 typedef SI_Float SI_Matrix[4][4];
00335 // endgroup
00336
00337
00338 #define SI_CUSTOMPSET_PCHAR "Text"
00339 #define SI_CUSTOMPSET_BOOL "Boolean"
00340 #define SI_CUSTOMPSET_INT "Integer"
00341 #define SI_CUSTOMPSET_UBYTE "Small Integer Number"
00342 #define SI_CUSTOMPSET_DOUBLE "Floating Point Number"
00343
00344
00352 #define SI_VT_BOOL 0
00353 #define SI_VT_BYTE 1
00354 #define SI_VT_UBYTE 2
00355 #define SI_VT_SHORT 3
00356 #define SI_VT_USHORT 4
00357 #define SI_VT_INT 5
00358 #define SI_VT_UINT 6
00359 #define SI_VT_FLOAT 7
00360 #define SI_VT_DOUBLE 8
00361 #define SI_VT_LONG 9
00362 #define SI_VT_ULONG 10
00364 #define SI_VT_PBOOL 11
00365 #define SI_VT_PBYTE 12
00366 #define SI_VT_PUBYTE 13
00367 #define SI_VT_PSHORT 14
00368 #define SI_VT_PUSHORT 15
00369 #define SI_VT_PINT 16
00370 #define SI_VT_PUINT 17
00371 #define SI_VT_PFLOAT 18
00372 #define SI_VT_PDOUBLE 19
00373 #define SI_VT_PLONG 20
00374 #define SI_VT_PULONG 21
00376 #define SI_VT_PCHAR 22
00377 #define SI_VT_PPCHAR 23
00379 #define SI_VT_PVOID 24 // endgroup.
00381
00382
00390 #define SI_TT_NONE 0
00391 #define SI_TT_POSITION 1
00392 #define SI_TT_NORMAL 2
00393 #define SI_TT_TEXCOORD 3
00394 #define SI_TT_COLOR 4
00395 #define SI_TT_TRANSFO 5
00396 #define SI_TT_INTEGER 6
00397 #define SI_TT_FLOAT 7
00398 #define SI_TT_TINYFLOAT 8 // endgroup.
00400
00408 struct TinyVariant {
00409
00410 TinyVariant() { memset(this,0,sizeof(TinyVariant));};
00411 TinyVariant(SI_Int v,SI_Int t,SI_Int e )
00412 {
00413 variantType = v;
00414 tweakType = t;
00415 numElems = e;
00416 };
00417
00418 SI_Int variantType;
00419 SI_Int tweakType;
00420 SI_Int numElems;
00425 union {
00426 SI_Bool boolVal;
00427 SI_Byte bVal;
00428 SI_UByte ubVal;
00429 SI_Short sVal;
00430 SI_UShort usVal;
00431 SI_Int nVal;
00432 SI_UInt unVal;
00433 SI_Float fVal;
00434 SI_Double dVal;
00435 SI_Long lVal;
00436 SI_ULong ulVal;
00438 SI_Bool *p_boolVal;
00439 SI_Byte *p_bVal;
00440 SI_UByte *p_ubVal;
00441 SI_Short *p_sVal;
00442 SI_UShort *p_usVal;
00443 SI_Int *p_nVal;
00444 SI_UInt *p_unVal;
00445 SI_Float *p_fVal;
00446 SI_Double *p_dVal;
00447 SI_Long *p_lVal;
00448 SI_ULong *p_ulVal;
00450
00451 char *p_cVal;
00452 char **pp_cVal;
00454 SI_Void *p_voidVal;
00455 };
00456 };
00457
00461 typedef TinyVariant SI_TinyVariant;
00462
00465
00466
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
00507 #define _SI_MSIZE( x ) 0
00508 #define _SI_MEMCPY( x, y, z ) memcpy( x, y, z )
00509
00510
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
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
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
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
00598 #ifdef _DEBUG
00599 #define _SI_ASSERT(x) assert(x)
00600 #else
00601
00602
00603 #define _SI_ASSERT(exp)
00604 #endif
00605
00606
00607 #define _SI_LIBHANDLE int
00608
00609
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
00672 #define _SI_MSIZE( x ) _msize( x )
00673 #define _SI_MEMCPY( x, y, z ) memcpy( x, y, z )
00674
00675
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
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
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
00744 #ifdef _DEBUG
00745 #define _SI_ASSERT(x) assert(x)
00746 #else
00747
00748
00749 #define _SI_ASSERT(exp)
00750 #endif
00751
00752
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
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
00780 #define _SI_ASSERT(x)
00781 #include <tchar.h>
00782 #include <winbase.h>
00783
00784
00785 #define _SI_MSIZE( x ) 0
00786 #define _SI_MEMCPY( x, y, z ) 0
00787
00788
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
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
00893 #define _SI_MSIZE( x ) _msize( x )
00894 #define _SI_MEMCPY( x, y, z ) memcpy( x, y, z )
00895
00896
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
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
00957
00958 #define __SI_FILE FILE *
00959 #define __SI_FILE_MODE SI_Char *
00960 #define __SI_FILE_NULL (NULL)
00961 #define __SI_FILE_READ_TEXT "r"
00962 #define __SI_FILE_READ_BINARY "rb"
00963 #define __SI_FILE_WRITE_TEXT "w"
00964 #define __SI_FILE_WRITE_BINARY "wb"
00965 #define __SI_FILE_SET SEEK_SET
00966 #define __SI_FILE_CUR SEEK_CUR
00967 #define __SI_FILE_END SEEK_END
00968 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00969 #define __SI_FOPEN( name, mode ) XBOXFileOpen( name, mode )
00970 #define __SI_FCLOSE( x ) XBOXFileClose( x )
00971 #define __SI_FREAD( a, b, c, d ) XBOXFileRead( a, b, c, d )
00972 #define __SI_FWRITE( a, b, c, d ) XBOXFileWrite( a, b, c, d )
00973 #define __SI_FPRINTF( a, b ) (0)
00974 #define __SI_FSEEK( ptr, count, type ) XBOXFileSeek( ptr, count, type )
00975 #define __SI_FTELL( ptr ) XBOXFileTell( ptr )
00976 #define __SI_FGETC( fp ) XBOXFileGETC(fp)
00977 #define __SI_FEOF( x ) XBOXFileEOF( x )
00978 #define __SI_FERROR( x ) (0)
00979 #define __SI_FFLUSH( x ) (0)
00980
00981 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, __SI_FILE x );
00982
00983 #define __SI_UNGETC( ch, fp ) (0)
00984
00985
00986 #ifdef _DEBUG
00987 #define _SI_ASSERT(x) assert(x)
00988 #else
00989
00990
00991 #define _SI_ASSERT(exp)
00992 #endif
00993
00994
00995 #define SI_INVALID_LIB_HANDLE NULL
00996 #define _SI_LIBHANDLE HMODULE
00997 #define _SI_LOADMODULE LoadLibrary
00998 #define _SI_UNLOADMODULE( x ) FreeLibrary( x )
00999 #define _SI_LOADFUNCTION( HAND, NAME ) GetProcAddress( HAND, NAME )
01000
01001
01002 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
01003 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
01004 #endif
01005
01006
01007
01009
01010 #if defined( _PSX2 ) || defined( __MWERKS__ )
01011
01012 #include <eekernel.h>
01013 #include <sifdev.h>
01014 #include <eeregs.h>
01015 #include <eetypes.h>
01016 #include <stdio.h>
01017 #include <string.h>
01018 #include <stdlib.h>
01019 #include <SIPS2Comm.h>
01020
01021
01022
01023
01024
01025
01026 #ifdef __XSI_MAINLIB_
01027 #define XSIEXPORT
01028 #define XSITEMPLATEEXP
01029 #endif
01030
01031 #ifdef __XSI_PLUGIN_
01032 #define XSIEXPORT
01033 #define XSITEMPLATEEXP
01034 #endif
01035
01036 #ifdef __XSI_APPLICATION_
01037 #ifdef XSI_STATIC_LINK
01038 #define XSIEXPORT
01039 #define XSITEMPLATEEXP
01040 #else
01041 #define XSIEXPORT
01042 #define XSITEMPLATEEXP
01043 #endif
01044 #endif
01045
01046 #ifndef XSICOREEXPORT
01047 #define XSICOREEXPORT
01048 #endif
01049
01050 #ifndef XSIEXPORT
01051 #define XSIEXPORT
01052 #endif
01053
01054 #ifndef min
01055 # define min(a,b) ((a) < (b) ? (a) : (b))
01056 #endif
01057
01058 #ifndef max
01059 # define max(a,b) ((a) > (b) ? (a) : (b))
01060 #endif
01061
01062 #ifndef _PSX2_FILEIO_NATIVE
01063 #define _PSX2_FILEIO_NATIVE
01064 #endif
01065
01066
01067 #ifdef __cplusplus
01068 extern "C"
01069 {
01070 #endif
01071 int open( const char *, int );
01072 int close( int );
01073
01074 char *strcat( char *dest, const char *src );
01075 int sprintf( char *str, const char *, ...);
01076 int printf( const char *, ... );
01077 int rand(void);
01078 int read( int , void*, int);
01079 int atoi( const char * );
01080 double atof( const char * );
01081 char * si_strchr( char *, int );
01082
01083 #ifdef __cplusplus
01084 }
01085 #endif
01086
01087
01088
01089 #define _SI_MSIZE( x ) 0
01090 #define _SI_MEMCPY( x, y, z ) memcpy( x, y, z )
01091
01092
01093 #define SI_Char char
01094 #define _SI_STRCMP strcmp
01095 #define _SI_STRNCMP strncmp
01096 #define _SI_STRICMP stricmp
01097 #define _SI_STRDUP si_strdup
01098 #define _SI_BSTRDUP si_bstrdup
01099 #define _SI_STRCPY strcpy
01100 #define _SI_STRNCPY strncpy
01101 #define _SI_STRCAT strcat
01102 #define _SI_SPRINTF sprintf
01103 #define _SI_STRLEN strlen
01104 #define _SI_TEXT(quote) quote
01105 #define _SI_PRINTF printf
01106 #define _SI_ATOI atoi
01107 #define _SI_ATOF atof
01108
01109
01110
01111
01112 #define _SI_RAND() rand()
01113 #define _SI_STRTOK strtok
01114 #define _SI_STRSTR strstr
01115 #define _SI_STRCHR si_strchr // MJD - Found a bug in strchr on GSCube
01116 #define _SI_STRRCHR strrchr
01117
01118
01119
01120
01121 #define _SI_SQRT sqrt
01122 #define _SI_SQRTF sqrtf
01123 #define _SI_ASIN asin
01124 #define _SI_ASINF asinf
01125 #define _SI_ACOS acos
01126 #define _SI_ACOSF acosf
01127 #define _SI_FLOOR floor
01128 #define _SI_FLOORF floorf
01129 #define _SI_TAN tan
01130 #define _SI_TANF tanf
01131 #define _SI_ATANF atanf
01132
01133 #ifdef _INLINETRIG_
01134 #define _SI_COS(x) SI_CosineTable[((int)(x) * 10000) % 62831]
01135 #define _SI_COSF(x) SI_CosineTable[((int)(x) * 10000) % 62831]
01136 #define _SI_SIN(x) SI_SineTable[((int)(x) * 10000) % 62831]
01137 #define _SI_SINF(x) SI_SineTable[((int)(x) * 10000) % 62831]
01138 #else
01139 #define _SI_COS CSIBCUtil::cos
01140 #define _SI_COSF CSIBCUtil::cos
01141 #define _SI_SIN CSIBCUtil::sin
01142 #define _SI_SINF CSIBCUtil::sin
01143 #endif
01144
01145
01146
01147
01148
01149
01150
01151
01152 #ifndef __APPLE__
01153 #define LITTLE_ENDIAN
01154 #endif
01155
01156
01157 #define __SI_FILE int
01158 #define __SI_FILE_MODE int
01159 #define __SI_FILE_NULL (int)(-1)
01160 #define __SI_FILE_READ_TEXT SCE_RDONLY
01161 #define __SI_FILE_READ_BINARY SCE_RDONLY
01162 #define __SI_FILE_WRITE_TEXT SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01163 #define __SI_FILE_WRITE_BINARY SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01164 #define __SI_FILE_SET SCE_SEEK_SET
01165 #define __SI_FILE_CUR SCE_SEEK_CUR
01166 #define __SI_FILE_END SCE_SEEK_END
01167 #define __SI_IS_FILE_MODE( a, b ) ((a)==(b))
01168 #define __SI_FOPEN( NAME, MODE ) PS2FileOpen( NAME, MODE )
01169 #define __SI_FCLOSE( x ) PS2FileClose( x )
01170 #define __SI_FREAD( buf, size, count, fp ) PS2FileRead( fp, buf, size, count )
01171 #define __SI_FWRITE( buf, size, count, fp ) PS2FileWrite( fp, buf, size, count )
01172
01173 #define __SI_FSEEK( ptr, count, type ) PS2FileSeek( ptr, count, type )
01174 #define __SI_FTELL( ptr ) PS2FileTell( ptr )
01175 #define __SI_FGETC( fp ) PS2FileGetC( fp )
01176 #define __SI_FEOF( x ) PS2FileEOF( x )
01177
01178 #define _SI_INITCORE SIPS2CommInit();
01179 #define _SI_EXITCORE SIPS2CommClose();
01180
01181 #ifdef _DEBUG
01182 #define _SI_ASSERT(x) assert(x)
01183 #else
01184 void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
01185
01186 #define _SI_ASSERT(exp)
01187 #endif
01188
01189
01190
01191 #define SI_INVALID_LIB_HANDLE -1
01192 #define _SI_LIBHANDLE int
01193
01194 #endif
01195
01197
01198
01199
01200 #ifndef M_PI
01201 #define M_PI 3.14159265358979323846
01202 #endif
01203
01209 #define _ERRMSG(x) _SI_PRINTF(_SI_TEXT("ERROR : %s\n"),x);
01210
01212 #define _MSG(x) _SI_PRINTF(_SI_TEXT("MSG : %s\n"),x);
01213
01215 #define _SI_NEW(x,y) { x = new y; _SI_ASSERT( x != NULL ); }
01216
01218 #define _SI_DELETE( ptr ) { if ( ptr != NULL ) { delete ptr; ptr = NULL; } }
01219
01221 #define _SI_DELETE_ARRAY( ptr ) {if ( ptr != NULL ) { delete [] ptr; ptr = NULL; } }
01222
01227 #define _SI_CALL(x,y) { if (result==SI_SUCCESS) { result = x;if(result != SI_SUCCESS){_ERRMSG(y);}}}
01228
01229 #define _SI_CHKRESULT( RESULT, MESSAGE, ACTION ){if (RESULT != SI_SUCCESS){ _ERRMSG( MESSAGE ); ACTION; } }
01230
01231 XSICOREEXPORT SI_Char * si_strdup( const SI_Char * );
01232 XSICOREEXPORT SI_Char * si_bstrdup( const SI_Byte * );
01233 XSICOREEXPORT SI_Error si_bstringtostring( SI_Char *, const SI_Byte * );
01234 XSICOREEXPORT SI_Void si_splitpath(const SI_Char *, SI_Char *, SI_Char *, SI_Char *, SI_Char *);
01235
01236 #define _SI_STRDUPL(D,S) { D = (char *) alloca(strlen(S)); strcpy(D,S); }
01237
01238 #ifdef __cplusplus //If included by C-files this causes an error
01239
01240 #ifdef _INLINETRIG_
01241 extern float SI_SineTable[62831];
01242 extern float SI_CosineTable[62831];
01243 #endif
01244
01245
01246
01247
01248
01250
01254 class XSICOREEXPORT CSIBCUtil
01255 {
01256 public:
01257
01261 CSIBCUtil();
01262 ~CSIBCUtil();
01263
01274 static SI_Error Open(SI_Char *in_pFilename);
01275
01285 static SI_Error Close();
01286
01290 static void SetToStderr();
01291
01298 static void printf(SI_Char * str,...);
01299
01300
01301
01306 static void InitializeTrigTables();
01307
01314 static float cos(float x);
01315
01322 static float sin(float x);
01323
01324 protected:
01325 static SI_Char m_Filename[256];
01326
01327 private:
01328 SI_Void *m_pUnused;
01329
01330 };
01331
01332 #endif
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348 inline float CSIBCUtil::cos(float x)
01349 {
01350 #ifdef _INLINETRIG_
01351 int index = (int) ( x * 10000.0f);
01352
01353 if (index < 0)
01354 index += 628310000;
01355
01356 return SI_CosineTable[index % 62831];
01357 #else
01358 return _SI_COSF(x);
01359 #endif
01360 }
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370 inline float CSIBCUtil::sin(float x)
01371 {
01372 #ifdef _INLINETRIG_
01373 int index = (int) ( x * 10000.0f);
01374
01375 if (index < 0)
01376 index += 628310000;
01377
01378 return SI_SineTable[index % 62831];
01379 #else
01380 return _SI_SINF(x);
01381 #endif
01382 }
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393 class SIFileInterface
01394 {
01395 public:
01396 virtual ~SIFileInterface()
01397 {
01398 }
01399
01400
01401 virtual int close() = 0;
01402
01403 virtual size_t read( void *pbuffer, size_t size, size_t count ) = 0;
01404
01405 virtual size_t write( const void *buffer, size_t size, size_t count ) = 0;
01406
01407 virtual int printf( const char *format ) = 0;
01408
01409 virtual int seek( LONG offset, int origin ) = 0;
01410
01411 virtual LONG tell() = 0;
01412
01413 virtual int fgetc() = 0;
01414
01415 virtual int eof() = 0;
01416
01417 virtual int error() = 0;
01418
01419 virtual int flush() = 0;
01420
01421 virtual int siungetc( int ch ) = 0;
01422
01423
01424 virtual operator __SI_FILE() = 0;
01425
01426
01427
01428
01429 };
01430 class SIFile: public SIFileInterface
01431 {
01432 private:
01433 __SI_FILE fp;
01434
01435 public:
01436 enum openMode
01437 {
01438 Read_Text = 0,
01439 Read_Binary,
01440 Write_Text,
01441 Write_Binary,
01442 };
01443
01444 enum seekDir
01445 {
01446 #ifdef __SI_FILE_SET
01447 sdSet = __SI_FILE_SET,
01448 #endif
01449 #ifdef __SI_FILE_CUR
01450 sdCur = __SI_FILE_CUR,
01451 #endif
01452 #ifdef __SI_FILE_END
01453 sdEnd = __SI_FILE_END,
01454 #endif
01455 };
01456
01457
01458
01459 SIFile(): fp( __SI_FILE_NULL ) {}
01460
01461 SIFile( __SI_FILE file ): fp( file ) {}
01462
01463 SIFile( const char *name, int mode )
01464 {
01465 #ifdef __SI_FOPEN
01466 static __SI_FILE_MODE const mt[] =
01467 {
01468 #ifdef __SI_FILE_READ_TEXT
01469 __SI_FILE_READ_TEXT,
01470 #else
01471 #error you need to define this
01472 #endif
01473 #ifdef __SI_FILE_READ_BINARY
01474 __SI_FILE_READ_BINARY,
01475 #else
01476 #error you need to define this
01477 #endif
01478 #ifdef __SI_FILE_WRITE_TEXT
01479 __SI_FILE_WRITE_TEXT,
01480 #else
01481 #error you need to define this
01482 #endif
01483 #ifdef __SI_FILE_WRITE_BINARY
01484 __SI_FILE_WRITE_BINARY,
01485 #else
01486 #error you need to define this
01487 #endif
01488 };
01489 fp = __SI_FOPEN( (char*)name, mt[mode] );
01490 #else
01491 #error you need to define this
01492 #endif
01493 }
01494
01495
01496 int close()
01497 {
01498 #ifdef __SI_FCLOSE
01499 int temp = __SI_FCLOSE( fp );
01500 fp = __SI_FILE_NULL;
01501 return temp;
01502 #else
01503 _SI_ASSERT( false );
01504 return 0;
01505 #endif
01506 }
01507
01508 size_t read( void *buffer, size_t size, size_t count )
01509 {
01510 #ifdef __SI_FREAD
01511 return __SI_FREAD( buffer, size, count, fp );
01512 #else
01513 _SI_ASSERT( false );
01514 return 0;
01515 #endif
01516 }
01517
01518 size_t write( const void *buffer, size_t size, size_t count )
01519 {
01520 #ifdef __SI_FWRITE
01521 return __SI_FWRITE( (void*)buffer, size, count, fp );
01522 #else
01523 _SI_ASSERT( false );
01524 return 0;
01525 #endif
01526 }
01527
01528 int printf( const char *format )
01529 {
01530 #ifdef __SI_FPRINTF
01531 return __SI_FPRINTF( fp, format );
01532 #else
01533 _SI_ASSERT( false );
01534 return 0;
01535 #endif
01536 }
01537
01538 int seek( LONG offset, int origin )
01539 {
01540 #ifdef __SI_FSEEK
01541 return __SI_FSEEK( fp, offset, origin );
01542 #else
01543 _SI_ASSERT( false );
01544 return 0;
01545 #endif
01546 }
01547
01548 LONG tell()
01549 {
01550 #ifdef __SI_FTELL
01551 return __SI_FTELL( fp );
01552 #else
01553 _SI_ASSERT( false );
01554 return 0;
01555 #endif
01556 }
01557
01558 int fgetc()
01559 {
01560 #ifdef __SI_FGETC
01561 return __SI_FGETC( fp );
01562 #else
01563 _SI_ASSERT( false );
01564 return 0;
01565 #endif
01566 }
01567
01568 int eof()
01569 {
01570 #ifdef __SI_FEOF
01571 return __SI_FEOF( fp );
01572 #else
01573 _SI_ASSERT( false );
01574 return 0;
01575 #endif
01576 }
01577
01578 int error()
01579 {
01580 #ifdef __SI_FERROR
01581 return __SI_FERROR( fp );
01582 #else
01583 _SI_ASSERT( false );
01584 return 0;
01585 #endif
01586 }
01587
01588 int flush()
01589 {
01590 #ifdef __SI_FFLUSH
01591 return __SI_FFLUSH( fp );
01592 #else
01593 _SI_ASSERT( false );
01594 return 0;
01595 #endif
01596 }
01597
01598 int siungetc( int ch )
01599 {
01600 #ifdef __SI_UNGETC
01601 return __SI_UNGETC( ch, fp );
01602 #else
01603 _SI_ASSERT( false );
01604 return 0;
01605 #endif
01606 }
01607
01608
01609 operator __SI_FILE()
01610 {
01611 return fp;
01612 }
01613
01614
01615
01616
01617
01618
01619 SIFile operator=( __SI_FILE const& other )
01620 {
01621 fp = other;
01622 return *this;
01623 }
01624
01625 SIFile operator=( SIFile const& other )
01626 {
01627 fp = other.fp;
01628 return *this;
01629 }
01630 };
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643 #if defined( _XBOX ) || defined( _PSX2 )
01644 class BufferedFile: public SIFileInterface
01645 {
01646 private:
01647 char *buffer;
01648 int goodBytes;
01649 int position;
01650 unsigned int bufferSize;
01651 SIFile fp;
01652
01653
01654
01655
01656
01657 public:
01658
01659 BufferedFile(): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp()
01660 {
01661 }
01662
01663 BufferedFile( __SI_FILE fpIn ): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp( fpIn )
01664 {
01665 }
01666
01667 BufferedFile( const char *name, int mode, unsigned int bs ): buffer( new char[bs] ), goodBytes(0), position(0), bufferSize( bs ), fp()
01668 {
01669 fp = SIFile( name, mode );
01670 }
01671
01672 virtual ~BufferedFile()
01673 {
01674 if( buffer!=NULL ) delete [] buffer;
01675 }
01676
01677
01678 void clearBuffer()
01679 {
01680 goodBytes = 0;
01681 }
01682
01683 void reseekBuffer()
01684 {
01685 int seekdistance = position-goodBytes;
01686 if( seekdistance==0 ) return;
01687 fp.seek( seekdistance, SIFile::sdCur );
01688 position = 0;
01689 clearBuffer();
01690 }
01691
01692 unsigned int fillBuffer()
01693 {
01694 reseekBuffer();
01695 goodBytes = fp.read( buffer, 1, bufferSize );
01696 #ifdef _PSX2
01697 if (goodBytes < 0)
01698 goodBytes = 0;
01699 #endif
01700 position = 0;
01701 return goodBytes;
01702 }
01703
01704 unsigned int remainingBytesInBuffer()
01705 {
01706 return goodBytes-position;
01707 }
01708
01709
01710 int close()
01711 {
01712 clearBuffer();
01713 return fp.close();
01714 }
01715
01716 size_t read( void *pbuffer, size_t size, size_t count )
01717 {
01718 if( size*count<=bufferSize )
01719
01720 {
01721 char *dest = (char*)pbuffer;
01722 int copiedWords = 0;
01723
01724 while( count>0 )
01725 {
01726 if( remainingBytesInBuffer()<size )
01727 {
01728 if( fillBuffer()<size )
01729 {
01730 break;
01731 }
01732 }
01733
01734
01735 {
01736 int copyWords = min( remainingBytesInBuffer()/size, count );
01737 int copyBytes = copyWords * size;
01738
01739 _SI_MEMCPY( dest, buffer+position, copyBytes );
01740
01741 dest += copyBytes;
01742 position += copyBytes;
01743
01744 copiedWords += copyWords;
01745 count -= copyWords;
01746 }
01747 }
01748
01749 return copiedWords;
01750 }
01751 else
01752 {
01753 reseekBuffer();
01754 clearBuffer();
01755 return fp.read( pbuffer, size, count );
01756 }
01757 }
01758
01759 size_t write( const void *buffer, size_t size, size_t count )
01760 {
01761 reseekBuffer();
01762 clearBuffer();
01763 return fp.write( buffer, size, count );
01764 }
01765
01766 int printf( const char *format )
01767 {
01768 reseekBuffer();
01769 clearBuffer();
01770 return fp.printf( format );
01771 }
01772
01773 int seek( LONG offset, int origin )
01774 {
01775 if( origin==SIFile::sdCur )
01776 {
01777 offset+=position-goodBytes;
01778 }
01779 position = 0;
01780 clearBuffer();
01781 return fp.seek( offset, origin );
01782 }
01783
01784 LONG tell()
01785 {
01786 return fp.tell() + position;
01787 }
01788
01789 int fgetc()
01790 {
01791 char retval;
01792 if( read( &retval, 1, 1 )==0 )
01793 {
01794 return fp.fgetc();
01795 }
01796 return retval;
01797 }
01798
01799 int eof()
01800 {
01801 if( goodBytes > position ) return 0;
01802 reseekBuffer();
01803 return fp.eof();
01804 }
01805
01806 int error()
01807 {
01808 reseekBuffer();
01809 return fp.error();
01810 }
01811
01812 int flush()
01813 {
01814
01815 return fp.flush();
01816 }
01817
01818 int siungetc( int ch )
01819 {
01820 reseekBuffer();
01821 clearBuffer();
01822 return fp.siungetc( ch );
01823 }
01824
01825
01826 operator SIFile()
01827 {
01828 reseekBuffer();
01829 clearBuffer();
01830 return fp;
01831 }
01832
01833 operator __SI_FILE()
01834 {
01835 reseekBuffer();
01836 clearBuffer();
01837 return fp;
01838 }
01839
01840
01841
01842
01843
01844 };
01845 #endif
01846
01847 class SIFilePtr
01848 {
01849 private:
01850 SIFileInterface *fp;
01851
01852 public:
01853 SIFilePtr()
01854 {
01855 fp = NULL;
01856 }
01857
01858 SIFilePtr( __SI_FILE file )
01859 {
01860 fp = NULL;
01861 this->operator=( file );
01862 }
01863
01864
01865 SIFilePtr( const char *name, int mode )
01866 {
01867 #if (defined _XBOX) || (defined _PSX2)
01868 fp = (SIFileInterface*)new BufferedFile( name, mode, 2048 );
01869 #elif (defined unix) \
01870 || ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX) \
01871 || (defined _WIN32_WCE)
01872 fp = (SIFileInterface*)new SIFile( name, mode );
01873 #else
01874
01875 fp = (SIFileInterface*)new SIFile( name, mode );
01876 #endif
01877 }
01878
01879 ~SIFilePtr()
01880 {
01881 }
01882
01883
01884 int close()
01885 {
01886 int retval = fp->close();
01887 delete fp;
01888 return retval;
01889 }
01890
01891 size_t read( void *pbuffer, size_t size, size_t count )
01892 {
01893 return fp->read( pbuffer, size, count );
01894 }
01895
01896 size_t write( const void *buffer, size_t size, size_t count )
01897 {
01898 return fp->write( buffer, size, count );
01899 }
01900
01901 int printf( const char *format )
01902 {
01903 return fp->printf( format );
01904 }
01905
01906 int seek( LONG offset, int origin )
01907 {
01908 return fp->seek( offset, origin );
01909 }
01910
01911 LONG tell()
01912 {
01913 return fp->tell();
01914 }
01915
01916 int fgetc()
01917 {
01918 return fp->fgetc();
01919 }
01920
01921 int eof()
01922 {
01923 return fp->eof();
01924 }
01925
01926 int error()
01927 {
01928 return fp->error();
01929 }
01930
01931 int flush()
01932 {
01933 return fp->flush();
01934 }
01935
01936 int siungetc( int ch )
01937 {
01938 return fp->siungetc( ch );
01939 }
01940
01941
01942
01943 operator __SI_FILE()
01944 {
01945 if( fp==NULL ) return __SI_FILE_NULL;
01946 return (__SI_FILE)(*fp);
01947 }
01948
01949
01950
01951
01952
01953
01954
01955 SIFilePtr& operator=( __SI_FILE const & other )
01956 {
01957 if( other == __SI_FILE_NULL )
01958 {
01959 fp = NULL;
01960 }
01961 else
01962 {
01963 fp = (SIFileInterface*)new SIFile( other );
01964 }
01965 return *this;
01966 }
01967
01968 SIFilePtr& operator=( const SIFilePtr &other )
01969 {
01970
01971 if (this != &other) {
01972 fp = other.fp;
01973 }
01974 return *this;
01975 }
01976 };
01977
01978 typedef SIFilePtr _SI_FILE;
01979
01980 XSICOREEXPORT SI_Char si_getc( _SI_FILE x );
01981 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, _SI_FILE x );
01982
01983
01984
01985 #define _SI_FILE_MODE SIFile::openMode
01986 #define _SI_FILE_NULL __SI_FILE_NULL
01987 #define _SI_FILE_READ_TEXT (SIFile::Read_Text)
01988 #define _SI_FILE_READ_BINARY (SIFile::Read_Binary)
01989 #define _SI_FILE_WRITE_TEXT (SIFile::Write_Text)
01990 #define _SI_FILE_WRITE_BINARY (SIFile::Write_Binary)
01991 #define _SI_FILE_SET (SIFile::sdSet)
01992 #define _SI_FILE_CUR (SIFile::sdCur)
01993 #define _SI_FILE_END (SIFile::sdEnd)
01994 #define _SI_IS_FILE_MODE( a, b ) ((a)==(b))
01995 #define _SI_FOPEN( name, mode ) (_SI_FILE( name, mode ))
01996 #define _SI_FCLOSE( x ) ((x).close())
01997 #define _SI_FREAD( a, b, c, d ) ((d).read( a, b, c ))
01998 #define _SI_FWRITE( a, b, c, d ) ((d).write( a, b, c ))
01999 #define _SI_FPRINTF( a, b ) ((a).printf( b ))
02000 #define _SI_FSEEK( ptr, count, type ) ((ptr).seek( count, type ))
02001 #define _SI_FTELL( ptr ) ((ptr).tell())
02002 #define _SI_FGETC( fp ) ((fp).fgetc())
02003 #define _SI_FEOF( x ) ((x).eof())
02004 #define _SI_FERROR( x ) ((x).error())
02005 #define _SI_FFLUSH( fp ) ((fp).flush())
02006 #define _SI_UNGETC( fp ) ((fp).siungetc())
02007
02008
02009
02010
02011
02012
02013
02014 typedef SI_Void (*SI_WARNING_CALLBACK_FNC) ( SI_Char*, SI_Int );
02015 #define SI_MESSAGE 0
02016 #define SI_WARNING 1
02017 #define SI_ERROR 2
02018
02019
02020
02021
02022
02023 XSICOREEXPORT void * FTK_calloc( size_t, size_t );
02024 XSICOREEXPORT void FTK_free( void * );
02025 XSICOREEXPORT void FTK_delete( void * );
02026
02027
02028
02029
02030
02031
02032
02033 class CSIBCString;
02034 SI_Error FTK_GetURLParts(char* in_pURL, CSIBCString* out_pScheme, CSIBCString* out_pAuthority, CSIBCString* out_pPath, CSIBCString* out_pQuery, CSIBCString* out_pFragment);
02035 void FTK_ConvertStringFromURL(CSIBCString &io_String);
02036 void FTK_ConvertStringToURL(CSIBCString &io_String);
02037
02038 #endif // CSIBCUtil