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;
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);
Checksum = 0;
if (line[i++] != ':') {
- printf("%s: line not beginning with \":\"\n", PACKAGE);
+ log_err("hexfile line not beginning with \":\"");
goto close_file;
}
Checksum &= 0x000000FF;
if (Checksum) {
- /* Error. */
- printf("%s: Invalid format\n", PACKAGE);
+ log_err("hexfile invalid format");
goto close_file;
} else {
/* OK */
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");
}
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;
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];