2 * AdPlug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2003 Simon Peter <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * players.h - Players enumeration, by Simon Peter <dn.tlp@gmx.net>
27 /***** CPlayerDesc *****/
29 CPlayerDesc::CPlayerDesc()
30 : factory(0), extensions(0), extlength(0)
34 CPlayerDesc::CPlayerDesc(const CPlayerDesc &pd)
35 : factory(pd.factory), filetype(pd.filetype), extlength(pd.extlength)
38 extensions = (char *)malloc(extlength);
39 memcpy(extensions, pd.extensions, extlength);
44 CPlayerDesc::CPlayerDesc(Factory f, const std::string &type, const char *ext)
45 : factory(f), filetype(type), extensions(0)
49 // Determine length of passed extensions list
50 while(*i) i += strlen(i) + 1;
51 extlength = i - ext + 1; // length = difference between last and first char + 1
53 extensions = (char *)malloc(extlength);
54 memcpy(extensions, ext, extlength);
57 CPlayerDesc::~CPlayerDesc()
59 if(extensions) free(extensions);
62 void CPlayerDesc::add_extension(const char *ext)
64 unsigned long newlength = extlength + strlen(ext) + 1;
66 extensions = (char *)realloc(extensions, newlength);
67 strcpy(extensions + extlength - 1, ext);
68 extensions[newlength - 1] = '\0';
69 extlength = newlength;
72 const char *CPlayerDesc::get_extension(unsigned int n) const
74 const char *i = extensions;
77 for(j = 0; j < n && (*i); j++, i += strlen(i) + 1) ;
78 return (*i != '\0' ? i : 0);
81 /***** CPlayers *****/
83 const CPlayerDesc *CPlayers::lookup_filetype(const std::string &ftype) const
87 for(i = begin(); i != end(); i++)
88 if((*i)->filetype == ftype)
94 const CPlayerDesc *CPlayers::lookup_extension(const std::string &extension) const
99 for(i = begin(); i != end(); i++)
100 for(j = 0; (*i)->get_extension(j); j++)
101 if(!stricmp(extension.c_str(), (*i)->get_extension(j)))