908a27434169fd2b68dc6f5262a6fda44bb5a021
[darkstat] / static / c-ify.c
1 /* DON'T LOOK AT MY FACE! MY HIDEOUS FACE! */
2 #include <stdio.h>
3 #include <stdlib.h>
4 int
5 main(int argc, char **argv)
6 {
7 int c, eol;
8 if (argc != 2) {
9 fprintf(stderr, "usage: %s name <infile >outfile.h\n",
10 argv[0]);
11 exit(EXIT_FAILURE);
12 }
13 printf("/* this file was automatically generated */\n"
14 "static char %s[] =", argv[1]);
15 eol = 1;
16 while ((c = getchar()) != EOF) {
17 if (eol) {
18 printf("\n\"");
19 eol = 0;
20 }
21 switch (c) {
22 case '\n': printf("\\n\""); eol = 1; break;
23 case '"': printf("\\\""); break;
24 case '\\': printf("\\\\"); break;
25 default: putchar(c);
26 }
27 }
28 printf(";\n"
29 "static const size_t %s_len = sizeof(%s) - 1;\n",
30 argv[1], argv[1]);
31 return (0);
32 }