Mercurial > audlegacy
annotate Plugins/Input/adplug/core/players.cpp @ 1458:f12d7e208b43 trunk
[svn] Update FSF address in copyright notices. Update autotools templates.
author | chainsaw |
---|---|
date | Wed, 02 Aug 2006 15:44:07 -0700 |
parents | 8df427a314a8 |
children | 705d4c089fce |
rev | line source |
---|---|
359 | 1 /* |
2 * AdPlug - Replayer for many OPL2/OPL3 audio file formats. | |
3 * Copyright (C) 1999 - 2003 Simon Peter <dn.tlp@gmx.net>, et al. | |
4 * | |
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. | |
9 * | |
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. | |
14 * | |
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 | |
1458
f12d7e208b43
[svn] Update FSF address in copyright notices. Update autotools templates.
chainsaw
parents:
359
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA |
359 | 18 * |
19 * players.h - Players enumeration, by Simon Peter <dn.tlp@gmx.net> | |
20 */ | |
21 | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 | |
25 #include "players.h" | |
26 | |
27 /***** CPlayerDesc *****/ | |
28 | |
29 CPlayerDesc::CPlayerDesc() | |
30 : factory(0), extensions(0), extlength(0) | |
31 { | |
32 } | |
33 | |
34 CPlayerDesc::CPlayerDesc(const CPlayerDesc &pd) | |
35 : factory(pd.factory), filetype(pd.filetype), extlength(pd.extlength) | |
36 { | |
37 if(pd.extensions) { | |
38 extensions = (char *)malloc(extlength); | |
39 memcpy(extensions, pd.extensions, extlength); | |
40 } else | |
41 extensions = 0; | |
42 } | |
43 | |
44 CPlayerDesc::CPlayerDesc(Factory f, const std::string &type, const char *ext) | |
45 : factory(f), filetype(type), extensions(0) | |
46 { | |
47 const char *i = ext; | |
48 | |
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 | |
52 | |
53 extensions = (char *)malloc(extlength); | |
54 memcpy(extensions, ext, extlength); | |
55 } | |
56 | |
57 CPlayerDesc::~CPlayerDesc() | |
58 { | |
59 if(extensions) free(extensions); | |
60 } | |
61 | |
62 void CPlayerDesc::add_extension(const char *ext) | |
63 { | |
64 unsigned long newlength = extlength + strlen(ext) + 1; | |
65 | |
66 extensions = (char *)realloc(extensions, newlength); | |
67 strcpy(extensions + extlength - 1, ext); | |
68 extensions[newlength - 1] = '\0'; | |
69 extlength = newlength; | |
70 } | |
71 | |
72 const char *CPlayerDesc::get_extension(unsigned int n) const | |
73 { | |
74 const char *i = extensions; | |
75 unsigned int j; | |
76 | |
77 for(j = 0; j < n && (*i); j++, i += strlen(i) + 1) ; | |
78 return (*i != '\0' ? i : 0); | |
79 } | |
80 | |
81 /***** CPlayers *****/ | |
82 | |
83 const CPlayerDesc *CPlayers::lookup_filetype(const std::string &ftype) const | |
84 { | |
85 const_iterator i; | |
86 | |
87 for(i = begin(); i != end(); i++) | |
88 if((*i)->filetype == ftype) | |
89 return *i; | |
90 | |
91 return 0; | |
92 } | |
93 | |
94 const CPlayerDesc *CPlayers::lookup_extension(const std::string &extension) const | |
95 { | |
96 const_iterator i; | |
97 unsigned int j; | |
98 | |
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))) | |
102 return *i; | |
103 | |
104 return 0; | |
105 } |