/[jscoverage]/trunk/generate-resources.c
ViewVC logotype

Annotation of /trunk/generate-resources.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Wed Aug 1 13:51:53 2007 UTC (11 years, 9 months ago) by siliconforks
File MIME type: text/plain
File size: 1659 byte(s)
Initial import.

1 siliconforks 2 /*
2     generate-resources.c - code generator for embedded resources
3     Copyright (C) 2007 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    
27     int 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     exit(EXIT_FAILURE);
33     }
34     int c;
35     int j = 0;
36     while ((c = fgetc(f)) != EOF) {
37     if (j % 16 == 0) {
38     printf("\n ");
39     }
40     printf("0x%02x,", c);
41     j++;
42     }
43     fclose(f);
44     printf("\n};\n");
45     }
46    
47     printf("const struct Resource RESOURCES[] = {\n");
48     for (int i = 1; i < argc; i++) {
49     printf(" {\n");
50     printf(" \"%s\",\n", argv[i]);
51     printf(" RESOURCE%d_,\n", i);
52     printf(" sizeof(RESOURCE%d_)\n", i);
53     printf(" },\n");
54     }
55     printf("};\n");
56     exit(EXIT_SUCCESS);
57     }

  ViewVC Help
Powered by ViewVC 1.1.24