syncfiles/macos/error.c
Dietrich Epp d5bfaa510a Clean up Mac OS GUI code
Include paths are updated to include the directory. It seems that
CodeWarrior will search for include files recursively, which means that
"error.h" may resolve to the wrong file (there are two). I am unsure of
the rules CodeWarrior uses to find header files.

Support for older versions of Universal Interfaces has been added.

The project code has been reworked after thoroughly reviewing Inside
Macintosh: Files. It is not complete, but it compiles, and the behavior
of the Save / Save As commands have been thought out more carefully.
2022-11-16 18:19:05 -05:00

76 lines
1.8 KiB
C

// Copyright 2022 Dietrich Epp.
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
#include "macos/error.h"
#include "macos/main.h"
#include "macos/resources.h"
#include "macos/strutil.h"
#include <Dialogs.h>
#include <TextUtils.h>
void ExitError(ErrorCode errCode)
{
Str255 message;
GetIndString(message, rSTRS_Errors, errCode);
if (message[0] == 0) {
GetIndString(message, rSTRS_Errors, kErrUnknown);
}
ParamText(message, NULL, NULL, NULL);
Alert(rAlrtError, NULL);
QuitApp();
}
void ExitErrorOS(ErrorCode errCode, short osErr)
{
Str255 message;
GetIndString(message, rSTRS_Errors, errCode);
if (message[0] == 0) {
GetIndString(message, rSTRS_Errors, kErrUnknown);
}
StrAppendFormat(message, "\p\rError code: %d", osErr);
ParamText(message, NULL, NULL, NULL);
Alert(rAlrtError, NULL);
QuitApp();
}
void ExitMemError(void)
{
ExitErrorOS(kErrOutOfMemory, MemError());
}
void ExitAssert(const unsigned char *file, int line,
const unsigned char *message)
{
Str255 dmessage;
GetIndString(dmessage, rSTRS_Errors, kErrInternal);
StrAppendFormat(dmessage, "\p\rError at: %S:%d", file, line);
if (message != NULL) {
StrAppendFormat(dmessage, "\p: %S", message);
}
ParamText(dmessage, NULL, NULL, NULL);
Alert(rAlrtError, NULL);
QuitApp();
}
void ShowError(const struct ErrorParams *p)
{
Str255 message;
GetIndString(message, rSTRS_Errors, p->err);
if (message[0] == 0) {
GetIndString(message, rSTRS_Errors, kErrUnknown);
} else if (p->strParam != NULL) {
StrSubstitute(message, p->strParam);
}
if (p->osErr != NULL) {
StrAppendFormat(message, "\p\rError code: %d", p->osErr);
}
ParamText(message, NULL, NULL, NULL);
Alert(rAlrtError, NULL);
}