#ifndef _c_O_S_Err_Lookup_h #define _c_O_S_Err_Lookup_h // =========================================================================== // cOSErrLookup.h Version 1.0 ©1999 Joakim Braun All rights reserved. // =========================================================================== // // CONTENTS: cOSErrLookup: A PowerPlant class for looking up operating system errors // and viewing their text constants and descriptions. // REQUIRES: Jim Luther's MoreFiles package (to be found on any infoMac site). // Also requires several PowerPlant classes. // HOW TO USE: Accompanying this file should be a resource file called "Errors.rsrc". // Include it in your app, and you will be able to use cOSErrLookup's two main static methods: // Boolean GetOSErrDescription(ResIDT inResID, OSErr inErr, Str255 outErrorConstant, Str255 outErrorDescription); // void SignalOSErr(OSErr inErr, ResIDT inResID = eErrorResourceID); // They do what you'd expect them to: Use data in the resource to extract the C constant for // the error (e g, -108 is "memFullErr"), as well as the descriptive text, if any. // SignalOSErr() will signal using these strings if inErr != noErr. // cOSErrLookup also includes methods for compiling your own 'err#' resources from simple text files, // as well as decompiling them and dumping them to a text file. Note that you can't compile // header files directly, see description below under "Compile()". // CAVEAT: The error resource included was compiled using TexEdit, AppleScript and lots of search and replace // on the "Errors.h" header of the Universal Interfaces 3.0.1. "Errors.h" doesn't have very much // in the way of descriptive error strings, and hunting through Inside Mac is something I'll leave // for someone else to do. If you have Resorcerer, you can easily alter or supplement the included // 'err#' resource to suit your needs. // These classes are free for any and all use. // Do not distribute modified source code under my name. // No support promised, no liability accepted. Provided "as is". // That said, I can be reached at braun@swipnet.se. // Change history: // 1.0 January 4, 1999 First release #include class cOSErrLookup{ public: enum { eErrorResourceType = 'err#', eErrorResourceID = 128 }; static Boolean GetOSErrDescription(ResIDT inResID, OSErr inErr, Str255 outErrorConstant, Str255 outErrorDescription); static void SignalOSErr(OSErr inErr, ResIDT inResID = eErrorResourceID); static void CompileTextFile(ResIDT inTgtResID = eErrorResourceID); static void DecompileResource(ResIDT inSrcResID = eErrorResourceID); protected: typedef struct errorSpec{ OSErr error; Str63 errorConstant; Str255 errorDescription; }; static Boolean MakeSpecArray(ResIDT inResID, TArray& outArray); static void Compile(ifstream& inFileStream, ResIDT inTgtResID); static Handle Decompile(ResIDT inSrcResID); }; class cErrorSpecComparator : public LComparator{ public: cErrorSpecComparator(void){} virtual Int32 Compare( const void* inItemOne, const void* inItemTwo, Uint32 inSizeOne, Uint32 inSizeTwo) const; virtual Int32 CompareToKey( const void* inItem, Uint32 inSize, const void* inKey) const; }; #endif