nuclear@39: /* nuclear@39: Stereoscopic tunnel for iOS. nuclear@39: Copyright (C) 2011 John Tsiombikas nuclear@39: nuclear@39: This program is free software: you can redistribute it and/or modify nuclear@39: it under the terms of the GNU General Public License as published by nuclear@39: the Free Software Foundation, either version 3 of the License, or nuclear@39: (at your option) any later version. nuclear@39: nuclear@39: This program is distributed in the hope that it will be useful, nuclear@39: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@39: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@39: GNU General Public License for more details. nuclear@39: nuclear@39: You should have received a copy of the GNU General Public License nuclear@39: along with this program. If not, see . nuclear@39: */ nuclear@39: nuclear@39: nuclear@4: #include nuclear@4: #include nuclear@4: #include nuclear@4: #include nuclear@4: #include nuclear@4: #include "respath.h" nuclear@15: #include "config.h" nuclear@4: nuclear@15: #ifdef IPHONE nuclear@4: #include nuclear@4: #endif nuclear@4: nuclear@4: nuclear@4: #ifndef IPHONE nuclear@4: struct path_node { nuclear@4: char *path; nuclear@4: struct path_node *next; nuclear@4: }; nuclear@4: nuclear@4: static struct path_node *pathlist; nuclear@4: nuclear@4: void add_resource_path(const char *path) nuclear@4: { nuclear@4: struct path_node *node = 0; nuclear@4: nuclear@4: if(!(node = malloc(sizeof *node)) || !(node->path = malloc(strlen(path) + 1))) { nuclear@4: free(node); nuclear@4: fprintf(stderr, "failed to add path: %s: %s\n", path, strerror(errno)); nuclear@4: return; nuclear@4: } nuclear@4: strcpy(node->path, path); nuclear@4: node->next = pathlist; nuclear@4: pathlist = node; nuclear@4: } nuclear@4: nuclear@4: char *find_resource(const char *fname, char *path, size_t sz) nuclear@4: { nuclear@4: static char buffer[1024]; nuclear@4: struct path_node *node; nuclear@4: nuclear@4: if(!path) { nuclear@4: path = buffer; nuclear@4: sz = sizeof buffer; nuclear@4: } nuclear@4: nuclear@4: node = pathlist; nuclear@4: while(node) { nuclear@4: snprintf(path, sz, "%s/%s", node->path, fname); nuclear@4: if(access(path, F_OK) != -1) { nuclear@4: return path; nuclear@4: } nuclear@4: node = node->next; nuclear@4: } nuclear@27: nuclear@27: fprintf(stderr, "can't find resource: %s\n", fname); nuclear@4: return 0; nuclear@4: } nuclear@4: nuclear@4: #else /* IPHONE */ nuclear@4: nuclear@4: void add_resource_path(const char *path) nuclear@4: { nuclear@4: } nuclear@4: nuclear@4: nuclear@4: char *find_resource(const char *fname, char *path, size_t sz) nuclear@4: { nuclear@4: static char buffer[1024]; nuclear@4: CFBundleRef bundle; nuclear@4: CFURLRef url; nuclear@4: CFStringRef cfname; nuclear@4: nuclear@4: cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII); nuclear@4: nuclear@4: bundle = CFBundleGetMainBundle(); nuclear@4: if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) { nuclear@4: return 0; nuclear@4: } nuclear@4: nuclear@4: if(!path) { nuclear@4: path = buffer; nuclear@4: sz = sizeof buffer; nuclear@4: } nuclear@4: nuclear@4: if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sz)) { nuclear@4: return 0; nuclear@4: } nuclear@4: return path; nuclear@4: } nuclear@4: #endif