home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-04 | 2.8 KB | 127 lines | [TEXT/CWIE] |
- // MADE - Macintosh Application Development Essentials
- // ---------------------------------------------------
-
- // (c) Gideon Greenspan, Sig Software - June 1997 - http://www.kagi.com/gdg/
-
- // These files can only be used for experimental standalone purposes. To obtain
- // fully commented code, and licenses for standalone, shareware, internal and
- // commercial usage, run the enclosed Register application.
-
- // Essential Errors.c
- //
- // Error checking, handling, reporting and assertion support.
- //
- // Version 1.0.0 - 10th November 1996
-
- #include "Essential Headers.h"
- #include "Essential Prototypes.h"
-
- #if Project_Under_Development
-
- void HandleAssertFailure(char* file, char* date, int line)
- {
- Str255 fileString, dateString, lineString, memoryString;
- unsigned char *stringPtr;
-
- stringPtr=fileString+1;
- while (*stringPtr++=*file++);
- *fileString=stringPtr-fileString-2;
-
- stringPtr=dateString+1;
- while (*stringPtr++=*date++);
- *dateString=stringPtr-dateString-2;
-
- NumToString(line, lineString);
- NumToString(MaxBlock(), memoryString);
-
- ParamText(fileString, dateString, lineString, memoryString);
-
- switch (Alert(32767, 0)) {
- case 1:
- Debugger();
- break;
- case 2:
- ExitToShell();
- break;
- case 3:
- ExecutionBody();
- break;
- case 4:
- break;
- }
- }
-
- #endif
-
- void TestError(Error error)
- {
- Str255 IDString, messageString;
- short numString, totalStrings, compareError;
- Handle errorsResource;
- char *errorStrings;
- unsigned char charsToCopy, *messagePointer;
-
- if (error) {
- NumToString(error, IDString);
-
- errorsResource=GetResource('ErrS', 128);
- if (ResError() || errorsResource==0)
- SysBeep(1); // If that failed, then we're really in trouble so just beep!
-
- else {
- errorStrings=*errorsResource;
- totalStrings=*(short*)errorStrings;
- errorStrings+=sizeof(short);
-
- for (numString=0; numString<totalStrings; numString++) {
- compareError=*(short*)errorStrings;
- errorStrings+=sizeof(short);
-
- if (compareError==error) {
-
- charsToCopy=*(unsigned char*)errorStrings+1;
- messagePointer=messageString;
-
- while (charsToCopy--)
- *messagePointer++=*errorStrings++;
- goto stringFound;
-
- } else
- errorStrings+=*(unsigned char*)errorStrings+1;
- }
-
- *messageString=0;
-
- stringFound:
- ParamText(IDString, messageString, 0, 0);
- Alert(128, 0);
- }
- }
- }
-
- Error TestResError(void* resource)
- {
- Error error;
-
- error=ResError();
- if (!error)
- if (resource==0L)
- error=resNotFound; // It is unclear which error it should be, so this will do
- TestError(error);
-
- return error;
- }
-
- Error TestMemError(void* pointer)
- {
- Error error;
-
- error=MemError();
- if (!error)
- if (pointer==0L)
- error=memFullErr; // It is unclear which error it should be, so this will do
- TestError(error);
-
- return error;
- }
-