PageRenderTime 122ms CodeModel.GetById 70ms app.highlight 4ms RepoModel.GetById 47ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/generate-resources.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 58 lines | 36 code | 4 blank | 18 comment | 8 complexity | b8a5ca96b30e44592fc9ba1b692510ec MD5 | raw file
 1/*
 2    generate-resources.c - code generator for embedded resources
 3    Copyright (C) 2007, 2008 siliconforks.com
 4
 5    This program is free software; you can redistribute it and/or modify
 6    it under the terms of the GNU General Public License as published by
 7    the Free Software Foundation; either version 2 of the License, or
 8    (at your option) any later version.
 9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License along
16    with this program; if not, write to the Free Software Foundation, Inc.,
17    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#include <ctype.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <sys/stat.h>
26
27int main(int argc, char ** argv) {
28  for (int i = 1; i < argc; i++) {
29    printf("const unsigned char RESOURCE%d_[] = {\n", i);
30    FILE * f = fopen(argv[i], "rb");
31    if (f == NULL) {
32      fprintf(stderr, "cannot open file %s\n", argv[i]);
33      exit(EXIT_FAILURE);
34    }
35    int c;
36    int j = 0;
37    while ((c = fgetc(f)) != EOF) {
38      if (j % 16 == 0) {
39        printf("\n  ");
40      }
41      printf("0x%02x,", c);
42      j++;
43    }
44    fclose(f);
45    printf("\n};\n");
46  }
47
48  printf("const struct Resource RESOURCES[] = {\n");
49  for (int i = 1; i < argc; i++) {
50    printf("  {\n");
51    printf("    \"%s\",\n", argv[i]);
52    printf("    RESOURCE%d_,\n", i);
53    printf("    sizeof(RESOURCE%d_)\n", i);
54    printf("  },\n");
55  }
56  printf("};\n");
57  exit(EXIT_SUCCESS);
58}