File: txt2c.c

package info (click to toggle)
mutt 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,432 kB
  • sloc: ansic: 95,029; sh: 4,720; perl: 1,152; makefile: 708; yacc: 318; python: 211
file content (39 lines) | stat: -rw-r--r-- 599 bytes parent folder | download
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
#include <stdio.h>

#define per_line 12

void
txt2c(char *sym, FILE *fp)
{
  unsigned char buf[per_line];
  int i;
  int sz = 0;

  printf("unsigned char %s[] = {\n", sym);
  while (1)
  {
    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;
}