annotate src/xs_stil.c @ 232:e613873c3379

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