Use log functions to display errors
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 26 Jan 2014 20:23:48 +0000 (15:23 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 26 Jan 2014 20:38:46 +0000 (15:38 -0500)
src/common/hexfile.c
src/common/memory.c
src/gtk/memwin.c
src/gtk/pgmwin.c
src/gtk/pswwin.c
src/gtk/regwin.c

index 6411166..c879c89 100644 (file)
@@ -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");
 }
index bd33cac..2e37210 100644 (file)
@@ -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];
index dae27a9..c525fb1 100644 (file)
@@ -349,7 +349,7 @@ memwin_refresh(int memory_id)
                }
 
                if (!valid) {
-                       printf("Invalid iter...\n");
+                       log_err("Tree model: invalid iter");
                        return;
                }
 
index 15f26b5..6db09e4 100644 (file)
@@ -241,7 +241,7 @@ pgmwin_refresh(void)
                }
 
                if (!valid) {
-                       printf("Invalid iter...\n");
+                       log_err("Tree model: invalid iter");
                        return;
                }
 
index 94f733c..6b890d0 100644 (file)
@@ -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;
        }
 
index af16a7c..8b470a9 100644 (file)
@@ -239,7 +239,7 @@ regwin_refresh(void)
                }
 
                if (!valid) {
-                       printf("Invalid iter...\n");
+                       log_err("Tree model: invalid iter");
                        return;
                }