istereo2

view src/respath.c @ 35:643f4ab609a4

added readme and license
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 31 Oct 2015 05:45:35 +0200
parents 81d35769f546
children
line source
1 /*
2 Stereoscopic tunnel for iOS.
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
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 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <unistd.h>
25 #include "respath.h"
26 #include "config.h"
27 #include "assman.h"
29 #ifdef IPHONE
30 #include <CoreFoundation/CoreFoundation.h>
31 #endif
34 #ifndef IPHONE
35 struct path_node {
36 char *path;
37 struct path_node *next;
38 };
40 static struct path_node *pathlist;
42 void add_resource_path(const char *path)
43 {
44 struct path_node *node = 0;
46 if(!(node = malloc(sizeof *node)) || !(node->path = malloc(strlen(path) + 1))) {
47 free(node);
48 fprintf(stderr, "failed to add path: %s: %s\n", path, strerror(errno));
49 return;
50 }
51 strcpy(node->path, path);
52 node->next = pathlist;
53 pathlist = node;
54 }
56 char *find_resource(const char *fname, char *path, size_t sz)
57 {
58 static char buffer[1024];
59 struct path_node *node;
61 if(!path) {
62 path = buffer;
63 sz = sizeof buffer;
64 }
66 node = pathlist;
67 while(node) {
68 ass_file *fp;
70 snprintf(path, sz, "%s/%s", node->path, fname);
71 if((fp = ass_fopen(path, "r"))) {
72 ass_fclose(fp);
73 return path;
74 }
75 node = node->next;
76 }
78 fprintf(stderr, "can't find resource: %s\n", fname);
79 return 0;
80 }
82 #else /* IPHONE */
84 void add_resource_path(const char *path)
85 {
86 }
89 char *find_resource(const char *fname, char *path, size_t sz)
90 {
91 static char buffer[1024];
92 CFBundleRef bundle;
93 CFURLRef url;
94 CFStringRef cfname;
96 cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII);
98 bundle = CFBundleGetMainBundle();
99 if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) {
100 return 0;
101 }
103 if(!path) {
104 path = buffer;
105 sz = sizeof buffer;
106 }
108 if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sz)) {
109 return 0;
110 }
111 return path;
112 }
113 #endif