Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

fformat_.cpp

Go to the documentation of this file.
00001 //
00002 // /home/ms/sidplay/libsidplay/fformat/RCS/fformat_.cpp,v
00003 //
00004 
00005 #include <ctype.h>
00006 #include <string.h>
00007 
00008 #include "fformat.h"
00009 #include "myendian.h"
00010 
00011 // Case-insensitive comparison of two strings up to ``sizeof(s2)'' characters.
00012 int myStrNcaseCmp( char* s1, const char* s2 )
00013 {
00014   char tmp = *(s1 +strlen(s2));
00015   *(s1 +strlen(s2)) = 0;
00016 
00017 #if defined(__SYMBIAN32__)
00018   int ret = strcasecmp( s1, s2 ); //ALFRED - TODO
00019 #else
00020   int ret = stricmp( s1, s2 );
00021 #endif
00022 
00023   *(s1 +strlen(s2)) = tmp;
00024   return ret;
00025 }
00026 
00027 // Case-insensitive comparison of two strings.
00028 int myStrCaseCmp( char* s1, char* s2 )
00029 {
00030 #if defined(__SYMBIAN32__)
00031  return strcasecmp(s1,s2); //ALFRED - TODO
00032 #else
00033         return stricmp(s1,s2);
00034 #endif
00035 }
00036 
00037 // Own version of strdup, which uses new instead of malloc.
00038 char* myStrDup(const char *source)
00039 {
00040         char *dest;
00041         if ( (dest = new char[strlen(source)+1]) != 0)
00042         {
00043                 strcpy(dest,source);
00044         }
00045         return dest;
00046 }
00047 
00048 // Return pointer to file name position in complete path.
00049 char* fileNameWithoutPath(char* s)
00050 {
00051         int last_slash_pos = -1;
00052         for ( unsigned pos = 0; pos < strlen(s); pos++ )
00053         {
00054 #if defined(__MSDOS__) || defined(__WIN32__) || defined(_Windows) 
00055                 if ( s[pos] == '\\' )
00056 #elif defined(__POWERPC__)
00057                 if ( s[pos] == ':' )
00058 #elif defined(__amigaos__)
00059                 if ( s[pos] == ':' || s[pos] == '/' )
00060 #else
00061                 if ( s[pos] == '/' )
00062 #endif    
00063                     last_slash_pos = pos;
00064         }
00065         return( &s[last_slash_pos +1] );
00066 }
00067 
00068 // Return pointer to file name extension in file name.
00069 char* fileExtOfFilename(char* s)
00070 {
00071         int last_dot_pos = strlen(s)-1;  // assume no dot
00072         for ( unsigned pos = 0; pos < strlen(s); pos++ )
00073         {
00074                 if ( s[pos] == '.' )
00075                         last_dot_pos = pos;
00076         }
00077         return( &s[last_dot_pos] );
00078 }
00079 
00080 #if 0 //ALFRED - TODO
00081 // Parse input string stream. Read and convert a hexa-decimal number up 
00082 // to a ``,'' or ``:'' or ``\0'' or end of stream.
00083 udword readHex( istrstream& hexin )
00084 {
00085         udword hexLong = 0;
00086         char c;
00087         do
00088         {
00089                 hexin >> c;
00090                 if ( !hexin )
00091                         break;
00092                 if (( c != ',') && ( c != ':' ) && ( c != 0 ))
00093                 {
00094                         // machine independed to_upper
00095                         c &= 0xdf;
00096                         ( c < 0x3a ) ? ( c &= 0x0f ) : ( c -= ( 0x41 - 0x0a ));
00097                         hexLong <<= 4;
00098                         hexLong |= (udword)c;
00099                 }
00100                 else
00101                 {
00102                         if ( c == 0 )
00103                                 hexin.putback(c);
00104                         break;
00105                 }
00106         }  while ( hexin );
00107         return hexLong;
00108 }
00109 
00110 // Parse input string stream. Read and convert a decimal number up 
00111 // to a ``,'' or ``:'' or ``\0'' or end of stream.
00112 udword readDec( istrstream& decin )
00113 {
00114         udword hexLong = 0;
00115         char c;
00116         do
00117         {
00118                 decin >> c;
00119                 if ( !decin )
00120                         break;
00121                 if (( c != ',') && ( c != ':' ) && ( c != 0 ))
00122                 {
00123                         c &= 0x0f;
00124                         hexLong *= 10;
00125                         hexLong += (udword)c;
00126                 }
00127                 else
00128                 { 
00129                         if ( c == 0 )
00130                                 decin.putback(c);
00131                         break;
00132                 }
00133         }  while ( decin );
00134         return hexLong;
00135 }
00136 #endif //ALFRED - TODO
00137 
00138 // Search terminated string for next newline sequence.
00139 // Skip it and return pointer to start of next line.
00140 char* returnNextLine( char* s )
00141 {
00142         // Unix: LF = 0x0A
00143         // Windows, DOS: CR,LF = 0x0D,0x0A
00144         // Mac: CR = 0x0D
00145         char c;
00146         while ((c = *s) != 0)
00147         {
00148                 s++;                            // skip read character
00149                 if (c == 0x0A)
00150                 {
00151                         break;                      // LF found
00152                 }
00153                 else if (c == 0x0D)
00154                 {
00155                         if (*s == 0x0A)
00156                         {
00157                                 s++;                    // CR,LF found, skip LF
00158                         }
00159                         break;                      // CR or CR,LF found
00160                 }
00161         }
00162         if (*s == 0)                        // end of string ?
00163         {
00164                 return 0;                       // no next line available
00165         }
00166         return s;                           // next line available
00167 }
00168 
00169 #if 0 //ALFRED - TODO
00170 // Skip any characters in an input string stream up to '='.
00171 void skipToEqu( istrstream& parseStream )
00172 {
00173         char c;
00174         do
00175         {
00176                 parseStream >> c;
00177         }
00178         while ( c != '=' );
00179 }
00180 #endif //ALFRED - TODO
00181 
00182 
00183 void copyStringValueToEOL( char* pSourceStr, char* pDestStr, int DestMaxLen )
00184 {
00185         // Start at first character behind '='.
00186         while ( *pSourceStr != '=' )
00187         {
00188                 pSourceStr++;
00189         }
00190         pSourceStr++;  // Skip '='.
00191         while (( DestMaxLen > 0 ) && ( *pSourceStr != 0 )
00192                    && ( *pSourceStr != '\n' ) && ( *pSourceStr != '\r' ))
00193         {
00194                 *pDestStr++ = *pSourceStr++;
00195                 DestMaxLen--;
00196         }
00197         *pDestStr++ = 0;
00198 }

Generated on Tue Feb 8 04:13:58 2005 for Esidplay by doxygen 1.3.3