diff --git a/src/fvhex2bin.c b/src/fvhex2bin.c index c50e890..0d82de0 100644 --- a/src/fvhex2bin.c +++ b/src/fvhex2bin.c @@ -68,6 +68,6 @@ int main(int argc, char *argv[]) return arg ? EXIT_FAILURE : EXIT_SUCCESS; } - hex2bin(infile, outfile); + heckfv_hex2bin(infile, outfile); return EXIT_SUCCESS; } diff --git a/src/libfvhex2bin.c b/src/libfvhex2bin.c index 7428607..389c001 100644 --- a/src/libfvhex2bin.c +++ b/src/libfvhex2bin.c @@ -22,25 +22,21 @@ */ #include "kk_ihex_read.h" +#include "libfvhex2bin.h" #include #include #include #include -#define AUTODETECT_ADDRESS (~0UL) - - static unsigned long line_number = 1L; static unsigned long file_position = 0L; static unsigned long address_offset = 0UL; static bool debug_enabled = 0; - - static FILE *infile = NULL; static FILE *outfile = NULL; -int hex2bin(const char *infilename, const char *outfilename) +int heckfv_hex2bin(char *infilename, char *outfilename) { int ret = 0; if (!(infile = fopen(infilename, "r"))) { @@ -55,9 +51,7 @@ int hex2bin(const char *infilename, const char *outfilename) ihex_count_t count; char buf[256]; - ihex_read_at_address( - &ihex, - (address_offset != AUTODETECT_ADDRESS) ? (ihex_address_t)address_offset : 0); + ihex_read_at_address(&ihex, (ihex_address_t)address_offset); while (fgets(buf, sizeof(buf), infile)) { count = (ihex_count_t)strlen(buf); ihex_read_bytes(&ihex, buf, count); @@ -87,28 +81,8 @@ ihex_bool_t ihex_data_read(struct ihex_state *ihex, ihex_record_type_t type, ihe } if (type == IHEX_DATA_RECORD) { unsigned long address = (unsigned long)IHEX_LINEAR_ADDRESS(ihex); - if (address < address_offset) { - if (address_offset == AUTODETECT_ADDRESS) { - // autodetect initial address - address_offset = address; - if (debug_enabled) { - (void)fprintf(stderr, "Address offset: 0x%lx\n", address_offset); - } - } else { - (void)fprintf(stderr, "Address underflow on line %lu\n", line_number); - exit(EXIT_FAILURE); - } - } address -= address_offset; if (address != file_position) { - if (debug_enabled) { - (void)fprintf( - stderr, - "Seeking from 0x%lx to 0x%lx on line %lu\n", - file_position, - address, - line_number); - } if (outfile == stdout || fseek(outfile, (long)address, SEEK_SET)) { if (file_position < address) { // "seek" forward in stdout by writing NUL bytes @@ -128,9 +102,6 @@ ihex_bool_t ihex_data_read(struct ihex_state *ihex, ihex_record_type_t type, ihe } file_position += ihex->length; } else if (type == IHEX_END_OF_FILE_RECORD) { - if (debug_enabled) { - (void)fprintf(stderr, "%lu bytes written\n", file_position); - } if (outfile != stdout) { (void)fclose(outfile); } diff --git a/src/libfvhex2bin.h b/src/libfvhex2bin.h index 52f9526..bede56a 100644 --- a/src/libfvhex2bin.h +++ b/src/libfvhex2bin.h @@ -1,3 +1,14 @@ -#pragma once +#ifndef LIB_FV_HEX2BIN +#define LIB_FV_HEX2BIN -int hex2bin(const char *infilename, const char *outfile); +#ifdef __cplusplus +extern "C" { +#endif + + int heckfv_hex2bin(char *infilename, char *outfilename); + +#ifdef __cplusplus +}; +#endif + +#endif \ No newline at end of file