1 /*
2 * libcddb - CDDB Interface Library for xmcd/cda
3 *
4 * This library implements an interface to access the "classic"
5 * CDDB1 services.
6 *
7 * Copyright (C) 1993-2004 Ti Kan
8 * E-mail: xmcd@amb.org
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25 #ifndef lint
26 static char *_genretree_c_ident_ = "@(#)genretree.c 1.11 03/12/12";
27 #endif
28
29 #include "fcddb.h"
30
31
32 /*
33 * CddbGenreTree_GetCount
34 * Return the number of genre lists in the tree
35 */
36 CddbResult
CddbGenreTree_GetCount(CddbGenreTreePtr gtreep,long * pval)37 CddbGenreTree_GetCount(CddbGenreTreePtr gtreep, long *pval)
38 {
39 cddb_genretree_t *p = (cddb_genretree_t *) gtreep;
40
41 *pval = p->count;
42 return Cddb_OK;
43 }
44
45
46 /*
47 * CddbGenreTree_GetMetaGenre
48 * Return a meta genre in the tree
49 */
50 CddbResult
CddbGenreTree_GetMetaGenre(CddbGenreTreePtr gtreep,long item,CddbGenrePtr * pval)51 CddbGenreTree_GetMetaGenre(
52 CddbGenreTreePtr gtreep,
53 long item,
54 CddbGenrePtr *pval
55 )
56 {
57 cddb_genretree_t *p = (cddb_genretree_t *) gtreep;
58 cddb_genre_t *gp;
59 long i;
60
61 for (i = 1, gp = p->genres; p != NULL; i++, gp = gp->nextmeta) {
62 if (i == item)
63 break;
64 }
65 if (i > item) {
66 *pval = NULL;
67 return Cddb_E_INVALIDARG;
68 }
69
70 *pval = (CddbGenrePtr) gp;
71 return Cddb_OK;
72 }
73
74
75 /*
76 * CddbGenreTree_GetSubGenreList
77 * Return a genre list in the tree
78 */
79 CddbResult
CddbGenreTree_GetSubGenreList(CddbGenreTreePtr gtreep,CddbConstStr id,CddbGenreListPtr * pval)80 CddbGenreTree_GetSubGenreList(
81 CddbGenreTreePtr gtreep,
82 CddbConstStr id,
83 CddbGenreListPtr *pval
84 )
85 {
86 cddb_genretree_t *p = (cddb_genretree_t *) gtreep;
87 cddb_genrelist_t *glp;
88 cddb_genre_t *gp;
89
90 *pval = NULL;
91 for (gp = p->genres; gp != NULL; gp = gp->nextmeta) {
92 if (gp->id != NULL && strcmp(gp->id, id) == 0) {
93 glp = (cddb_genrelist_t *) fcddb_obj_alloc(
94 "CddbGenreList",
95 sizeof(cddb_genrelist_t)
96 );
97 if (glp == NULL)
98 return CDDBTRNOutOfMemory;
99
100 glp->genres = gp->next;
101 *pval = (CddbGenreListPtr) glp;
102 break;
103 }
104 }
105 return Cddb_OK;
106 }
107
108
109