summaryrefslogtreecommitdiff
path: root/wct4xxp/fw2h.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-08-27 02:02:42 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-08-27 02:02:42 +0000
commitff729b007e96a90d1d78b0271480779859d41b04 (patch)
tree34ae3b76710c3568412dcc983db1ce33e7984b34 /wct4xxp/fw2h.c
parent059e0fa03c63025261ba8411132814046f5280f4 (diff)
merge in new, cleaner Octasic API integration
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.2@1359 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'wct4xxp/fw2h.c')
-rw-r--r--wct4xxp/fw2h.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/wct4xxp/fw2h.c b/wct4xxp/fw2h.c
new file mode 100644
index 0000000..5b6c73a
--- /dev/null
+++ b/wct4xxp/fw2h.c
@@ -0,0 +1,47 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+int main(int argc, char *argv[])
+{
+ char *c;
+ int fd;
+ FILE *f;
+ int res;
+ int x;
+ unsigned char buf[1024];
+ if (argc != 3) {
+ fprintf(stderr, "Usage: fw2h <infile> <outfile>");
+ exit(1);
+ }
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Unable to open '%s': %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
+ f = fopen(argv[2], "w+");
+ if (!f) {
+ fprintf(stderr, "Unable to open '%s' for writing: %s\n", argv[2], strerror(errno));
+ exit(1);
+ }
+ c = strrchr(argv[2], '.');
+ if (c) *c = '\0';
+ fprintf(f, "static unsigned char %s[] = {\t", argv[2]);
+ while ((res = read(fd, buf, sizeof(buf))) > 0) {
+ for (x = 0; x < res; x++) {
+ if (!(x % 16))
+ fprintf(f, "\n\t");
+ fprintf(f, "0x%02x, ", buf[x]);
+ }
+ }
+ fprintf(f, "\n};\n");
+ if (res < 0) {
+ fprintf(stderr, "Error reading file: %s\n", strerror(errno));
+ exit(1);
+ }
+ fclose(f);
+ close(fd);
+ exit(0);
+}