comparison src/xs_slsup.c @ 657:acaba070cf49

Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Apr 2008 19:46:59 +0300
parents d7389ea52113
children b0743dc9165d
comparison
equal deleted inserted replaced
656:e9257f006f41 657:acaba070cf49
22 */ 22 */
23 #include "xs_slsup.h" 23 #include "xs_slsup.h"
24 #include "xs_config.h" 24 #include "xs_config.h"
25 25
26 26
27 static t_xs_sldb *xs_sldb_db = NULL; 27 static xs_sldb_t *xs_sldb_db = NULL;
28 XS_MUTEX(xs_sldb_db); 28 XS_MUTEX(xs_sldb_db);
29 29
30 static t_xs_stildb *xs_stildb_db = NULL; 30 static xs_stildb_t *xs_stildb_db = NULL;
31 XS_MUTEX(xs_stildb_db); 31 XS_MUTEX(xs_stildb_db);
32 32
33 33
34 /* STIL-database handling 34 /* STIL-database handling
35 */ 35 */
47 /* Check if already initialized */ 47 /* Check if already initialized */
48 if (xs_stildb_db) 48 if (xs_stildb_db)
49 xs_stildb_free(xs_stildb_db); 49 xs_stildb_free(xs_stildb_db);
50 50
51 /* Allocate database */ 51 /* Allocate database */
52 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); 52 xs_stildb_db = (xs_stildb_t *) g_malloc0(sizeof(xs_stildb_t));
53 if (!xs_stildb_db) { 53 if (!xs_stildb_db) {
54 XS_MUTEX_UNLOCK(xs_cfg); 54 XS_MUTEX_UNLOCK(xs_cfg);
55 XS_MUTEX_UNLOCK(xs_stildb_db); 55 XS_MUTEX_UNLOCK(xs_stildb_db);
56 return -2; 56 return -2;
57 } 57 }
87 xs_stildb_db = NULL; 87 xs_stildb_db = NULL;
88 XS_MUTEX_UNLOCK(xs_stildb_db); 88 XS_MUTEX_UNLOCK(xs_stildb_db);
89 } 89 }
90 90
91 91
92 t_xs_stil_node *xs_stil_get(gchar *pcFilename) 92 stil_node_t *xs_stil_get(gchar *filename)
93 { 93 {
94 t_xs_stil_node *pResult; 94 stil_node_t *result;
95 gchar *tmpFilename; 95 gchar *tmpFilename;
96 96
97 XS_MUTEX_LOCK(xs_stildb_db); 97 XS_MUTEX_LOCK(xs_stildb_db);
98 XS_MUTEX_LOCK(xs_cfg); 98 XS_MUTEX_LOCK(xs_cfg);
99 99
103 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/'); 103 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/');
104 if (tmpFilename && (tmpFilename[1] == 0)) 104 if (tmpFilename && (tmpFilename[1] == 0))
105 tmpFilename[0] = 0; 105 tmpFilename[0] = 0;
106 106
107 /* Remove HVSC location-prefix from filename */ 107 /* Remove HVSC location-prefix from filename */
108 tmpFilename = strstr(pcFilename, xs_cfg.hvscPath); 108 tmpFilename = strstr(filename, xs_cfg.hvscPath);
109 if (tmpFilename) 109 if (tmpFilename)
110 tmpFilename += strlen(xs_cfg.hvscPath); 110 tmpFilename += strlen(xs_cfg.hvscPath);
111 else 111 else
112 tmpFilename = pcFilename; 112 tmpFilename = filename;
113 } else 113 } else
114 tmpFilename = pcFilename; 114 tmpFilename = filename;
115 115
116 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); 116 result = xs_stildb_get_node(xs_stildb_db, tmpFilename);
117 } else 117 } else
118 pResult = NULL; 118 result = NULL;
119 119
120 XS_MUTEX_UNLOCK(xs_stildb_db); 120 XS_MUTEX_UNLOCK(xs_stildb_db);
121 XS_MUTEX_UNLOCK(xs_cfg); 121 XS_MUTEX_UNLOCK(xs_cfg);
122 122
123 return pResult; 123 return result;
124 } 124 }
125 125
126 126
127 /* Song length database handling glue 127 /* Song length database handling glue
128 */ 128 */
140 /* Check if already initialized */ 140 /* Check if already initialized */
141 if (xs_sldb_db) 141 if (xs_sldb_db)
142 xs_sldb_free(xs_sldb_db); 142 xs_sldb_free(xs_sldb_db);
143 143
144 /* Allocate database */ 144 /* Allocate database */
145 xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb)); 145 xs_sldb_db = (xs_sldb_t *) g_malloc0(sizeof(xs_sldb_t));
146 if (!xs_sldb_db) { 146 if (!xs_sldb_db) {
147 XS_MUTEX_UNLOCK(xs_cfg); 147 XS_MUTEX_UNLOCK(xs_cfg);
148 XS_MUTEX_UNLOCK(xs_sldb_db); 148 XS_MUTEX_UNLOCK(xs_sldb_db);
149 return -2; 149 return -2;
150 } 150 }
180 xs_sldb_db = NULL; 180 xs_sldb_db = NULL;
181 XS_MUTEX_UNLOCK(xs_sldb_db); 181 XS_MUTEX_UNLOCK(xs_sldb_db);
182 } 182 }
183 183
184 184
185 t_xs_sldb_node *xs_songlen_get(const gchar * pcFilename) 185 sldb_node_t *xs_songlen_get(const gchar * filename)
186 { 186 {
187 t_xs_sldb_node *pResult; 187 sldb_node_t *result;
188 188
189 XS_MUTEX_LOCK(xs_sldb_db); 189 XS_MUTEX_LOCK(xs_sldb_db);
190 190
191 if (xs_cfg.songlenDBEnable && xs_sldb_db) 191 if (xs_cfg.songlenDBEnable && xs_sldb_db)
192 pResult = xs_sldb_get(xs_sldb_db, pcFilename); 192 result = xs_sldb_get(xs_sldb_db, filename);
193 else 193 else
194 pResult = NULL; 194 result = NULL;
195 195
196 XS_MUTEX_UNLOCK(xs_sldb_db); 196 XS_MUTEX_UNLOCK(xs_sldb_db);
197 197
198 return pResult; 198 return result;
199 } 199 }
200 200
201 201
202 /* Allocate a new tune information structure 202 /* Allocate a new tune information structure
203 */ 203 */
204 t_xs_tuneinfo *xs_tuneinfo_new(const gchar * pcFilename, 204 xs_tuneinfo_t *xs_tuneinfo_new(const gchar * filename,
205 gint nsubTunes, gint startTune, const gchar * sidName, 205 gint nsubTunes, gint startTune, const gchar * sidName,
206 const gchar * sidComposer, const gchar * sidCopyright, 206 const gchar * sidComposer, const gchar * sidCopyright,
207 gint loadAddr, gint initAddr, gint playAddr, 207 gint loadAddr, gint initAddr, gint playAddr,
208 gint dataFileLen, const gchar *sidFormat, gint sidModel) 208 gint dataFileLen, const gchar *sidFormat, gint sidModel)
209 { 209 {
210 t_xs_tuneinfo *pResult; 210 xs_tuneinfo_t *result;
211 t_xs_sldb_node *tmpLength; 211 sldb_node_t *tmpLength;
212 gint i; 212 gint i;
213 213
214 /* Allocate structure */ 214 /* Allocate structure */
215 pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo)); 215 result = (xs_tuneinfo_t *) g_malloc0(sizeof(xs_tuneinfo_t));
216 if (!pResult) { 216 if (!result) {
217 xs_error(_("Could not allocate memory for t_xs_tuneinfo ('%s')\n"), 217 xs_error("Could not allocate memory for tuneinfo ('%s')\n",
218 pcFilename); 218 filename);
219 return NULL; 219 return NULL;
220 } 220 }
221 221
222 pResult->sidFilename = XS_CS_FILENAME(pcFilename); 222 result->sidFilename = XS_CS_FILENAME(filename);
223 if (!pResult->sidFilename) { 223 if (!result->sidFilename) {
224 xs_error(_("Could not allocate sidFilename ('%s')\n"), 224 xs_error("Could not allocate sidFilename ('%s')\n",
225 pcFilename); 225 filename);
226 g_free(pResult); 226 g_free(result);
227 return NULL; 227 return NULL;
228 } 228 }
229 229
230 /* Allocate space for subtune information */ 230 /* Allocate space for subtune information */
231 pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * (nsubTunes + 1)); 231 result->subTunes = g_malloc0(sizeof(xs_subtuneinfo_t) * (nsubTunes + 1));
232 if (!pResult->subTunes) { 232 if (!result->subTunes) {
233 xs_error(_("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n"), 233 xs_error("Could not allocate memory for subtuneinfo ('%s', %i)\n",
234 pcFilename, nsubTunes); 234 filename, nsubTunes);
235 235
236 g_free(pResult->sidFilename); 236 g_free(result->sidFilename);
237 g_free(pResult); 237 g_free(result);
238 return NULL; 238 return NULL;
239 } 239 }
240 240
241 /* The following allocations don't matter if they fail */ 241 /* The following allocations don't matter if they fail */
242 pResult->sidName = XS_CS_SID(sidName); 242 result->sidName = XS_CS_SID(sidName);
243 pResult->sidComposer = XS_CS_SID(sidComposer); 243 result->sidComposer = XS_CS_SID(sidComposer);
244 pResult->sidCopyright = XS_CS_SID(sidCopyright); 244 result->sidCopyright = XS_CS_SID(sidCopyright);
245 245
246 pResult->nsubTunes = nsubTunes; 246 result->nsubTunes = nsubTunes;
247 pResult->startTune = startTune; 247 result->startTune = startTune;
248 248
249 pResult->loadAddr = loadAddr; 249 result->loadAddr = loadAddr;
250 pResult->initAddr = initAddr; 250 result->initAddr = initAddr;
251 pResult->playAddr = playAddr; 251 result->playAddr = playAddr;
252 pResult->dataFileLen = dataFileLen; 252 result->dataFileLen = dataFileLen;
253 pResult->sidFormat = XS_CS_SID(sidFormat); 253 result->sidFormat = XS_CS_SID(sidFormat);
254 254
255 pResult->sidModel = sidModel; 255 result->sidModel = sidModel;
256 256
257 /* Get length information (NOTE: Do not free this!) */ 257 /* Get length information (NOTE: Do not free this!) */
258 tmpLength = xs_songlen_get(pcFilename); 258 tmpLength = xs_songlen_get(filename);
259 259
260 /* Fill in sub-tune information */ 260 /* Fill in sub-tune information */
261 for (i = 0; i < pResult->nsubTunes; i++) { 261 for (i = 0; i < result->nsubTunes; i++) {
262 if (tmpLength && (i < tmpLength->nLengths)) 262 if (tmpLength && (i < tmpLength->nlengths))
263 pResult->subTunes[i].tuneLength = tmpLength->sLengths[i]; 263 result->subTunes[i].tuneLength = tmpLength->lengths[i];
264 else 264 else
265 pResult->subTunes[i].tuneLength = -1; 265 result->subTunes[i].tuneLength = -1;
266 266
267 pResult->subTunes[i].tuneSpeed = -1; 267 result->subTunes[i].tuneSpeed = -1;
268 } 268 }
269 269
270 return pResult; 270 return result;
271 } 271 }
272 272
273 273
274 /* Free given tune information structure 274 /* Free given tune information structure
275 */ 275 */
276 void xs_tuneinfo_free(t_xs_tuneinfo * pTune) 276 void xs_tuneinfo_free(xs_tuneinfo_t * tune)
277 { 277 {
278 if (!pTune) return; 278 if (!tune) return;
279 279
280 g_free(pTune->subTunes); 280 g_free(tune->subTunes);
281 g_free(pTune->sidFilename); 281 g_free(tune->sidFilename);
282 g_free(pTune->sidName); 282 g_free(tune->sidName);
283 g_free(pTune->sidComposer); 283 g_free(tune->sidComposer);
284 g_free(pTune->sidCopyright); 284 g_free(tune->sidCopyright);
285 g_free(pTune->sidFormat); 285 g_free(tune->sidFormat);
286 g_free(pTune); 286 g_free(tune);
287 } 287 }