Mercurial > hg > xmms-sid
comparison src/xs_stil.c @ 230:608f31f6c095
Raw cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 09:25:03 +0000 |
parents | 92bad4c7b998 |
children | e613873c3379 |
comparison
equal
deleted
inserted
replaced
229:7bb9e20e3092 | 230:608f31f6c095 |
---|---|
19 along with this program; if not, write to the Free Software | 19 along with this program; if not, write to the Free Software |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 */ | 21 */ |
22 #include "xs_stil.h" | 22 #include "xs_stil.h" |
23 #include "xs_support.h" | 23 #include "xs_support.h" |
24 #include "xs_config.h" | |
24 #include <stdio.h> | 25 #include <stdio.h> |
25 #include <stdlib.h> | 26 #include <stdlib.h> |
26 #include <ctype.h> | 27 #include <ctype.h> |
27 | 28 |
28 | 29 |
381 | 382 |
382 return pResult; | 383 return pResult; |
383 } | 384 } |
384 | 385 |
385 | 386 |
386 /* Get from STIL database | 387 /* |
387 */ | 388 * These should be moved out of this module some day ... |
388 t_xs_stil_node * xs_stildb_get(t_xs_stildb *db, gchar *hvscPath, gchar *pcFilename) | 389 */ |
389 { | 390 static t_xs_stildb *xs_stildb_db = NULL; |
391 XS_MUTEX(xs_stildb_db); | |
392 | |
393 gint xs_stil_init(void) | |
394 { | |
395 XS_MUTEX_LOCK(xs_cfg); | |
396 | |
397 if (!xs_cfg.stilDBPath) | |
398 { | |
399 XS_MUTEX_UNLOCK(xs_cfg); | |
400 return -1; | |
401 } | |
402 | |
403 XS_MUTEX_LOCK(xs_stildb_db); | |
404 | |
405 /* Check if already initialized */ | |
406 if (xs_stildb_db) xs_stildb_free(xs_stildb_db); | |
407 | |
408 /* Allocate database */ | |
409 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); | |
410 if (!xs_stildb_db) | |
411 { | |
412 XS_MUTEX_UNLOCK(xs_cfg); | |
413 XS_MUTEX_UNLOCK(xs_stildb_db); | |
414 return -2; | |
415 } | |
416 | |
417 /* Read the database */ | |
418 if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) | |
419 { | |
420 xs_stildb_free(xs_stildb_db); | |
421 xs_stildb_db = NULL; | |
422 XS_MUTEX_UNLOCK(xs_cfg); | |
423 XS_MUTEX_UNLOCK(xs_stildb_db); | |
424 return -3; | |
425 } | |
426 | |
427 /* Create index */ | |
428 if (xs_stildb_index(xs_stildb_db) != 0) | |
429 { | |
430 xs_stildb_free(xs_stildb_db); | |
431 xs_stildb_db = NULL; | |
432 XS_MUTEX_UNLOCK(xs_cfg); | |
433 XS_MUTEX_UNLOCK(xs_stildb_db); | |
434 return -4; | |
435 } | |
436 | |
437 XS_MUTEX_UNLOCK(xs_cfg); | |
438 XS_MUTEX_UNLOCK(xs_stildb_db); | |
439 return 0; | |
440 } | |
441 | |
442 | |
443 void xs_stil_close(void) | |
444 { | |
445 XS_MUTEX_LOCK(xs_stildb_db); | |
446 xs_stildb_free(xs_stildb_db); | |
447 xs_stildb_db = NULL; | |
448 XS_MUTEX_UNLOCK(xs_stildb_db); | |
449 } | |
450 | |
451 | |
452 t_xs_stil_node * xs_stil_get(gchar *pcFilename) | |
453 { | |
454 t_xs_stil_node *pResult; | |
390 gchar *tmpFilename; | 455 gchar *tmpFilename; |
391 | 456 |
392 /* Remove postfixed directory separator from HVSC-path */ | 457 XS_MUTEX_LOCK(xs_stildb_db); |
393 tmpFilename = xs_strrchr(hvscPath, '/'); | 458 XS_MUTEX_LOCK(xs_cfg); |
394 if (tmpFilename && (tmpFilename[1] == 0)) | 459 |
395 tmpFilename[0] = 0; | 460 if (xs_cfg.hvscPath) |
396 | 461 { |
397 /* Remove HVSC location-prefix from filename */ | 462 /* Remove postfixed directory separator from HVSC-path */ |
398 tmpFilename = strstr(pcFilename, hvscPath); | 463 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/'); |
399 if (tmpFilename) | 464 if (tmpFilename && (tmpFilename[1] == 0)) |
400 tmpFilename += strlen(hvscPath); | 465 tmpFilename[0] = 0; |
401 else | 466 |
402 tmpFilename = pcFilename; | 467 /* Remove HVSC location-prefix from filename */ |
403 | 468 tmpFilename = strstr(pcFilename, xs_cfg.hvscPath); |
404 return xs_stildb_get_node(db, pcFilename); | 469 if (tmpFilename) |
405 } | 470 tmpFilename += strlen(xs_cfg.hvscPath); |
406 | 471 else |
472 tmpFilename = pcFilename; | |
473 } else | |
474 tmpFilename = pcFilename; | |
475 | |
476 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); | |
477 | |
478 XS_MUTEX_UNLOCK(xs_stildb_db); | |
479 XS_MUTEX_UNLOCK(xs_cfg); | |
480 | |
481 return pResult; | |
482 } | |
483 |