#include #include #include "types.h" #include "ihexparse.h" #include #define BUFSIZE 65536 UINT8 *pBuffer; int main(int argc, char *argv[]) { FILE *pFile; HEXREC recIn, recOut; INT32 count; UINT16 maxAddress, fileLen; if (argc < 2) { printf("Usage: IHexParse \n"); return 1; } HexOpen(&recIn, argv[1]); HexCreate(&recOut, "out.hex"); pFile = fopen("out.bin","wb"); if (pFile <= 0) return 1; pBuffer = malloc(BUFSIZE); memset(pBuffer, 0xFF, BUFSIZE); maxAddress = 0; count = 1; while (count > 0) { count = HexReadRecord(&recIn); if (count > 0) { memcpy(recOut.recData, recIn.recData, recIn.length); recOut.dataStart = recIn.dataStart; recOut.length = recIn.length; recOut.type = recIn.type; HexWriteRecord(&recOut); } if (maxAddress > recIn.dataStart) continue; else { maxAddress = recIn.dataStart; fileLen = maxAddress + recIn.length; } } memcpy(&pBuffer[recIn.dataStart], recIn.recData, recIn.length); if ((INT32)count < 0) printf("Error in HEX file\n"); HexClose(&recOut); HexClose(&recIn); fwrite(pBuffer, sizeof(UINT8), fileLen, pFile); fclose (pFile); free(pBuffer); return 0; }