1 /* Variations on RockDodger
2 * Copyright (C) 2004 Joshua Grams <josh@qualdan.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # include <sys/stat.h>
25 #include <sys/types.h>
29 #include "vorconfig.h"
34 #define DATA_DIR "data\\"
37 add_data_path(char *filename)
40 if(!filename) return filename;
41 s = malloc(sizeof(DATA_DIR)+strlen(filename));
44 strcpy(s+sizeof(DATA_DIR)-1, filename);
56 open_score_file(char *mode)
58 return fopen("scores", mode);
69 add_path(char *path, char *file)
74 if(!path || !file) return NULL;
77 s = malloc(2+plen+flen);
79 memcpy(s, path, plen);
81 memcpy(s+plen+1, file, flen+1);
86 add_data_path(char *filename)
88 return add_path(g_data_dir, filename);
95 if(stat(dirname, &buf)) {
98 return S_ISDIR(buf.st_mode);
102 is_file(char *filename)
105 if(stat(filename, &buf)) {
108 return S_ISREG(buf.st_mode);
115 char *data_options[3] = {
122 if(!data_options[i]) continue;
123 g_data_dir = strdup(data_options[i]);
124 if(is_dir(g_data_dir)) {
125 char *s = add_path(g_data_dir, "b_variations.png");
131 fprintf(stderr, "Can't find VoR data! Tried:\n");
133 if(data_options[i]) fprintf(stderr, "\t%s\n", data_options[i]);
139 find_score_file(void)
143 /* in case we get called twice */
144 if(g_score_file) return true;
146 dir = getenv("HOME"); if(!dir) return false;
147 s = add_path(dir, ".vor-scores");
157 return find_data_dir() && find_score_file();
161 open_score_file(char *mode)
163 if(!g_score_file) return NULL;
164 return fopen(g_score_file, mode);