home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
- * error.c
- *
- * Error Handling Package
- *
- * Written by Paco Xander Nathan
- * ⌐1990, Motorola Inc. Public domain source code.
- ********************************************************************************/
-
- #include "applic.h"
- #include "dialog.h"
- #include "error.h"
- #include "string.h"
- #include <MemoryMgr.h>
-
-
- /* External Data Structures
- */
- Handle
- errAvatarHdl = NULL;
-
-
- /* Present a warning error dialog to the user... Can ask the user whether or not
- * to exit gracefully and then call ApplQuit.
- */
- short
- ErrWarning (nButtons, isFatal, p1, p2, p3, p4)
- register short nButtons;
- register Boolean isFatal;
- register StringPtr p1, p2, p3, p4;
- {
- register short result = 0;
-
- /* Stuff the specified strings into the alert and force the cursor to be an arrow
- */
- ParamText(p1, p2, p3, p4);
- InitCursor();
-
- /* Call the appropriate alert template, based on nButtons
- */
- switch (nButtons) {
- case warnYes:
- result = Alert(continueAlertID, (Ptr) DlogModalEvent);
- break;
-
- case warnNo:
- result = Alert(yesnoAlertID, (Ptr) DlogModalEvent);
- break;
-
- case warnCancel:
- result = Alert(cancelAlertID, (Ptr) DlogModalEvent);
- break;
-
- default:
- break;
- }
-
- /* If we need to die, go mercifully... Otherwise return the user's choice
- */
- if (isFatal && (result == warnYes))
- ApplQuit();
-
- return result;
- }
-
-
- /* In case our application cannot get enough memory, please squeek about it.
- */
- pascal long
- ErrGrowZone (needed)
- register long needed;
- {
- register Size theSize = 0L;
- static Str255 param1, param2, param3;
-
- /* Going to first get rid of the avatar handle... Invoke the
- * goddess of the MemoryMgr to intervene on behalf of this
- * application
- */
- if (errAvatarHdl) {
- theSize = GetHandleSize(errAvatarHdl);
- DisposHandle(errAvatarHdl);
- errAvatarHdl = NULL;
- }
-
- /* Pull in the needed strings
- */
- GetIndString(param1, strsConverse, strApplName);
- GetIndString(param2, strsConverse, strNoMem);
- GetIndString(param3, strsConverse, strExitGrace);
-
- /* Now, ask whether the user wishes to die mercifully or by tempting
- * Fate and continuing with a mortally wounded application. If the
- * has industrial strength computing balls and continues, then we
- * don't need to be careful anymore, so free the locked last resort
- * warning alert DITL.
- */
- (void) ErrWarning(warnNo, TRUE, param1, param2, param3, NullStr);
- FreeAlert(yesnoAlertID);
-
- return theSize;
- }
-
-
- /* Attempt to allocate memory, error check the result and notify the user in the
- * event of a failure, otherwise return a pointer to the requested memory block.
- */
- Ptr
- ErrNewPtr (theSize)
- register Size theSize;
- {
- register Ptr result = NULL;
- Str255 param1, param2, param3;
-
- if (!(result = NewPtr(theSize))) {
- /* Pull in the needed strings
- */
- GetIndString(param1, strsConverse, strMemFail);
- GetIndString(param2, strsConverse, strDontPanic);
- GetIndString(param3, strsConverse, strExitGrace);
-
- (void) ErrWarning(warnNo, TRUE, param1, param2, param3, NullStr);
- }
-
- return result;
- }
-
-
- /* Attempt to allocate a new handle, error check the result and notify the user in
- * the event of a failure, otherwise return a handle to the requested memory block.
- */
- Handle
- ErrNewHandle (theSize)
- register Size theSize;
- {
- register Handle result = NULL;
- Str255 param1, param2, param3;
-
- if (!(result = NewHandle(theSize)) || !(*result)) {
- /* Pull in the needed strings
- */
- GetIndString(param1, strsConverse, strMemFail);
- GetIndString(param2, strsConverse, strDontPanic);
- GetIndString(param3, strsConverse, strExitGrace);
-
- (void) ErrWarning(warnNo, TRUE, param1, param2, param3, NullStr);
- }
-
- return result;
- }
-
-
- /* Signal a file error to the user.
- */
- void
- ErrFileMgr (errNum, fileName)
- register OSErr errNum;
- register StringPtr fileName;
- {
- Str255 param1, errStr;
-
- /* Pull in the needed strings
- */
- GetIndString(param1, strsConverse, strFileErr);
- NumToString(errNum, errStr);
-
- (void) ErrWarning(warnYes, FALSE, param1, fileName, errStr, NullStr);
- }
-