libsidplayfp  0.3.5
SidTuneTools.h
1 /*
2  * /home/ms/files/source/libsidtune/RCS/SidTuneTools.h,v
3  *
4  * Copyright (C) Michael Schwendt <mschwendt@yahoo.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #ifndef TOOLS_H
22 #define TOOLS_H
23 
24 #include "SidTuneCfg.h"
25 #include "sidplayfp/sidtypes.h"
26 
27 #include <string.h>
28 #if defined(HAVE_SSTREAM)
29 # include <sstream>
30 #else
31 # include <strstream>
32 # undef istringstream
33 # define istringstream istrstream
34 #endif
35 
36 #if defined(HAVE_STRINGS_H)
37 # include <strings.h>
38 #endif
39 
40 #if defined(HAVE_STRCASECMP)
41 # define MYSTRICMP strcasecmp
42 #else
43 # define MYSTRICMP stricmp
44 #endif
45 
46 #if defined(HAVE_STRNCASECMP)
47 # define MYSTRNICMP strncasecmp
48 #else
49 # define MYSTRNICMP strnicmp
50 #endif
51 
53 {
54  public:
55 
56  // Wrapper for ``strnicmp'' without third argument.
57  static int myStrNcaseCmp(const char* s1, const char* s2)
58  {
59  return MYSTRNICMP(s1,s2,strlen(s2));
60  }
61 
62  // Own version of strdup, which uses new instead of malloc.
63  static char* myStrDup(const char *source);
64 
65  // Return pointer to file name position in complete path.
66  static char* fileNameWithoutPath(char* s);
67 
68  // Return pointer to file name position in complete path.
69  // Special version: file separator = forward slash.
70  static char* slashedFileNameWithoutPath(char* s);
71 
72  // Return pointer to file name extension in path.
73  // Searching backwards until first dot is found.
74  static char* fileExtOfPath(char* s);
75 
76  // Parse input string stream. Read and convert a hexa-decimal number up
77  // to a ``,'' or ``:'' or ``\0'' or end of stream.
78  static uint_least32_t readHex(std::istringstream& parseStream);
79 
80  // Parse input string stream. Read and convert a decimal number up
81  // to a ``,'' or ``:'' or ``\0'' or end of stream.
82  static uint_least32_t readDec(std::istringstream& parseStream);
83 
84  // Search terminated string for next newline sequence.
85  // Skip it and return pointer to start of next line.
86  static const char* returnNextLine(const char* s, uint_least32_t len);
87 
88  // Skip any characters in an input string stream up to '='.
89  static void skipToEqu(std::istringstream& parseStream);
90 
91  // Start at first character behind '=' and copy rest of string.
92  static void copyStringValueToEOL(const char* pSourceStr, char* pDestStr, int destMaxLen);
93 };
94 
95 #endif /* TOOLS_H */