rev |
line source |
nuclear@2
|
1 /*
|
nuclear@2
|
2 Stereoscopic tunnel for iOS.
|
nuclear@2
|
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@2
|
4
|
nuclear@2
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@2
|
6 it under the terms of the GNU General Public License as published by
|
nuclear@2
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@2
|
8 (at your option) any later version.
|
nuclear@2
|
9
|
nuclear@2
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@2
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@2
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@2
|
13 GNU General Public License for more details.
|
nuclear@2
|
14
|
nuclear@2
|
15 You should have received a copy of the GNU General Public License
|
nuclear@2
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@2
|
17 */
|
nuclear@2
|
18
|
nuclear@2
|
19
|
nuclear@2
|
20 #include <stdio.h>
|
nuclear@2
|
21 #include <stdlib.h>
|
nuclear@2
|
22 #include <string.h>
|
nuclear@2
|
23 #include <errno.h>
|
nuclear@2
|
24 #include <unistd.h>
|
nuclear@2
|
25 #include "respath.h"
|
nuclear@2
|
26 #include "config.h"
|
nuclear@24
|
27 #include "assman.h"
|
nuclear@2
|
28
|
nuclear@2
|
29 #ifdef IPHONE
|
nuclear@2
|
30 #include <CoreFoundation/CoreFoundation.h>
|
nuclear@2
|
31 #endif
|
nuclear@2
|
32
|
nuclear@2
|
33
|
nuclear@2
|
34 #ifndef IPHONE
|
nuclear@2
|
35 struct path_node {
|
nuclear@2
|
36 char *path;
|
nuclear@2
|
37 struct path_node *next;
|
nuclear@2
|
38 };
|
nuclear@2
|
39
|
nuclear@2
|
40 static struct path_node *pathlist;
|
nuclear@2
|
41
|
nuclear@2
|
42 void add_resource_path(const char *path)
|
nuclear@2
|
43 {
|
nuclear@2
|
44 struct path_node *node = 0;
|
nuclear@2
|
45
|
nuclear@2
|
46 if(!(node = malloc(sizeof *node)) || !(node->path = malloc(strlen(path) + 1))) {
|
nuclear@2
|
47 free(node);
|
nuclear@2
|
48 fprintf(stderr, "failed to add path: %s: %s\n", path, strerror(errno));
|
nuclear@2
|
49 return;
|
nuclear@2
|
50 }
|
nuclear@2
|
51 strcpy(node->path, path);
|
nuclear@2
|
52 node->next = pathlist;
|
nuclear@2
|
53 pathlist = node;
|
nuclear@2
|
54 }
|
nuclear@2
|
55
|
nuclear@2
|
56 char *find_resource(const char *fname, char *path, size_t sz)
|
nuclear@2
|
57 {
|
nuclear@2
|
58 static char buffer[1024];
|
nuclear@2
|
59 struct path_node *node;
|
nuclear@2
|
60
|
nuclear@2
|
61 if(!path) {
|
nuclear@2
|
62 path = buffer;
|
nuclear@2
|
63 sz = sizeof buffer;
|
nuclear@2
|
64 }
|
nuclear@2
|
65
|
nuclear@2
|
66 node = pathlist;
|
nuclear@2
|
67 while(node) {
|
nuclear@24
|
68 ass_file *fp;
|
nuclear@24
|
69
|
nuclear@2
|
70 snprintf(path, sz, "%s/%s", node->path, fname);
|
nuclear@24
|
71 if((fp = ass_fopen(path, "r"))) {
|
nuclear@24
|
72 ass_fclose(fp);
|
nuclear@2
|
73 return path;
|
nuclear@2
|
74 }
|
nuclear@2
|
75 node = node->next;
|
nuclear@2
|
76 }
|
nuclear@2
|
77
|
nuclear@2
|
78 fprintf(stderr, "can't find resource: %s\n", fname);
|
nuclear@2
|
79 return 0;
|
nuclear@2
|
80 }
|
nuclear@2
|
81
|
nuclear@2
|
82 #else /* IPHONE */
|
nuclear@2
|
83
|
nuclear@2
|
84 void add_resource_path(const char *path)
|
nuclear@2
|
85 {
|
nuclear@2
|
86 }
|
nuclear@2
|
87
|
nuclear@2
|
88
|
nuclear@2
|
89 char *find_resource(const char *fname, char *path, size_t sz)
|
nuclear@2
|
90 {
|
nuclear@2
|
91 static char buffer[1024];
|
nuclear@2
|
92 CFBundleRef bundle;
|
nuclear@2
|
93 CFURLRef url;
|
nuclear@2
|
94 CFStringRef cfname;
|
nuclear@2
|
95
|
nuclear@2
|
96 cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII);
|
nuclear@2
|
97
|
nuclear@2
|
98 bundle = CFBundleGetMainBundle();
|
nuclear@2
|
99 if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) {
|
nuclear@2
|
100 return 0;
|
nuclear@2
|
101 }
|
nuclear@2
|
102
|
nuclear@2
|
103 if(!path) {
|
nuclear@2
|
104 path = buffer;
|
nuclear@2
|
105 sz = sizeof buffer;
|
nuclear@2
|
106 }
|
nuclear@2
|
107
|
nuclear@2
|
108 if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sz)) {
|
nuclear@2
|
109 return 0;
|
nuclear@2
|
110 }
|
nuclear@2
|
111 return path;
|
nuclear@2
|
112 }
|
nuclear@2
|
113 #endif
|