diff options
author | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
commit | 954af9179665457b40453a0417ddf5b3949a0449 (patch) | |
tree | e3772817de5c79e29b602ebe47fe0129793f1470 /int2bin.c | |
parent | 892e6e107dbf2386831bd00e7f1c2a0bbe8b2cbb (diff) |
This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'int2bin.c')
-rw-r--r-- | int2bin.c | 88 |
1 files changed, 88 insertions, 0 deletions
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 <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <errno.h> + +#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<len;f++) + { + int b; + + b=ToHex(buff[f*2+9])<<4|ToHex(buff[f*2+10]); + putc(b,out); + } + } + } + + return EXIT_SUCCESS; +} |