/* * Copyright (C) 2002-2007 The Warp Rogue Team * Part of the Warp Rogue Project * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License. * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY. * * See the license.txt file for more details. */ /* * UNIX platform code */ /* * most of the needed platform functionality is actually provided by * the portable SDL platform */ #include #include #include #include #include #define __USE_BSD #include #define Uses_ProgramManager #define Uses_Util #define Uses_Game #define Uses_DataFile #include "mheader.h" static char * user_file_path(char *, PROGRAM_DIRECTORY, const char * ); /* * program directories */ static const char * ProgramDirectory[MAX_PROGRAM_DIRECTORIES] = { "/usr/local/share/wrogue/", /* engine directories */ "/usr/local/share/wrogue/engine/config/", "/usr/local/share/wrogue/engine/desc/", "/usr/local/share/wrogue/engine/graphics/", "/usr/local/share/wrogue/engine/help/", "/usr/local/share/wrogue/engine/psybolts/", /* scenario directories */ "/usr/local/share/wrogue/scenario/careers/", "/usr/local/share/wrogue/scenario/info/", "/usr/local/share/wrogue/scenario/npcs/", "/usr/local/share/wrogue/scenario/objects/", "/usr/local/share/wrogue/scenario/race/", "/usr/local/share/wrogue/scenario/terrain/", "/.wrogue/", "/usr/local/share/wrogue/scenario/world/" }; /* * returns the path of a file */ char * get_file_path(char *path, PROGRAM_DIRECTORY directory, const char *file_name ) { if (directory == DIR_USER_DATA) { return user_file_path(path, directory, file_name); } strcpy(path, ProgramDirectory[directory]); strcat(path, file_name); return path; } /* * returns all .rdb files in the passed directory */ LIST * data_files(PROGRAM_DIRECTORY directory) { DIR *d; struct dirent *ent; char *file_name; char *file_ext; LIST *file_list; file_list = list_new(); if (NULL == (d = opendir(ProgramDirectory[directory]))) { return file_list; } while (NULL != (ent = readdir(d))) { /* ignore dot-files */ if (ent->d_name[0] == '.') { continue; } /* ignore directories */ if (ent->d_type == DT_DIR) { continue; } /* Ignore non-.rdb files */ file_ext = strrchr(ent->d_name, '.'); if (NULL == file_ext || strncmp(file_ext, ".rdb", 4)) { continue; } file_name = checked_malloc(FILE_NAME_SIZE); strcpy(file_name, ent->d_name); list_add(file_list, file_name); } closedir(d); return file_list; } /* * main */ int main(int argc, char *argv[]) { NOT_USED(argc); NOT_USED(argv); game_run(); return EXIT_SUCCESS; } /* * user file path - get_file_path() auxiliary function */ static char * user_file_path(char *path, PROGRAM_DIRECTORY directory, const char *file_name ) { char *home; struct stat sb; home = getenv("HOME"); if (home == NULL) { die_no_data_path("*** BE_UNIX ERROR *** " \ "no HOME environment variable set" ); return NULL; } strcpy(path, home); strcat(path, ProgramDirectory[directory]); if(stat(path, &sb) == 0) { strcat(path, file_name); return path; } if (errno != ENOENT) { die_no_data_path("*** BE_UNIX ERROR *** " \ "could not access '%s': %s", path, strerror(errno) ); return NULL; } if(mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { die_no_data_path("*** BE_UNIX ERROR *** " \ "could not create directory '%s': %s", path, strerror(errno) ); return NULL; } strcat(path, file_name); return path; }