libsidplayfp
1.0.3
|
00001 /* 00002 * This file is part of libsidplayfp, a SID player engine. 00003 * 00004 * Copyright 1998, 2002 by LaLa <LaLa@C64.org> 00005 * Copyright 2012-2013 Leandro Nini <drfiemost@users.sourceforge.net> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 */ 00021 00022 00023 #ifndef STIL_H 00024 #define STIL_H 00025 00026 #include <string> 00027 #include <algorithm> 00028 #include <map> 00029 00030 #include "stildefs.h" 00031 00044 class STIL_EXTERN STIL 00045 { 00046 public: 00047 00049 enum STILField 00050 { 00051 all, 00052 name, 00053 author, 00054 title, 00055 artist, 00056 comment 00057 }; 00058 00060 enum STILerror 00061 { 00062 NO_STIL_ERROR = 0, 00063 BUG_OPEN, 00064 WRONG_DIR, 00065 NOT_IN_STIL, 00066 NOT_IN_BUG, 00067 WRONG_ENTRY, 00068 CRITICAL_STIL_ERROR = 10, 00069 BASE_DIR_LENGTH, 00070 STIL_OPEN, 00071 NO_EOL, 00072 NO_STIL_DIRS, 00073 NO_BUG_DIRS 00074 }; 00075 00077 bool STIL_DEBUG; 00078 00079 //----// 00080 00087 STIL(const char *stilPath = DEFAULT_PATH_TO_STIL, const char *bugsPath = DEFAULT_PATH_TO_BUGLIST); 00088 00101 const char *getVersion(); 00102 00110 float getVersionNo(); 00111 00124 bool setBaseDir(const char *pathToHVSC); 00125 00134 float getSTILVersionNo(); 00135 00176 const char *getEntry(const char *relPathToEntry, int tuneNo = 0, STILField field = all); 00177 00182 const char *getAbsEntry(const char *absPathToEntry, int tuneNo = 0, STILField field = all); 00183 00200 const char *getGlobalComment(const char *relPathToEntry); 00201 00206 const char *getAbsGlobalComment(const char *absPathToEntry); 00207 00230 const char *getBug(const char *relPathToEntry, int tuneNo = 0); 00231 00236 const char *getAbsBug(const char *absPathToEntry, int tuneNo = 0); 00237 00245 inline STILerror getError() const {return (lastError);} 00246 00254 inline bool hasCriticalError() const 00255 { 00256 return ((lastError >= CRITICAL_STIL_ERROR) ? true : false); 00257 } 00258 00267 inline const char *getErrorStr() const {return (STIL_ERROR_STR[lastError]);} 00268 00269 private: 00270 typedef std::map<std::string, std::streampos> dirList; 00271 00273 const char *PATH_TO_STIL; 00274 00276 const char *PATH_TO_BUGLIST; 00277 00279 std::string versionString; 00280 00282 float STILVersion; 00283 00285 std::string baseDir; 00286 00291 dirList stilDirs; 00292 dirList bugDirs; 00294 00299 char STIL_EOL; 00300 char STIL_EOL2; 00301 00303 STILerror lastError; 00304 00306 static const char *STIL_ERROR_STR[]; 00307 00309 00311 char entrybuf[STIL_MAX_ENTRY_SIZE]; 00312 00314 char globalbuf[STIL_MAX_ENTRY_SIZE]; 00315 00317 char bugbuf[STIL_MAX_ENTRY_SIZE]; 00318 00320 char resultEntry[STIL_MAX_ENTRY_SIZE]; 00321 char resultBug[STIL_MAX_ENTRY_SIZE]; 00322 00324 00325 void setVersionString(); 00326 00335 bool determineEOL(std::ifstream &stilFile); 00336 00351 bool getDirs(std::ifstream &inFile, dirList &dirs, bool isSTILFile); 00352 00364 bool positionToEntry(const char *entryStr, std::ifstream &inFile, dirList &dirs); 00365 00374 void readEntry(std::ifstream &inFile, char *buffer); 00375 00393 bool getField(char *result, char *buffer, int tuneNo = 0, STILField field = all); 00394 00407 bool getOneField(char *result, char *start, char *end, STILField field); 00408 00418 void getStilLine(std::ifstream &infile, char *line); 00419 00420 private: 00427 static void convertSlashes(std::string &str) { std::replace(str.begin(), str.end(), '/', SLASH); } 00428 00435 static void convertToSlashes(std::string &str) { std::replace(str.begin(), str.end(), SLASH, '/'); } 00436 }; 00437 00438 #endif // STIL_H