Debian Codegraph @

drivers/dahdi/makefw.c

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /* Xilinx firmware convertor program.
2 *
3 * Written by Jim Dixon <[email protected]>.
4 *
5 * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
6 * Copyright (C) 2001-2008 Digium, Inc.
7 *
8 * All rights reserved.
9 *
10 */
11
12 /*
13 * See http://www.asterisk.org for more information about
14 * the Asterisk project. Please do not directly contact
15 * any of the maintainers of this project for assistance;
16 * the project provides a web site, mailing lists and IRC
17 * channels for your use.
18 *
19 * This program is free software, distributed under the terms of
20 * the GNU General Public License Version 2 as published by the
21 * Free Software Foundation. See the LICENSE file included with
22 * this program for more details.
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #define SWATH 12
30
31 int main(int argc, char *argv[])
32 {
33 FILE *fp;
34 int i,j,nbytes;
35 unsigned char c;
36 char buf[300];
37
38 if (argc < 3)
39 {
40 puts("Usage... makefw filename.rbt array_name");
41 exit(1);
42 }
43
44 fp = fopen(argv[1],"r");
45 if (!fp)
46 {
47 perror("bit file open");
48 exit(1);
49 }
50 nbytes = 0;
51 printf("static unsigned char %s[] = {\n",argv[2]);
52 i = 0;
53 while(fgets(buf,sizeof(buf) - 1,fp))
54 {
55 if (!buf[0]) continue;
56 if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
57 if (!buf[0]) continue;
58 if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
59 if (!buf[0]) continue;
60 if (strlen(buf) < 32) continue;
61 if ((buf[0] != '0') && (buf[0] != '1')) continue;
62 c = 0;
63 for(j = 0; buf[j]; j++)
64 {
65 if (buf[j] > '0') c |= 1 << (j & 7);
66 if ((j & 7) == 7)
67 {
68 nbytes++;
69 if (i) printf(",");
70 printf("0x%02x",c);
71 if (i++ == SWATH) {
72 printf(",\n");
73 i = 0;
74 }
75 c = 0;
76 }
77 }
78 }
79 printf("\n};\n\n");
80 fprintf(stderr,"Loaded %d bytes from file\n",nbytes);
81 fclose(fp);
82 exit(0);
83 }
84