home *** CD-ROM | disk | FTP | other *** search
- /* $Id: 3dcofail.cpp 1.19 1997/07/10 01:21:01 john Exp $ */
- /*****************************************************************************\
- * *
- * 3DCoFail.cpp *
- * Failure handling for COM extensions *
- * *
- * Copyright (c) 1995, Ray Dream, Inc. All rights reserved. *
- * *
- \*****************************************************************************/
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- #ifndef __I3DSHUTI__
- #include "I3DShUti.h"
- #endif
-
- #ifndef __ISHSMP__
- #include "IShSMP.h"
- #endif
-
- #ifdef __MWERKS__
- #define SIZE_T unsigned long
- #else
- #define SIZE_T unsigned int
- #endif
-
-
- #include "String.h"
- #include <stdlib.h>
-
- IShUtilities* gShellUtilities = NULL;
- IShActionManager* gActionManager = NULL;
- IShMenuManager* gMenuManager = NULL;
- IShViewManager* gViewManager = NULL;
- IShSMPUtilities* gShellSMPUtilities = NULL;
-
- extern "C" {
- RDsetjmpProc RDsetjmp;
- }
-
- void QuitExtension() {
- gShellUtilities=nil;
- }
-
-
- // Initialize gShellUtilities. Must be called to have working failure handling
- void InitCoFailure(IShUtilities* shellUtilities) {
- if (shellUtilities) {
- atexit(QuitExtension);
- gShellUtilities = shellUtilities;
- gShellUtilities->QueryInterface(IID_IShActionManager, (void**)&gActionManager);
- gShellUtilities->QueryInterface(IID_IShMenuManager, (void**)&gMenuManager);
- gShellUtilities->QueryInterface(IID_IShViewManager, (void**)&gViewManager);
- gShellUtilities->QueryInterface(IID_IShSMPUtilities, (void**)&gShellSMPUtilities);
-
- RDsetjmp = (RDsetjmpProc) shellUtilities->GetSetJmpAddress();
- }
- }
-
- void FailNIL(void* apointer) {
- if (!apointer) Failure(-1, 0);
- }
-
- void FailOSErr(short err) {
- if (err) Failure(err, 0);
- }
-
- void __cdecl Failure(short error, long message) {
- if (gShellUtilities) {
- gShellUtilities->Failure(error, message);
- }
- }
-
- FailInfoPtr* __cdecl GetGTopHandler() {
- if (gShellUtilities) {
- return (FailInfoPtr*) gShellUtilities->GetGTopHandler();
- }
- else {
- return NULL;
- }
- }
-
- void* RDmalloc(unsigned long size) {
- if (gShellUtilities) {
- return gShellUtilities->Malloc(size);
- }
- else {
- return NULL;
- }
- }
-
- void* RDcalloc(unsigned long nmemb, unsigned long size) {
- if (gShellUtilities) {
- return gShellUtilities->Calloc(nmemb, size);
- }
- else {
- return NULL;
- }
- }
-
- void* RDrealloc(void* ptr, unsigned long size) {
- if (gShellUtilities) {
- return gShellUtilities->Realloc(ptr, size);
- }
- else {
- return NULL;
- }
- }
-
- void RDfree(void* ptr) {
- if (gShellUtilities && ptr) { //jfs 7/9/97
- gShellUtilities->Free(ptr);
- }
- }
-
-
- // Removed by eg. This function is also defined in RDMemcpy.cpp
-
- #ifdef NEVER
- void RDmemmove(void * dstPtr, void const * srcPtr, long size) {
- memmove(dstPtr, srcPtr, size);
- }
- #endif
-
-
- long RDRandom() {
- if (gShellUtilities) {
- return gShellUtilities->Random();
- }
- else {
- return 0;
- }
- }
-
- void RDSetRandomSeed(long seed) {
- if (gShellUtilities) {
- gShellUtilities->RandomSeed(seed);
- }
- }
-
- void* operator new(SIZE_T byteCount) {
- return RDmalloc(byteCount);
- }
-
- void operator delete(void* block) {
- RDfree(block);
- }
-
- void* __vec_new(void* p, int nb, int size, void* cst) {
- if (!p) {
- p = RDmalloc(nb*size);
- }
- if (p) {
- int i;
- char* pp = (char*)p;
- for (i = 0; i < nb; i++) {
- (*(void(*)(char*)) cst)(pp);
- pp += size;
- }
- return p;
- }
- return 0;
- }
-
- void __vec_delete(void* p, int nb, int size, void* dst, int auto_delete_vec, int auto_delete) {
- if (nb == -1) {
- Failure(-108, 0);
- }
- if (p) {
- int i;
- char* pp;
- pp = ((char*)p) + nb*size;
- for (i = 0; i < nb; i++) {
- pp -= size;
- (*(void(*)(char*, long)) dst)(pp, auto_delete);
- }
- }
- if (p && auto_delete_vec) {
- RDfree(p);
- }
- }
-
- #ifdef _WIN
- extern "C" {
- int __purecall(void) {
- Failure(-3,0);
- return 0;
- }
- int _purecall(void) {
- Failure(-3,0);
- return 0;
- }
- int purecall(void) {
- Failure(-3,0);
- return 0;
- }
- }
- #endif
-
-
-
-
-