forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt2c.c
57 lines (50 loc) · 1.34 KB
/
txt2c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @file
* Encode the compilation options as a C-string
*
* @authors
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdio.h>
#define PER_LINE 12
static void txt2c(char *sym, FILE *fp)
{
unsigned char buf[PER_LINE];
int i;
int sz = 0;
printf("unsigned char %s[] = {\n", sym);
while (true)
{
sz = fread(buf, sizeof(unsigned char), PER_LINE, fp);
if (sz == 0)
break;
printf("\t");
for (i = 0; i < sz; i++)
printf("0x%02x, ", buf[i]);
printf("\n");
}
printf("\t0x00\n};\n");
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "usage: %s symbol <textfile >textfile.c\n", argv[0]);
return 2;
}
txt2c(argv[1], stdin);
return 0;
}