summaryrefslogtreecommitdiff
path: root/cfile.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-04-06 15:10:32 +0000
committerIan C <ianc@noddybox.co.uk>2016-04-06 15:10:32 +0000
commitfa6bede3962a4729808db2c46c91b95285bf3eec (patch)
treedaf1d3a26e32eaa424fbcfef469d1169240f2d4f /cfile.c
parentc5036cd3bca4ab8aa9b7314a6fee826a6b1444f6 (diff)
Updated some files with changes that were lost during the backup accident.
Diffstat (limited to 'cfile.c')
-rw-r--r--cfile.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/cfile.c b/cfile.c
index b06c1d8..c9a22f5 100644
--- a/cfile.c
+++ b/cfile.c
@@ -5,14 +5,19 @@
#include <stdio.h>
#include <errno.h>
+#define TYPE unsigned char
+#define STR(x) #x
+#define XSTR(x) STR(x)
+
int main(int argc, char *argv[])
{
const char *name="bfile";
FILE *in,*out;
- unsigned long num;
+ TYPE num;
int col;
int first;
int len;
+ int fldsz;
in=stdin;
out=stdout;
@@ -47,7 +52,9 @@ int main(int argc, char *argv[])
fprintf(out,"/* Auto-generated binary */\n\n");
}
- fprintf(out,"unsigned long %s[]=\n\t\t\t{",name);
+ fldsz = sizeof num * 2;
+
+ fprintf(out,XSTR(TYPE) " %s[]=\n\t{",name);
col=0;
num=0;
@@ -56,33 +63,33 @@ int main(int argc, char *argv[])
while(!feof(in))
{
- fread(&num,sizeof(unsigned long),1,in);
+ fread(&num,sizeof num,1,in);
if (col==0)
{
if (first)
{
- fprintf(out,"\n\t\t\t");
+ fprintf(out,"\n\t\t");
first=0;
}
else
{
- fprintf(out,",\n\t\t\t");
+ fprintf(out,",\n\t\t");
}
}
else
{
- fprintf(out,",");
+ fprintf(out,", ");
}
- fprintf(out,"0x%.8x",num);
+ fprintf(out,"0x%.*x",fldsz, num);
- col=(col+1)%4;
+ col=(col+1) % (8 / sizeof num);
num=0;
len++;
}
- fprintf(out,"\n\t\t\t};\n#define %s_LEN %d\n", name, len);
+ fprintf(out,"\n\t};\n#define %s_LEN %d\n", name, len);
fclose(in);
fclose(out);