annotate Plugins/Input/sid/xs_stil.c @ 269:1b82a9932b60 trunk

[svn] Import sid plugin. Ported from XMMS by giacomo.
author chainsaw
date Thu, 08 Dec 2005 15:12:12 -0800
parents
children d0e9693d2115
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
1 /*
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
3
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
4 STIL-database handling functions
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
5
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
8
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
12 (at your option) any later version.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
13
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
17 GNU General Public License for more details.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
18
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
20 along with this program; if not, write to the Free Software
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
22 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
23 #include "xs_stil.h"
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
24 #include "xs_support.h"
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
25 #include "xs_config.h"
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
26 #include <stdio.h>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
27 #include <stdlib.h>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
28 #include <ctype.h>
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
29
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
30
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
31 /* Database handling functions
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
32 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
33 static t_xs_stil_node *xs_stildb_node_new(gchar * pcFilename)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
34 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
35 t_xs_stil_node *pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
36
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
37 /* Allocate memory for new node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
38 pResult = (t_xs_stil_node *) g_malloc0(sizeof(t_xs_stil_node));
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
39 if (!pResult)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
40 return NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
41
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
42 pResult->pcFilename = g_strdup(pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
43 if (!pResult->pcFilename) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
44 g_free(pResult);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
45 return NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
46 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
47
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
48 return pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
49 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
50
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
51
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
52 static void xs_stildb_node_free(t_xs_stil_node * pNode)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
53 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
54 gint i;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
55
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
56 if (pNode) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
57 /* Free subtune information */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
58 for (i = 0; i <= XS_STIL_MAXENTRY; i++) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
59 g_free(pNode->subTunes[i].pName);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
60 g_free(pNode->subTunes[i].pAuthor);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
61 g_free(pNode->subTunes[i].pInfo);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
62 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
63
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
64 g_free(pNode->pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
65 g_free(pNode);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
66 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
67 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
68
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
69
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
70 /* Insert given node to db linked list
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
71 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
72 static void xs_stildb_node_insert(t_xs_stildb * db, t_xs_stil_node * pNode)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
73 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
74 assert(db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
75
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
76 if (db->pNodes) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
77 /* The first node's pPrev points to last node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
78 LPREV = db->pNodes->pPrev; /* New node's prev = Previous last node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
79 db->pNodes->pPrev->pNext = pNode; /* Previous last node's next = New node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
80 db->pNodes->pPrev = pNode; /* New last node = New node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
81 LNEXT = NULL; /* But next is NULL! */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
82 } else {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
83 db->pNodes = pNode; /* First node ... */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
84 LPREV = pNode; /* ... it's also last */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
85 LNEXT = NULL; /* But next is NULL! */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
86 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
87 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
88
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
89
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
90 /* Read database (additively) to given db-structure
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
91 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
92 #define XS_STILDB_MULTI if (isMulti) { isMulti = FALSE; xs_pstrcat(&(tmpNode->subTunes[subEntry].pInfo), "\n"); }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
93
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
94
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
95 gint xs_stildb_read(t_xs_stildb * db, gchar * dbFilename)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
96 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
97 FILE *inFile;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
98 gchar inLine[XS_BUF_SIZE + 16]; /* Since we add some chars here and there */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
99 guint lineNum, linePos, eolPos;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
100 t_xs_stil_node *tmpNode;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
101 gboolean isError, isMulti;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
102 gint subEntry;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
103 assert(db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
104
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
105 /* Try to open the file */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
106 if ((inFile = fopen(dbFilename, "ra")) == NULL) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
107 XSERR("Could not open STILDB '%s'\n", dbFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
108 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
109 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
110
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
111 /* Read and parse the data */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
112 lineNum = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
113 isError = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
114 isMulti = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
115 tmpNode = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
116 subEntry = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
117
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
118 while (!feof(inFile) && !isError) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
119 fgets(inLine, XS_BUF_SIZE, inFile);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
120 inLine[XS_BUF_SIZE - 1] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
121 linePos = eolPos = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
122 xs_findeol(inLine, &eolPos);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
123 inLine[eolPos] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
124 lineNum++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
125
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
126 switch (inLine[0]) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
127 case '/':
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
128 /* Check if we are already parsing entry */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
129 isMulti = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
130 if (tmpNode) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
131 XSERR("New entry ('%s') before end of current ('%s')! Possibly malformed STIL-file!\n",
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
132 inLine, tmpNode->pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
133
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
134 xs_stildb_node_free(tmpNode);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
135 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
136
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
137 /* A new node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
138 subEntry = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
139 tmpNode = xs_stildb_node_new(inLine);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
140 if (!tmpNode) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
141 /* Allocation failed */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
142 XSERR("Could not allocate new STILdb-node for '%s'!\n", inLine);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
143 isError = TRUE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
144 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
145 break;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
146
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
147 case '(':
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
148 /* A new sub-entry */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
149 isMulti = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
150 linePos++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
151 if (inLine[linePos] == '#') {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
152 linePos++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
153 if (inLine[linePos]) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
154 xs_findnum(inLine, &linePos);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
155 inLine[linePos] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
156 subEntry = atol(&inLine[2]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
157
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
158 /* Sanity check */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
159 if ((subEntry < 1) || (subEntry > XS_STIL_MAXENTRY)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
160 XSERR("Number of subEntry (%i) for '%s' is invalid\n", subEntry,
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
161 tmpNode->pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
162 subEntry = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
163 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
164 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
165 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
166
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
167 break;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
168
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
169 case 0:
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
170 case '#':
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
171 case '\n':
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
172 case '\r':
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
173 /* End of entry/field */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
174 isMulti = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
175 if (tmpNode) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
176 /* Insert to database */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
177 xs_stildb_node_insert(db, tmpNode);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
178 tmpNode = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
179 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
180 break;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
181
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
182 default:
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
183 /* Check if we are parsing an entry */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
184 if (!tmpNode) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
185 XSERR("Entry data encountered outside of entry!\n");
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
186 break;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
187 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
188
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
189 /* Some other type */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
190 if (strncmp(inLine, " NAME:", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
191 XS_STILDB_MULTI g_free(tmpNode->subTunes[subEntry].pName);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
192 tmpNode->subTunes[subEntry].pName = g_strdup(&inLine[9]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
193 } else if (strncmp(inLine, " AUTHOR:", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
194 XS_STILDB_MULTI g_free(tmpNode->subTunes[subEntry].pAuthor);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
195 tmpNode->subTunes[subEntry].pAuthor = g_strdup(&inLine[9]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
196 } else if (strncmp(inLine, " TITLE:", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
197 XS_STILDB_MULTI inLine[eolPos++] = '\n';
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
198 inLine[eolPos++] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
199 xs_pstrcat(&(tmpNode->subTunes[subEntry].pInfo), &inLine[2]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
200 } else if (strncmp(inLine, " ARTIST:", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
201 XS_STILDB_MULTI inLine[eolPos++] = '\n';
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
202 inLine[eolPos++] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
203 xs_pstrcat(&(tmpNode->subTunes[subEntry].pInfo), &inLine[1]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
204 } else if (strncmp(inLine, "COMMENT:", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
205 XS_STILDB_MULTI isMulti = TRUE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
206 xs_pstrcat(&(tmpNode->subTunes[subEntry].pInfo), inLine);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
207 } else if (strncmp(inLine, " ", 8) == 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
208 xs_pstrcat(&(tmpNode->subTunes[subEntry].pInfo), &inLine[8]);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
209 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
210 break;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
211 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
212
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
213 } /* while */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
214
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
215 /* Check if there is one remaining node */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
216 if (tmpNode)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
217 xs_stildb_node_insert(db, tmpNode);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
218
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
219 /* Close the file */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
220 fclose(inFile);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
221
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
222 return 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
223 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
224
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
225
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
226 /* Compare two nodes
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
227 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
228 static gint xs_stildb_cmp(const void *pNode1, const void *pNode2)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
229 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
230 /* We assume here that we never ever get NULL-pointers or similar */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
231 return strcmp((*(t_xs_stil_node **) pNode1)->pcFilename, (*(t_xs_stil_node **) pNode2)->pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
232 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
233
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
234
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
235 /* (Re)create index
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
236 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
237 gint xs_stildb_index(t_xs_stildb * db)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
238 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
239 t_xs_stil_node *pCurr;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
240 gint i;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
241
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
242 /* Free old index */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
243 if (db->ppIndex) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
244 g_free(db->ppIndex);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
245 db->ppIndex = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
246 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
247
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
248 /* Get size of db */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
249 pCurr = db->pNodes;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
250 db->n = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
251 while (pCurr) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
252 db->n++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
253 pCurr = pCurr->pNext;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
254 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
255
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
256 /* Check number of nodes */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
257 if (db->n > 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
258 /* Allocate memory for index-table */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
259 db->ppIndex = (t_xs_stil_node **) g_malloc(sizeof(t_xs_stil_node *) * db->n);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
260 if (!db->ppIndex)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
261 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
262
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
263 /* Get node-pointers to table */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
264 i = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
265 pCurr = db->pNodes;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
266 while (pCurr && (i < db->n)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
267 db->ppIndex[i++] = pCurr;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
268 pCurr = pCurr->pNext;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
269 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
270
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
271 /* Sort the indexes */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
272 qsort(db->ppIndex, db->n, sizeof(t_xs_stil_node *), xs_stildb_cmp);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
273 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
274
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
275 return 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
276 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
277
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
278 /* Free a given STIL database
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
279 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
280 void xs_stildb_free(t_xs_stildb * db)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
281 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
282 t_xs_stil_node *pCurr, *pNext;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
283
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
284 if (!db)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
285 return;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
286
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
287 /* Free the memory allocated for nodes */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
288 pCurr = db->pNodes;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
289 while (pCurr) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
290 pNext = pCurr->pNext;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
291 xs_stildb_node_free(pCurr);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
292 pCurr = pNext;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
293 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
294
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
295 db->pNodes = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
296
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
297 /* Free memory allocated for index */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
298 if (db->ppIndex) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
299 g_free(db->ppIndex);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
300 db->ppIndex = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
301 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
302
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
303 /* Free structure */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
304 db->n = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
305 g_free(db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
306 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
307
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
308
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
309 /* Get STIL information node from database
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
310 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
311 static t_xs_stil_node *xs_stildb_get_node(t_xs_stildb * db, gchar * pcFilename)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
312 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
313 gint iStartNode, iEndNode, iQNode, r, i;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
314 gboolean iFound;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
315 t_xs_stil_node *pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
316
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
317 /* Check the database pointers */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
318 if (!db || !db->pNodes || !db->ppIndex)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
319 return NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
320
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
321 /* Look-up via index using binary search */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
322 pResult = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
323 iStartNode = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
324 iEndNode = (db->n - 1);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
325 iQNode = (iEndNode / 2);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
326 iFound = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
327
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
328 while ((!iFound) && ((iEndNode - iStartNode) > XS_BIN_BAILOUT)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
329 r = strcmp(pcFilename, db->ppIndex[iQNode]->pcFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
330 if (r < 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
331 /* Hash was in the <- LEFT side */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
332 iEndNode = iQNode;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
333 iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
334 } else if (r > 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
335 /* Hash was in the RIGHT -> side */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
336 iStartNode = iQNode;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
337 iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
338 } else
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
339 iFound = TRUE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
340 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
341
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
342 /* If not found already */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
343 if (!iFound) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
344 /* Search the are linearly */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
345 iFound = FALSE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
346 i = iStartNode;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
347 while ((i <= iEndNode) && (!iFound)) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
348 if (strcmp(pcFilename, db->ppIndex[i]->pcFilename) == 0)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
349 iFound = TRUE;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
350 else
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
351 i++;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
352 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
353
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
354 /* Check the result */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
355 if (iFound)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
356 pResult = db->ppIndex[i];
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
357
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
358 } else {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
359 /* Found via binary search */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
360 pResult = db->ppIndex[iQNode];
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
361 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
362
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
363 return pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
364 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
365
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
366
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
367 /*
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
368 * These should be moved out of this module some day ...
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
369 */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
370 static t_xs_stildb *xs_stildb_db = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
371 XS_MUTEX(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
372
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
373 gint xs_stil_init(void)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
374 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
375 XS_MUTEX_LOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
376
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
377 if (!xs_cfg.stilDBPath) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
378 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
379 return -1;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
380 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
381
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
382 XS_MUTEX_LOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
383
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
384 /* Check if already initialized */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
385 if (xs_stildb_db)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
386 xs_stildb_free(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
387
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
388 /* Allocate database */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
389 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb));
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
390 if (!xs_stildb_db) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
391 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
392 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
393 return -2;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
394 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
395
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
396 /* Read the database */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
397 if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
398 xs_stildb_free(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
399 xs_stildb_db = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
400 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
401 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
402 return -3;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
403 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
404
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
405 /* Create index */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
406 if (xs_stildb_index(xs_stildb_db) != 0) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
407 xs_stildb_free(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
408 xs_stildb_db = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
409 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
410 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
411 return -4;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
412 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
413
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
414 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
415 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
416 return 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
417 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
418
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
419
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
420 void xs_stil_close(void)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
421 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
422 XS_MUTEX_LOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
423 xs_stildb_free(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
424 xs_stildb_db = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
425 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
426 }
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
427
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
428
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
429 t_xs_stil_node *xs_stil_get(gchar * pcFilename)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
430 {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
431 t_xs_stil_node *pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
432 gchar *tmpFilename;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
433
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
434 XS_MUTEX_LOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
435 XS_MUTEX_LOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
436
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
437 if (xs_cfg.stilDBEnable && xs_stildb_db) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
438 if (xs_cfg.hvscPath) {
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
439 /* Remove postfixed directory separator from HVSC-path */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
440 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/');
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
441 if (tmpFilename && (tmpFilename[1] == 0))
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
442 tmpFilename[0] = 0;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
443
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
444 /* Remove HVSC location-prefix from filename */
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
445 tmpFilename = strstr(pcFilename, xs_cfg.hvscPath);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
446 if (tmpFilename)
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
447 tmpFilename += strlen(xs_cfg.hvscPath);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
448 else
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
449 tmpFilename = pcFilename;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
450 } else
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
451 tmpFilename = pcFilename;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
452
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
453 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
454 } else
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
455 pResult = NULL;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
456
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
457 XS_MUTEX_UNLOCK(xs_stildb_db);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
458 XS_MUTEX_UNLOCK(xs_cfg);
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
459
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
460 return pResult;
1b82a9932b60 [svn] Import sid plugin. Ported from XMMS by giacomo.
chainsaw
parents:
diff changeset
461 }