From: Hugo Villeneuve Date: Sun, 26 Jan 2014 20:23:48 +0000 (-0500) Subject: Use log functions to display errors X-Git-Tag: v2.0.1~36 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=cc6633f78b5f497c347b656f0c854455871f5efb;p=emu8051.git Use log functions to display errors --- diff --git a/src/common/hexfile.c b/src/common/hexfile.c index 6411166..c879c89 100644 --- a/src/common/hexfile.c +++ b/src/common/hexfile.c @@ -85,8 +85,8 @@ Ascii2Hex(char *istring, int length) result <<= 4; result += ascii_code; } else { - printf("%s: In Ascii2Hex(), syntax error.\n", PACKAGE); - printf(" str=%s, length=%d\n", istring, length); + log_fail("Error converting ASCII string <%s> to hex" + " (len=%d)", istring, length); } } return result; @@ -102,18 +102,14 @@ LoadHexFile(const char *filename) int status; char line[LINE_BUFFER_LEN]; - if (filename == NULL) { - printf("%s: No file specified\n", PACKAGE); - exit(EXIT_FAILURE); - } + if (filename == NULL) + log_fail("No file specified"); /* Trying to open the file. */ fp = fopen(filename, "r"); - if (fp == NULL) { - perror(filename); - /*ErrorLocation(__FILE__, __LINE__);*/ - exit(EXIT_FAILURE); - } + if (fp == NULL) + log_fail("Error opening hex file <%s>: %s", filename, + strerror(errno)); /* Reading one line of data from the hex file. */ /* char *fgets(char *s, int size, FILE *stream); @@ -126,7 +122,7 @@ LoadHexFile(const char *filename) Checksum = 0; if (line[i++] != ':') { - printf("%s: line not beginning with \":\"\n", PACKAGE); + log_err("hexfile line not beginning with \":\""); goto close_file; } @@ -148,8 +144,7 @@ LoadHexFile(const char *filename) Checksum &= 0x000000FF; if (Checksum) { - /* Error. */ - printf("%s: Invalid format\n", PACKAGE); + log_err("hexfile invalid format"); goto close_file; } else { /* OK */ @@ -171,16 +166,13 @@ LoadHexFile(const char *filename) Checksum &= 0x000000FF; if (Checksum) { - printf("%s: Invalid format\n", PACKAGE); + log_err("hexfile checksum mismatch"); goto close_file; } } close_file: status = fclose(fp); - if (status != EXIT_SUCCESS) { - fprintf(stderr, "%s: Error closing hex file.\n", PACKAGE); - /*ErrorLocation(__FILE__, __LINE__);*/ - exit(EXIT_FAILURE); - } + if (status != EXIT_SUCCESS) + log_fail("Error closing hex file"); } diff --git a/src/common/memory.c b/src/common/memory.c index bd33cac..2e37210 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -91,9 +91,9 @@ void memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value) { if (address >= (unsigned long) mem_infos[id].max_size) { - printf("Error writing to memory ID: %d\n", id); - printf(" Address (%lu) greater than maximum memory size\n", - address); + log_err("Error writing to memory ID: %d\n" + " Address (%lu) greater than maximum memory size", + id, address); return; } else mem_infos[id].buf[address] = value; @@ -117,9 +117,9 @@ u_int8_t memory_read8(enum mem_id_t id, unsigned long address) { if (address >= (unsigned long) mem_infos[id].max_size) { - printf("Error reading from memory ID: %d\n", id); - printf(" Address (%lu) greater than maximum memory size\n", - address); + log_err("Error reading from memory ID: %d\n" + " Address (%lu) greater than maximum memory size", + id, address); return 0; } else return mem_infos[id].buf[address]; diff --git a/src/gtk/memwin.c b/src/gtk/memwin.c index dae27a9..c525fb1 100644 --- a/src/gtk/memwin.c +++ b/src/gtk/memwin.c @@ -349,7 +349,7 @@ memwin_refresh(int memory_id) } if (!valid) { - printf("Invalid iter...\n"); + log_err("Tree model: invalid iter"); return; } diff --git a/src/gtk/pgmwin.c b/src/gtk/pgmwin.c index 15f26b5..6db09e4 100644 --- a/src/gtk/pgmwin.c +++ b/src/gtk/pgmwin.c @@ -241,7 +241,7 @@ pgmwin_refresh(void) } if (!valid) { - printf("Invalid iter...\n"); + log_err("Tree model: invalid iter"); return; } diff --git a/src/gtk/pswwin.c b/src/gtk/pswwin.c index 94f733c..6b890d0 100644 --- a/src/gtk/pswwin.c +++ b/src/gtk/pswwin.c @@ -230,7 +230,7 @@ pswwin_refresh(void) GTK_TREE_MODEL(store), &iter); if (!valid) { - printf("Invalid iter...\n"); + log_err("Tree model: invalid iter"); return; } diff --git a/src/gtk/regwin.c b/src/gtk/regwin.c index af16a7c..8b470a9 100644 --- a/src/gtk/regwin.c +++ b/src/gtk/regwin.c @@ -239,7 +239,7 @@ regwin_refresh(void) } if (!valid) { - printf("Invalid iter...\n"); + log_err("Tree model: invalid iter"); return; }