/[jscoverage]/trunk/resource-manager.c
ViewVC logotype

Contents of /trunk/resource-manager.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 427 - (show annotations)
Wed Feb 18 16:08:33 2009 UTC (9 years, 7 months ago) by siliconforks
File MIME type: text/plain
File size: 1832 byte(s)
Update Copyright year.
1 /*
2 resource-manager.c - handles embedded files
3 Copyright (C) 2007, 2008, 2009 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 <config.h>
21
22 #include "resource-manager.h"
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "util.h"
29
30 #include "resources.c"
31
32 const struct Resource * get_resource(const char * name) {
33 int num_resources = sizeof(RESOURCES) / sizeof(struct Resource);
34 for (int i = 0; i < num_resources; i++) {
35 if (strcmp(RESOURCES[i].name, name) == 0) {
36 return &RESOURCES[i];
37 }
38 }
39 return NULL;
40 }
41
42 void copy_resource_to_stream(const char * resource, FILE * stream) {
43 const struct Resource * r = get_resource(resource);
44 assert(r != NULL);
45 if (fwrite(r->data, 1, r->length, stream) != r->length) {
46 fatal("cannot write to stream");
47 }
48 }
49
50 void copy_resource(const char * resource, const char * destination_directory) {
51 char * file = make_path(destination_directory, resource);
52 char * directory = make_dirname(file);
53 mkdirs(directory);
54 free(directory);
55 FILE * f = xfopen(file, "wb");
56 copy_resource_to_stream(resource, f);
57 fclose(f);
58 free(file);
59 }

  ViewVC Help
Powered by ViewVC 1.1.24