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 /cfile8.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 'cfile8.c')
-rw-r--r-- | cfile8.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/cfile8.c b/cfile8.c new file mode 100644 index 0000000..702da6f --- /dev/null +++ b/cfile8.c @@ -0,0 +1,55 @@ +/* + Convert a binary file to a C unsigned char array +*/ +#include <stdio.h> +#include <errno.h> + +int main(int argc, char *argv[]) +{ + char *name="bfile"; + FILE *in,*out; + unsigned char num; + int col; + + in=stdin; + out=stdout; + + if (argc>1) + if (!(in=fopen(argv[1],"rb"))) + perror(argv[0]); + + if (argc>2) + if (!(out=fopen(argv[2],"w"))) + perror(argv[0]); + + if (argc>3) + name=argv[3]; + + if (argc>1) + fprintf(out,"/* Auto-generated binary of %s */\n\n",argv[1]); + else + fprintf(out,"/* Auto-generated binary */\n\n"); + + fprintf(out,"unsigned long %s[]=\n{",name); + + col=0; + num=0; + + while(!feof(in)) + { + fread(&num,sizeof num,1,in); + + if (col==0) + fprintf(out,"\n"); + + fprintf(out,"0x%.2x,",num); + + col=(col+1)%16; + num=0; + } + + fprintf(out,"\n};\n"); + + fclose(in); + fclose(out); +} |