libsidplayfp  1.1.0
stil.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 1998, 2002 by LaLa <LaLa@C64.org>
5  * Copyright 2012-2013 Leandro Nini <drfiemost@users.sourceforge.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 
23 #ifndef STIL_H
24 #define STIL_H
25 
26 #include <string>
27 #include <algorithm>
28 #include <map>
29 
30 #include "stildefs.h"
31 
44 class STIL_EXTERN STIL
45 {
46 public:
47 
49  enum STILField
50  {
51  all,
52  name,
53  author,
54  title,
55  artist,
56  comment
57  };
58 
60  enum STILerror
61  {
62  NO_STIL_ERROR = 0,
68  CRITICAL_STIL_ERROR = 10,
73  NO_BUG_DIRS
74  };
75 
77  bool STIL_DEBUG;
78 
79  //----//
80 
87  STIL(const char *stilPath = DEFAULT_PATH_TO_STIL, const char *bugsPath = DEFAULT_PATH_TO_BUGLIST);
88 
101  const char *getVersion();
102 
110  float getVersionNo();
111 
124  bool setBaseDir(const char *pathToHVSC);
125 
134  float getSTILVersionNo();
135 
176  const char *getEntry(const char *relPathToEntry, int tuneNo = 0, STILField field = all);
177 
182  const char *getAbsEntry(const char *absPathToEntry, int tuneNo = 0, STILField field = all);
183 
200  const char *getGlobalComment(const char *relPathToEntry);
201 
206  const char *getAbsGlobalComment(const char *absPathToEntry);
207 
230  const char *getBug(const char *relPathToEntry, int tuneNo = 0);
231 
236  const char *getAbsBug(const char *absPathToEntry, int tuneNo = 0);
237 
245  inline STILerror getError() const {return (lastError);}
246 
254  inline bool hasCriticalError() const
255  {
256  return ((lastError >= CRITICAL_STIL_ERROR) ? true : false);
257  }
258 
267  inline const char *getErrorStr() const {return (STIL_ERROR_STR[lastError]);}
268 
269 private:
270  typedef std::map<std::string, std::streampos> dirList;
271 
273  const char *PATH_TO_STIL;
274 
276  const char *PATH_TO_BUGLIST;
277 
279  std::string versionString;
280 
282  float STILVersion;
283 
285  std::string baseDir;
286 
291  dirList stilDirs;
292  dirList bugDirs;
294 
299  char STIL_EOL;
300  char STIL_EOL2;
301 
303  STILerror lastError;
304 
306  static const char *STIL_ERROR_STR[];
307 
309 
311  char entrybuf[STIL_MAX_ENTRY_SIZE];
312 
314  char globalbuf[STIL_MAX_ENTRY_SIZE];
315 
317  char bugbuf[STIL_MAX_ENTRY_SIZE];
318 
320  char resultEntry[STIL_MAX_ENTRY_SIZE];
321  char resultBug[STIL_MAX_ENTRY_SIZE];
322 
324 
325  void setVersionString();
326 
335  bool determineEOL(std::ifstream &stilFile);
336 
351  bool getDirs(std::ifstream &inFile, dirList &dirs, bool isSTILFile);
352 
364  bool positionToEntry(const char *entryStr, std::ifstream &inFile, dirList &dirs);
365 
374  void readEntry(std::ifstream &inFile, char *buffer);
375 
393  bool getField(char *result, char *buffer, int tuneNo = 0, STILField field = all);
394 
407  bool getOneField(char *result, char *start, char *end, STILField field);
408 
418  void getStilLine(std::ifstream &infile, char *line);
419 
420 private:
427  static void convertSlashes(std::string &str) { std::replace(str.begin(), str.end(), '/', SLASH); }
428 
435  static void convertToSlashes(std::string &str) { std::replace(str.begin(), str.end(), SLASH, '/'); }
436 };
437 
438 #endif // STIL_H