From 954af9179665457b40453a0417ddf5b3949a0449 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 4 Mar 2007 18:35:36 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- int2bin.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 int2bin.c (limited to 'int2bin.c') diff --git a/int2bin.c b/int2bin.c new file mode 100644 index 0000000..78125e3 --- /dev/null +++ b/int2bin.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#define TRUE 1 +#define FALSE 0 + +static const int ToHex(char c) +{ + c=toupper(c); + + if (c>='0' && c<='9') + return c-'0'; + + if (c>='A' && c<='F') + return c-'A'+10; + + return 0; +} + + +int main (int argc, char *argv[]) +{ + FILE *in, *out; + char buff[1024]; + int done; + int tot; + + if (argc!=3) + { + fprintf(stderr,"%s: usage %s source dest\n",argv[0],argv[0]); + exit(EXIT_FAILURE); + } + + if (!(in=fopen(argv[1],"r"))) + { + fprintf(stderr,"Couldn't open '%s'\n",argv[1]); + exit(EXIT_FAILURE); + } + + if (!(out=fopen(argv[2],"wb"))) + { + fprintf(stderr,"Couldn't create '%s'\n",argv[2]); + exit(EXIT_FAILURE); + } + + done=0; + tot=0; + + while(!done) + { + if (!fgets(buff,sizeof buff,in)) + { + printf("Missing EOF record\n"); + done=TRUE; + } + + if (!done && buff[0]!=':') + { + printf("Invalid Intel HEX file\n"); + done=TRUE; + } + + if (!done && buff[8]=='1') + { + done=TRUE; + } + + if (!done) + { + int len; + int f; + + len=ToHex(buff[1])<<4|ToHex(buff[2]); + + for(f=0;f