Menu

[b84aab]: / src / common / panic.c  Maximize  Restore  History

Download this file

108 lines (95 with data), 2.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
// This file is part of SmallBASIC
//
// System error manager
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2000 Nicholas Christopoulos
#if defined(_UnixOS)
#include <assert.h>
#endif
#include "common/sys.h"
#include "common/panic.h"
#include <assert.h>
static char preload_panic_buffer[SB_PANICMSG_SIZE + 1];
/**
* Displays a fatal error message
*/
void panic(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(preload_panic_buffer, SB_PANICMSG_SIZE, fmt, ap);
va_end(ap);
#if defined(IMPL_LOG_WRITE)
log_printf(preload_panic_buffer);
#elif defined(_WinGUI) || defined(_Win32)
MessageBox(NULL, preload_panic_buffer, "SB Panic", MB_OK);
#elif defined (__MINGW32__)
MessageBox(NULL, preload_panic_buffer, "SB Panic", MB_OK);
exit(1);
#else
fprintf(stderr, "\n\nPANIC: %s\a\n\n", preload_panic_buffer);
fflush(stderr);
assert(0);
memmgr_setabort(1);
exit(1);
#endif
}
/**
* Displays a warning message
*/
void warning(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsprintf(preload_panic_buffer, fmt, ap);
va_end(ap);
#if defined(IMPL_LOG_WRITE)
log_printf(preload_panic_buffer);
#elif defined(_WinGUI) || defined(_Win32)
MessageBox(NULL, preload_panic_buffer, "SB Warning", MB_OK);
#else // defined(_UnixOS)
fprintf(stderr, preload_panic_buffer, 0);
#endif
}
/**
* Displays a debugging message
*/
void debug(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
strcpy(preload_panic_buffer, "DEBUG: ");
vsprintf(&preload_panic_buffer[7], fmt, ap);
va_end(ap);
#if defined(IMPL_LOG_WRITE)
log_printf(preload_panic_buffer);
#elif defined(_WinGUI) || defined(_Win32)
MessageBox(NULL, preload_panic_buffer, "SB Debug", MB_OK);
#else // defined(_UnixOS)
fprintf(stderr, preload_panic_buffer, 0);
#endif
}
/**
* memory dump
*/
void hex_dump(const unsigned char *block, int size) {
#if defined(_UnixOS) || defined(_DOS)
int i, j;
printf("\n---HexDump---\n\t");
for (i = 0; i < size; i++) {
printf("%02X ", block[i]);
if (((i + 1) % 8) == 0 || (i == size - 1)) {
printf(" ");
for (j = ((i - 7 <= 0) ? 0 : i - 7); j <= i; j++) {
if (block[j] < 32) {
printf(".");
} else {
printf("%c", block[j]);
}
}
printf("\n\t");
}
}
printf("\n");
#endif
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.