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

Annotation of /trunk/generate-resources.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (hide annotations)
Fri Oct 3 02:29:03 2008 UTC (10 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 1722 byte(s)
Add error message.
1 siliconforks 2 /*
2     generate-resources.c - code generator for embedded resources
3 siliconforks 87 Copyright (C) 2007, 2008 siliconforks.com
4 siliconforks 2
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 siliconforks 227 fprintf(stderr, "cannot open file %s\n", argv[i]);
33 siliconforks 2 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     }

  ViewVC Help
Powered by ViewVC 1.1.24