Mercurial > hg > xmms-sid
annotate src/xs_stil.c @ 252:5a18af547f58
Fix few cases of multiline entry handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 20:15:04 +0000 |
parents | f436e16fa6d9 |
children | dd201740a720 |
rev | line source |
---|---|
1 | 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 | 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 | 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 | 7 |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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 | 24 #include "xs_config.h" |
1 | 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 | 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 */ |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
94 #define XS_STILDB_MULTI if (isMulti) { isMulti = FALSE; xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), "\n"); } |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
95 |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
96 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
97 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
|
98 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
99 FILE *inFile; |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
100 gchar inLine[XS_BUF_SIZE + 16]; /* Since we add some chars here and there */ |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
101 guint lineNum, linePos, eolPos; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
102 t_xs_stil_node *tmpNode; |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
103 gboolean isError, isMulti; |
110 | 104 gint subEntry; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
105 assert(db); |
94
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 /* Try to open the file */ |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
108 if ((inFile = fopen(dbFilename, "ra")) == NULL) |
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 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
|
111 return -1; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
112 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
113 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
114 /* Read and parse the data */ |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
115 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
|
116 isError = FALSE; |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
117 isMulti = FALSE; |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
118 tmpNode = NULL; |
132
4162a5370b9e
Added "seek"-subsong control option, in style of xmms-sidplay.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
119 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
|
120 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
121 while (!feof(inFile) && !isError) |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
122 { |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
123 fgets(inLine, XS_BUF_SIZE, inFile); |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
124 inLine[XS_BUF_SIZE-1] = 0; |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
125 linePos = eolPos = 0; |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
126 xs_findeol(inLine, &eolPos); |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
127 inLine[eolPos] = 0; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
128 lineNum++; |
103
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
129 |
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
130 switch (inLine[0]) { |
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
131 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
|
132 /* Check if we are already parsing entry */ |
252
5a18af547f58
Fix few cases of multiline entry handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
133 isMulti = FALSE; |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
134 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
|
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 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
|
137 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
|
138 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
139 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
|
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 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
142 /* A new node */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
143 subEntry = 0; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
144 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
|
145 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
|
146 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
147 /* 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
|
148 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
|
149 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
|
150 } |
103
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
151 break; |
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
152 |
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
153 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
|
154 /* A new sub-entry */ |
252
5a18af547f58
Fix few cases of multiline entry handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
155 isMulti = FALSE; |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
156 linePos++; |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
157 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
|
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 linePos++; |
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 (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
|
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 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
|
163 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
|
164 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
|
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 /* 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
|
167 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
|
168 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
169 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
|
170 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
|
171 } |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
172 } |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
173 } |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
174 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
175 break; |
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 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
|
178 case '#': |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
179 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
|
180 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
|
181 /* End of entry/field */ |
252
5a18af547f58
Fix few cases of multiline entry handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
182 isMulti = FALSE; |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
183 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
|
184 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
185 /* Insert to database */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
186 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
|
187 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
|
188 } |
103
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
189 break; |
101 | 190 |
103
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
191 default: |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
192 /* Check if we are parsing an entry */ |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
193 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
|
194 { |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
195 XSERR("Entry data encountered outside of entry!\n"); |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
196 break; |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
197 } |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
198 |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
199 /* 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
|
200 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
|
201 { |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
202 XS_STILDB_MULTI |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
203 |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
204 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
|
205 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
|
206 } else |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
207 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
|
208 { |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
209 XS_STILDB_MULTI |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
210 |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
211 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
|
212 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
|
213 } else |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
214 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
|
215 { |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
216 XS_STILDB_MULTI |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
217 |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
218 inLine[eolPos++] = '\n'; |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
219 inLine[eolPos++] = 0; |
224
df4cb5115322
Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
220 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
|
221 } else |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
222 if (strncmp(inLine, " ARTIST:", 8) == 0) |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
223 { |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
224 XS_STILDB_MULTI |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
225 |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
226 inLine[eolPos++] = '\n'; |
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
227 inLine[eolPos++] = 0; |
224
df4cb5115322
Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
228 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
|
229 } else |
117
453ac1293f6a
Fixed severe bug in xs_strmcat()
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
230 if (strncmp(inLine, "COMMENT:", 8) == 0) |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
231 { |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
232 XS_STILDB_MULTI |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
233 |
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
234 isMulti = TRUE; |
224
df4cb5115322
Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
235 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), inLine); |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
236 } 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
|
237 if (strncmp(inLine, " ", 8) == 0) |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
238 { |
224
df4cb5115322
Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
239 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[8]); |
240
f436e16fa6d9
Fixed cosmetic bug in handling of multi-line fields (COMMENT).
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
240 } |
103
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
241 break; |
fe83646e6baa
Changed plrFillBuffer()-functions to return actual number of samples computed.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
242 } |
101 | 243 |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
244 } /* while */ |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
245 |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
246 /* 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
|
247 if (tmpNode) |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
248 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
|
249 |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
250 /* Close the file */ |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
251 fclose(inFile); |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
252 |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
253 return 0; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
254 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
255 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
256 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
257 /* Compare two nodes |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
258 */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
259 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
|
260 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
261 /* 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
|
262 return strcmp((*(t_xs_stil_node **) pNode1)->pcFilename, |
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
263 (*(t_xs_stil_node **) pNode2)->pcFilename); |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
264 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
265 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
266 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
267 /* (Re)create index |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
268 */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
269 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
|
270 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
271 t_xs_stil_node *pCurr; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
272 gint i; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
273 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
274 /* Free old index */ |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
275 if (db->ppIndex) |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
276 { |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
277 g_free(db->ppIndex); |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
278 db->ppIndex = NULL; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
279 } |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
280 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
281 /* Get size of db */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
282 pCurr = db->pNodes; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
283 db->n = 0; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
284 while (pCurr) |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
285 { |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
286 db->n++; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
287 pCurr = pCurr->pNext; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
288 } |
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 /* Check number of nodes */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
291 if (db->n > 0) |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
292 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
293 /* 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
|
294 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
|
295 if (!db->ppIndex) return -1; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
296 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
297 /* Get node-pointers to table */ |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
298 i = 0; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
299 pCurr = db->pNodes; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
300 while (pCurr && (i < db->n)) |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
301 { |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
302 db->ppIndex[i++] = pCurr; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
303 pCurr = pCurr->pNext; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
304 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
305 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
306 /* Sort the indexes */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
307 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
|
308 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
309 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
310 return 0; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
311 } |
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 /* Free a given STIL database |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
314 */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
315 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
|
316 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
317 t_xs_stil_node *pCurr, *pNext; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
318 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
319 if (!db) return; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
320 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
321 /* 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
|
322 pCurr = db->pNodes; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
323 while (pCurr) |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
324 { |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
325 pNext = pCurr->pNext; |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
326 xs_stildb_node_free(pCurr); |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
327 pCurr = pNext; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
328 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
329 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
330 db->pNodes = NULL; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
331 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
332 /* Free memory allocated for index */ |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
333 if (db->ppIndex) |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
334 { |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
335 g_free(db->ppIndex); |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
336 db->ppIndex = NULL; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
337 } |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
338 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
339 /* Free structure */ |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
340 db->n = 0; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
341 g_free(db); |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
342 } |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
343 |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
344 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
345 /* Get STIL information node from database |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
346 */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
347 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
|
348 { |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
349 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
|
350 gboolean iFound; |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
351 t_xs_stil_node *pResult; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
352 |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
353 /* Check the database pointers */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
354 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
|
355 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
|
356 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
357 /* 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
|
358 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
|
359 iStartNode = 0; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
364 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
|
365 { |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
366 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
|
367 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
|
368 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
369 /* 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
|
370 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
|
371 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
|
372 } else |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
373 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
|
374 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
375 /* 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
|
376 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
|
377 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
|
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 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
|
380 } |
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 /* 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
|
383 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
|
384 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
385 /* 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
|
386 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
|
387 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
|
388 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
|
389 { |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
390 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
|
391 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
|
392 else |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
393 i++; |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
394 } |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
395 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
396 /* 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
|
397 if (iFound) |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
398 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
|
399 |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
400 } else { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
401 /* Found via binary search */ |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
402 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
|
403 } |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
404 |
94
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
405 return pResult; |
086681f70910
Start of re-write of STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
406 } |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
407 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
408 |
230 | 409 /* |
410 * 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
|
411 */ |
230 | 412 static t_xs_stildb *xs_stildb_db = NULL; |
413 XS_MUTEX(xs_stildb_db); | |
414 | |
415 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
|
416 { |
230 | 417 XS_MUTEX_LOCK(xs_cfg); |
418 | |
419 if (!xs_cfg.stilDBPath) | |
420 { | |
421 XS_MUTEX_UNLOCK(xs_cfg); | |
422 return -1; | |
423 } | |
424 | |
425 XS_MUTEX_LOCK(xs_stildb_db); | |
426 | |
427 /* Check if already initialized */ | |
428 if (xs_stildb_db) xs_stildb_free(xs_stildb_db); | |
429 | |
430 /* Allocate database */ | |
431 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); | |
432 if (!xs_stildb_db) | |
433 { | |
434 XS_MUTEX_UNLOCK(xs_cfg); | |
435 XS_MUTEX_UNLOCK(xs_stildb_db); | |
436 return -2; | |
437 } | |
438 | |
439 /* Read the database */ | |
440 if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) | |
441 { | |
442 xs_stildb_free(xs_stildb_db); | |
443 xs_stildb_db = NULL; | |
444 XS_MUTEX_UNLOCK(xs_cfg); | |
445 XS_MUTEX_UNLOCK(xs_stildb_db); | |
446 return -3; | |
447 } | |
448 | |
449 /* Create index */ | |
450 if (xs_stildb_index(xs_stildb_db) != 0) | |
451 { | |
452 xs_stildb_free(xs_stildb_db); | |
453 xs_stildb_db = NULL; | |
454 XS_MUTEX_UNLOCK(xs_cfg); | |
455 XS_MUTEX_UNLOCK(xs_stildb_db); | |
456 return -4; | |
457 } | |
458 | |
459 XS_MUTEX_UNLOCK(xs_cfg); | |
460 XS_MUTEX_UNLOCK(xs_stildb_db); | |
461 return 0; | |
462 } | |
463 | |
464 | |
465 void xs_stil_close(void) | |
466 { | |
467 XS_MUTEX_LOCK(xs_stildb_db); | |
468 xs_stildb_free(xs_stildb_db); | |
469 xs_stildb_db = NULL; | |
470 XS_MUTEX_UNLOCK(xs_stildb_db); | |
471 } | |
472 | |
473 | |
474 t_xs_stil_node * xs_stil_get(gchar *pcFilename) | |
475 { | |
476 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
|
477 gchar *tmpFilename; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
478 |
230 | 479 XS_MUTEX_LOCK(xs_stildb_db); |
480 XS_MUTEX_LOCK(xs_cfg); | |
481 | |
232
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
482 if (xs_cfg.stilDBEnable && xs_stildb_db) |
230 | 483 { |
232
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
484 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
|
485 { |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
486 /* 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
|
487 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
|
488 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
|
489 tmpFilename[0] = 0; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
490 |
232
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
491 /* 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
|
492 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
|
493 if (tmpFilename) |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
494 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
|
495 else |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
496 tmpFilename = pcFilename; |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
497 } else |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
498 tmpFilename = pcFilename; |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
499 |
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
500 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); |
230 | 501 } else |
232
e613873c3379
Thread locking now final. All parts, including GTK GUI, should be(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
502 pResult = NULL; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
503 |
230 | 504 XS_MUTEX_UNLOCK(xs_stildb_db); |
505 XS_MUTEX_UNLOCK(xs_cfg); | |
506 | |
507 return pResult; | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
508 } |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
509 |