2019-06-25 21:18:44 -07:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glk/alan3/syserr.h"
|
|
|
|
#include "glk/alan3/current.h"
|
|
|
|
#include "glk/alan3/debug.h"
|
|
|
|
#include "glk/alan3/glkio.h"
|
|
|
|
#include "glk/alan3/output.h"
|
|
|
|
#include "glk/alan3/utils.h"
|
2019-07-02 19:54:32 -07:00
|
|
|
#include "common/textconsole.h"
|
2019-06-25 21:18:44 -07:00
|
|
|
|
|
|
|
namespace Glk {
|
|
|
|
namespace Alan3 {
|
|
|
|
|
2019-06-26 19:37:00 -07:00
|
|
|
static void (*handler)(const char *);
|
2019-06-25 21:18:44 -07:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
2019-07-02 19:54:32 -07:00
|
|
|
static void runtimeError(CONTEXT, const char *errorClassification, const char *errorDescription, const char *blurb) {
|
2019-06-27 04:02:48 +01:00
|
|
|
output("$n$nAs you enter the twilight zone of Adventures, you stumble \
|
2019-06-25 21:18:44 -07:00
|
|
|
and fall to your knees. In front of you, you can vaguely see the outlines \
|
|
|
|
of an Adventure that never was.$n$n");
|
2019-06-27 04:02:48 +01:00
|
|
|
output(errorClassification);
|
|
|
|
output(errorDescription);
|
|
|
|
newline();
|
2019-06-25 21:18:44 -07:00
|
|
|
|
2019-06-27 04:02:48 +01:00
|
|
|
if (current.sourceLine != 0) {
|
|
|
|
printf("At source line %d in '%s':\n", current.sourceLine, sourceFileName(current.sourceFile));
|
|
|
|
printf("%s", readSourceLine(current.sourceFile, current.sourceLine));
|
|
|
|
}
|
2019-06-25 21:18:44 -07:00
|
|
|
|
2019-06-27 04:02:48 +01:00
|
|
|
newline();
|
|
|
|
output(blurb);
|
2019-06-25 21:18:44 -07:00
|
|
|
|
2019-07-02 19:54:32 -07:00
|
|
|
terminate(context, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void runtimeError(const char *errorClassification, const char *errorDescription, const char *blurb) {
|
2019-07-02 20:05:06 -07:00
|
|
|
::error("%s%s %s", errorClassification, errorDescription, blurb);
|
2019-06-25 21:18:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
2019-06-27 04:02:48 +01:00
|
|
|
void setSyserrHandler(void (*f)(const char *)) {
|
|
|
|
handler = f;
|
2019-06-25 21:18:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
// TODO Make syserr() use ... as printf()
|
2019-06-27 04:02:48 +01:00
|
|
|
void syserr(const char *description) {
|
|
|
|
lin = 0;
|
2021-11-13 23:40:25 +02:00
|
|
|
if (handler == nullptr) {
|
2019-06-26 19:37:00 -07:00
|
|
|
const char *blurb = "<If you are the creator of this piece of Interactive Fiction, \
|
2019-06-25 21:18:44 -07:00
|
|
|
please help debug this Alan system error. Collect *all* the sources, and, if possible, an \
|
|
|
|
exact transcript of the commands that led to this error, in a zip-file and send \
|
|
|
|
it to support@alanif.se. Thank you!>";
|
2019-06-27 04:02:48 +01:00
|
|
|
runtimeError("SYSTEM ERROR: ", description, blurb);
|
|
|
|
} else
|
|
|
|
handler(description);
|
2019-06-25 21:18:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
2019-06-27 04:02:48 +01:00
|
|
|
void apperr(const char *description) {
|
2021-11-13 23:40:25 +02:00
|
|
|
if (handler == nullptr) {
|
2019-06-26 19:37:00 -07:00
|
|
|
const char *blurb = "<If you are playing this piece of Interactive Fiction, \
|
2019-06-25 21:18:44 -07:00
|
|
|
please help the author to debug this programming error. Send an exact \
|
|
|
|
transcript of the commands that led to this error to the author. Thank you! \
|
|
|
|
If you *are* the author, then you have to figure this out before releasing the game.>";
|
2019-06-27 04:02:48 +01:00
|
|
|
runtimeError("APPLICATION ERROR: ", description, blurb);
|
|
|
|
} else
|
|
|
|
handler(description);
|
2019-06-25 21:18:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================*/
|
2019-07-02 19:54:32 -07:00
|
|
|
void playererr(CONTEXT, const char *description) {
|
2021-11-13 23:40:25 +02:00
|
|
|
if (handler == nullptr) {
|
2019-06-27 04:02:48 +01:00
|
|
|
const char *blurb = "<You have probably done something that is not exactly right.>";
|
2019-07-02 19:54:32 -07:00
|
|
|
runtimeError(context, "PLAYER ERROR: ", description, blurb);
|
2019-06-27 04:02:48 +01:00
|
|
|
} else
|
|
|
|
handler(description);
|
2019-06-25 21:18:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Alan3
|
|
|
|
} // End of namespace Glk
|