1
0
mirror of https://github.com/pevans/erc-c.git synced 2025-01-02 09:29:58 +00:00

Use log_crit() instead of log_critical()

This change also removes the former log_critical and log_error macros.
This commit is contained in:
Peter Evans 2018-03-29 21:45:25 -05:00
parent 7ca099d0d0
commit d2047457e9
11 changed files with 41 additions and 44 deletions

View File

@ -28,9 +28,6 @@ extern void log_write(int, const char *, ...);
* Here we have a couple of convenience macros that abstracts the log * Here we have a couple of convenience macros that abstracts the log
* level number. * level number.
*/ */
#define log_critical(...) log_write(0, __VA_ARGS__)
#define log_error(...) log_write(0, __VA_ARGS__)
#define log_alert(...) log_write(LOG_ALERT, __VA_ARGS__) #define log_alert(...) log_write(LOG_ALERT, __VA_ARGS__)
#define log_crit(...) log_write(LOG_CRIT, __VA_ARGS__) #define log_crit(...) log_write(LOG_CRIT, __VA_ARGS__)
#define log_debug(...) log_write(LOG_DEBUG, __VA_ARGS__) #define log_debug(...) log_write(LOG_DEBUG, __VA_ARGS__)

View File

@ -80,14 +80,14 @@ apple2_create(int width, int height)
mach->main = vm_segment_create(APPLE2_MEMORY_SIZE); mach->main = vm_segment_create(APPLE2_MEMORY_SIZE);
if (mach->main == NULL) { if (mach->main == NULL) {
log_critical("Could not initialize main RAM!"); log_crit("Could not initialize main RAM!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
mach->cpu = mos6502_create(mach->main, mach->main); mach->cpu = mos6502_create(mach->main, mach->main);
if (mach->cpu == NULL) { if (mach->cpu == NULL) {
log_critical("Could not create CPU!"); log_crit("Could not create CPU!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -96,7 +96,7 @@ apple2_create(int width, int height)
mach->rom = vm_segment_create(APPLE2_ROM_SIZE); mach->rom = vm_segment_create(APPLE2_ROM_SIZE);
mach->aux = vm_segment_create(APPLE2_MEMORY_SIZE); mach->aux = vm_segment_create(APPLE2_MEMORY_SIZE);
if (mach->rom == NULL || mach->aux == NULL) { if (mach->rom == NULL || mach->aux == NULL) {
log_critical("Could not initialize ROM / AUX!"); log_crit("Could not initialize ROM / AUX!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -106,7 +106,7 @@ apple2_create(int width, int height)
apple2_mem_map(mach, mach->aux); apple2_mem_map(mach, mach->aux);
if (apple2_mem_init_sys_rom(mach) != OK) { if (apple2_mem_init_sys_rom(mach) != OK) {
log_critical("Could not initialize apple2 ROM"); log_crit("Could not initialize apple2 ROM");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -117,7 +117,7 @@ apple2_create(int width, int height)
mach->drive2 = apple2_dd_create(); mach->drive2 = apple2_dd_create();
if (mach->drive1 == NULL || mach->drive2 == NULL) { if (mach->drive1 == NULL || mach->drive2 == NULL) {
log_critical("Could not create disk drives!"); log_crit("Could not create disk drives!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -128,7 +128,7 @@ apple2_create(int width, int height)
// Let's build our screen abstraction! // Let's build our screen abstraction!
mach->screen = vm_screen_create(); mach->screen = vm_screen_create();
if (mach->screen == NULL) { if (mach->screen == NULL) {
log_critical("Screen creation failed!"); log_crit("Screen creation failed!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -137,7 +137,7 @@ apple2_create(int width, int height)
// graphics. // graphics.
err = vm_screen_add_window(mach->screen, width, height); err = vm_screen_add_window(mach->screen, width, height);
if (err != OK) { if (err != OK) {
log_critical("Window creation failed!"); log_crit("Window creation failed!");
apple2_free(mach); apple2_free(mach);
return NULL; return NULL;
} }
@ -161,7 +161,7 @@ apple2_create(int width, int height)
0x7f); 0x7f);
if (mach->sysfont == NULL || mach->invfont == NULL) { if (mach->sysfont == NULL || mach->invfont == NULL) {
apple2_free(mach); apple2_free(mach);
log_critical("Could not initialize apple2: bad font"); log_crit("Could not initialize apple2: bad font");
return NULL; return NULL;
} }
@ -239,7 +239,7 @@ apple2_boot(apple2 *mach)
if (stream) { if (stream) {
err = apple2_dd_insert(mach->drive1, stream, DD_DOS33); err = apple2_dd_insert(mach->drive1, stream, DD_DOS33);
if (err != OK) { if (err != OK) {
log_critical("Unable to insert disk1 into drive"); log_crit("Unable to insert disk1 into drive");
return err; return err;
} }
} }
@ -248,7 +248,7 @@ apple2_boot(apple2 *mach)
if (stream) { if (stream) {
err = apple2_dd_insert(mach->drive2, stream, DD_DOS33); err = apple2_dd_insert(mach->drive2, stream, DD_DOS33);
if (err != OK) { if (err != OK) {
log_critical("Unable to insert disk2 into drive"); log_crit("Unable to insert disk2 into drive");
return err; return err;
} }
} }

View File

@ -30,7 +30,7 @@ apple2_dd_create()
drive = malloc(sizeof(apple2dd)); drive = malloc(sizeof(apple2dd));
if (drive == NULL) { if (drive == NULL) {
log_critical("Could not malloc space for apple2 disk drive"); log_crit("Could not malloc space for apple2 disk drive");
return NULL; return NULL;
} }
@ -120,18 +120,18 @@ apple2_dd_insert(apple2dd *drive, FILE *stream, int type)
int err; int err;
if (stream == NULL) { if (stream == NULL) {
log_critical("File stream is null"); log_crit("File stream is null");
return ERR_BADFILE; return ERR_BADFILE;
} }
// How large is this data set? Let's get the stat info. // How large is this data set? Let's get the stat info.
if (fstat(fileno(stream), &finfo)) { if (fstat(fileno(stream), &finfo)) {
log_critical("Couldn't inspect file stream: %s", strerror(errno)); log_crit("Couldn't inspect file stream: %s", strerror(errno));
return ERR_BADFILE; return ERR_BADFILE;
} }
if (finfo.st_size != _140K_) { if (finfo.st_size != _140K_) {
log_critical("Unexpected file format (file size = %d)", finfo.st_size); log_crit("Unexpected file format (file size = %d)", finfo.st_size);
return ERR_BADFILE; return ERR_BADFILE;
} }
@ -145,7 +145,7 @@ apple2_dd_insert(apple2dd *drive, FILE *stream, int type)
// Read the data from the stream and write into the memory segment // Read the data from the stream and write into the memory segment
err = vm_segment_fread(drive->image, stream, 0, finfo.st_size); err = vm_segment_fread(drive->image, stream, 0, finfo.st_size);
if (err != OK) { if (err != OK) {
log_critical("Could not read data into disk drive"); log_crit("Could not read data into disk drive");
return err; return err;
} }
@ -177,7 +177,7 @@ apple2_dd_encode(apple2dd *drive)
break; break;
default: default:
log_critical("Unknown image type"); log_crit("Unknown image type");
return ERR_INVALID; return ERR_INVALID;
} }
@ -220,7 +220,7 @@ apple2_dd_decode(apple2dd *drive)
break; break;
default: default:
log_critical("Unknown image type"); log_crit("Unknown image type");
return ERR_INVALID; return ERR_INVALID;
} }

View File

@ -110,7 +110,7 @@ apple2_mem_init_sys_rom(apple2 *mach)
err = vm_segment_copy_buf(mach->rom, sysrom, err = vm_segment_copy_buf(mach->rom, sysrom,
0, 0, APPLE2_SYSROM_SIZE); 0, 0, APPLE2_SYSROM_SIZE);
if (err != OK) { if (err != OK) {
log_critical("Could not copy apple2 system rom"); log_crit("Could not copy apple2 system rom");
return ERR_BADFILE; return ERR_BADFILE;
} }
@ -118,7 +118,7 @@ apple2_mem_init_sys_rom(apple2 *mach)
APPLE2_SYSROM_SIZE, 0, APPLE2_SYSROM_SIZE, 0,
APPLE2_PERIPHERAL_SIZE); APPLE2_PERIPHERAL_SIZE);
if (err != OK) { if (err != OK) {
log_critical("Could not copy apple2 peripheral rom"); log_crit("Could not copy apple2 peripheral rom");
return ERR_BADFILE; return ERR_BADFILE;
} }

View File

@ -164,7 +164,7 @@ mos6502_create(vm_segment *rmem, vm_segment *wmem)
cpu = malloc(sizeof(mos6502)); cpu = malloc(sizeof(mos6502));
if (cpu == NULL) { if (cpu == NULL) {
log_critical("Not enough memory to allocate mos6502"); log_crit("Not enough memory to allocate mos6502");
exit(1); exit(1);
} }

View File

@ -17,7 +17,7 @@
*/ */
DEFINE_INST(bad) DEFINE_INST(bad)
{ {
log_critical("Invalid instruction: %2x @ %4x", log_crit("Invalid instruction: %2x @ %4x",
mos6502_get(cpu, cpu->PC), cpu->PC); mos6502_get(cpu, cpu->PC), cpu->PC);
exit(1); exit(1);
} }

View File

@ -49,7 +49,7 @@ objstore_init()
// If the copy didn't work out somehow... // If the copy didn't work out somehow...
if (!objstore_ready()) { if (!objstore_ready()) {
log_critical("Object store initialization failed with bad data"); log_crit("Object store initialization failed with bad data");
return ERR_BADFILE; return ERR_BADFILE;
} }

View File

@ -39,7 +39,7 @@ vm_bitfont_create(vm_screen *screen,
// function. // function.
rw = SDL_RWFromConstMem(fontdata, fontsize); rw = SDL_RWFromConstMem(fontdata, fontsize);
if (rw == NULL) { if (rw == NULL) {
log_critical("Failed to create RWops from font data: %s", log_crit("Failed to create RWops from font data: %s",
SDL_GetError()); SDL_GetError());
return NULL; return NULL;
} }
@ -48,14 +48,14 @@ vm_bitfont_create(vm_screen *screen,
// of getting a bitmap from memory rather than loading from a file. // of getting a bitmap from memory rather than loading from a file.
surf = SDL_LoadBMP_RW(rw, 0); surf = SDL_LoadBMP_RW(rw, 0);
if (surf == NULL) { if (surf == NULL) {
log_critical("Failed to create bitmap from RWops: %s", log_crit("Failed to create bitmap from RWops: %s",
SDL_GetError()); SDL_GetError());
return NULL; return NULL;
} }
font = malloc(sizeof(vm_bitfont)); font = malloc(sizeof(vm_bitfont));
if (font == NULL) { if (font == NULL) {
log_critical("Could not allocate memory for font"); log_crit("Could not allocate memory for font");
return NULL; return NULL;
} }
@ -131,7 +131,7 @@ vm_bitfont_render(vm_bitfont *font,
if (SDL_RenderCopy(screen->render, font->texture, if (SDL_RenderCopy(screen->render, font->texture,
&src_rect, &dest_rect) < 0 &src_rect, &dest_rect) < 0
) { ) {
log_critical("Failed to render glyph: %s", SDL_GetError()); log_crit("Failed to render glyph: %s", SDL_GetError());
return ERR_GFXOP; return ERR_GFXOP;
} }
} }

View File

@ -23,7 +23,7 @@ vm_reflect_create()
ref = malloc(sizeof(vm_reflect)); ref = malloc(sizeof(vm_reflect));
if (ref == NULL) { if (ref == NULL) {
log_critical("Could not allocate memory for vm_reflect"); log_crit("Could not allocate memory for vm_reflect");
return NULL; return NULL;
} }

View File

@ -28,7 +28,7 @@ int
vm_screen_init() vm_screen_init()
{ {
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
log_critical("Could not initialize video: %s", SDL_GetError()); log_crit("Could not initialize video: %s", SDL_GetError());
return ERR_GFXINIT; return ERR_GFXINIT;
} }
@ -59,7 +59,7 @@ vm_screen_create()
screen = (vm_screen *)malloc(sizeof(vm_screen)); screen = (vm_screen *)malloc(sizeof(vm_screen));
if (screen == NULL) { if (screen == NULL) {
log_critical("Failed to allocate vm_screen"); log_crit("Failed to allocate vm_screen");
exit(1); exit(1);
} }
@ -114,7 +114,7 @@ vm_screen_add_window(vm_screen *screen, int width, int height)
width, height, 0, &screen->window, &screen->render); width, height, 0, &screen->window, &screen->render);
if (screen->window == NULL || screen->render == NULL) { if (screen->window == NULL || screen->render == NULL) {
log_critical("Could not create window: %s", SDL_GetError()); log_crit("Could not create window: %s", SDL_GetError());
return ERR_GFXINIT; return ERR_GFXINIT;
} }
#endif #endif

View File

@ -41,14 +41,14 @@ vm_segment_create(size_t size)
// Ack! We couldn't get the memory we wanted. Let's bail. // Ack! We couldn't get the memory we wanted. Let's bail.
if (segment == NULL) { if (segment == NULL) {
log_critical("Couldn't allocate enough space for vm_segment"); log_crit("Couldn't allocate enough space for vm_segment");
return NULL; return NULL;
} }
segment->memory = malloc(sizeof(vm_8bit) * size); segment->memory = malloc(sizeof(vm_8bit) * size);
if (segment->memory == NULL) { if (segment->memory == NULL) {
free(segment); free(segment);
log_critical("Couldn't allocate enough space for vm_segment"); log_crit("Couldn't allocate enough space for vm_segment");
return NULL; return NULL;
} }
@ -58,14 +58,14 @@ vm_segment_create(size_t size)
segment->read_table = malloc(sizeof(vm_segment_read_fn) * size); segment->read_table = malloc(sizeof(vm_segment_read_fn) * size);
if (segment->read_table == NULL) { if (segment->read_table == NULL) {
log_critical("Couldn't allocate enough space for segment read_table"); log_crit("Couldn't allocate enough space for segment read_table");
vm_segment_free(segment); vm_segment_free(segment);
return NULL; return NULL;
} }
segment->write_table = malloc(sizeof(vm_segment_write_fn) * size); segment->write_table = malloc(sizeof(vm_segment_write_fn) * size);
if (segment->write_table == NULL) { if (segment->write_table == NULL) {
log_critical("Couldn't allocate enough space for segment write_table"); log_crit("Couldn't allocate enough space for segment write_table");
vm_segment_free(segment); vm_segment_free(segment);
return NULL; return NULL;
} }
@ -103,7 +103,7 @@ vm_segment_set(vm_segment *segment, size_t index, vm_8bit value)
{ {
// Some bounds checking. // Some bounds checking.
if (!vm_segment_bounds_check(segment, index)) { if (!vm_segment_bounds_check(segment, index)) {
log_critical( log_crit(
"Attempt to set segment index (%d) greater than bounds (%d)", "Attempt to set segment index (%d) greater than bounds (%d)",
index, index,
segment->size); segment->size);
@ -130,7 +130,7 @@ vm_8bit
vm_segment_get(vm_segment *segment, size_t index) vm_segment_get(vm_segment *segment, size_t index)
{ {
if (!vm_segment_bounds_check(segment, index)) { if (!vm_segment_bounds_check(segment, index)) {
log_critical( log_crit(
"Attempt to get segment index (%d) greater than bounds (%d)", "Attempt to get segment index (%d) greater than bounds (%d)",
index, index,
segment->size); segment->size);
@ -178,7 +178,7 @@ vm_segment_copy(vm_segment *dest,
size_t length) size_t length)
{ {
if (src_index + length > src->size) { if (src_index + length > src->size) {
log_critical( log_crit(
"Attempt to copy beyond bounds of vm_segment (%d + %d >= %d)", "Attempt to copy beyond bounds of vm_segment (%d + %d >= %d)",
src_index, src_index,
length, length,
@ -188,7 +188,7 @@ vm_segment_copy(vm_segment *dest,
} }
if (dest_index + length > dest->size) { if (dest_index + length > dest->size) {
log_critical( log_crit(
"Attempt to copy beyond bounds of vm_segment (%d + %d >= %d)", "Attempt to copy beyond bounds of vm_segment (%d + %d >= %d)",
dest_index, dest_index,
length, length,
@ -216,7 +216,7 @@ vm_segment_copy_buf(vm_segment *dest, const vm_8bit *src,
size_t destoff, size_t srcoff, size_t len) size_t destoff, size_t srcoff, size_t len)
{ {
if (destoff + len > dest->size) { if (destoff + len > dest->size) {
log_critical("Attempt to copy buffer out of bounds (%d + %d >= %d)", log_crit("Attempt to copy buffer out of bounds (%d + %d >= %d)",
destoff, len, dest->size); destoff, len, dest->size);
return ERR_OOB; return ERR_OOB;
} }
@ -280,7 +280,7 @@ vm_segment_fread(vm_segment *segment, FILE *stream, size_t offset, size_t len)
// count on just that to tell us something went wrong (especially if // count on just that to tell us something went wrong (especially if
// len was not a valid length for the file to begin with). // len was not a valid length for the file to begin with).
if (ferror(stream)) { if (ferror(stream)) {
log_critical("Could not read file stream: %s\n", strerror(errno)); log_crit("Could not read file stream: %s\n", strerror(errno));
return ERR_BADFILE; return ERR_BADFILE;
} }
@ -298,7 +298,7 @@ vm_segment_fwrite(vm_segment *seg, FILE *stream, size_t off, size_t len)
fwrite(seg->memory + off, sizeof(vm_8bit), len, stream); fwrite(seg->memory + off, sizeof(vm_8bit), len, stream);
if (ferror(stream)) { if (ferror(stream)) {
log_critical("Could not write to the file stream: %s", strerror(errno)); log_crit("Could not write to the file stream: %s", strerror(errno));
return ERR_BADFILE; return ERR_BADFILE;
} }