Mercurial > hg > xmms-sid
annotate src/xs_length.c @ 223:16e3b2446a73
On some systems stdlib.h has prerequisite of stdio.h, corrected order of
inclusion on some files to prevent problems.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 15 Dec 2004 14:18:00 +0000 |
parents | 002e314712c4 |
children | 92bad4c7b998 |
rev | line source |
---|---|
4 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Get song length (from database or by other means) | |
5 | |
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org> | |
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 */ | |
39 | 22 #include "xs_length.h" |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
23 #include "xs_support.h" |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
24 #include "xs_config.h" |
223
16e3b2446a73
On some systems stdlib.h has prerequisite of stdio.h, corrected order of
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
25 #include <stdio.h> |
4 | 26 #include <stdlib.h> |
27 #include <ctype.h> | |
28 #include <string.h> | |
29 | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
30 |
4 | 31 /* |
32 * Pointer to database in memory | |
33 */ | |
96 | 34 static t_xs_sldb_node *xs_sldb = NULL; |
35 static t_xs_sldb_node **xs_sldbi = NULL; | |
36 static gint xs_sldbn = 0; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
37 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
38 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
39 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
40 * Hash-database handling functions |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
41 */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
42 t_xs_sldb_node *xs_sldb_node_new(void) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
43 { |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
44 t_xs_sldb_node *pResult; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
45 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
46 /* Allocate memory for new node */ |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
47 pResult = (t_xs_sldb_node *) g_malloc0(sizeof(t_xs_sldb_node)); |
86 | 48 if (!pResult) return NULL; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
49 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
50 return pResult; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
51 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
52 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
53 |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
54 void xs_sldb_node_free(t_xs_sldb_node *pNode) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
55 { |
86 | 56 if (pNode) g_free(pNode); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
57 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
58 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
59 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
60 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
61 * Insert given node to db linked list |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
62 */ |
86 | 63 #define LPREV (pNode->pPrev) |
64 #define LTHIS (pNode) | |
65 #define LNEXT (pNode->pNext) | |
66 | |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
67 void xs_sldb_node_insert(t_xs_sldb_node *pNode) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
68 { |
96 | 69 if (xs_sldb) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
70 { |
86 | 71 /* The first node's pPrev points to last node */ |
96 | 72 LPREV = xs_sldb->pPrev; /* New node's prev = Previous last node */ |
73 xs_sldb->pPrev->pNext = pNode; /* Previous last node's next = New node */ | |
74 xs_sldb->pPrev = pNode; /* New last node = New node */ | |
86 | 75 LNEXT = NULL; /* But next is NULL! */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
76 } else { |
96 | 77 xs_sldb = pNode; /* First node ... */ |
86 | 78 LPREV = pNode; /* ... it's also last */ |
79 LNEXT = NULL; /* But next is NULL! */ | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
80 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
81 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
82 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
83 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
84 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
85 * Compare two given MD5-hashes. |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
86 * Return: 0 if equal |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
87 * negative if testHash1 < testHash2 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
88 * positive if testHash1 > testHash2 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
89 */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
90 gint xs_sldb_cmphash(t_xs_md5hash testHash1, t_xs_md5hash testHash2) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
91 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
92 register gint i, res = 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
93 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
94 /* Compute difference of hashes */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
95 for (i = 0; (i < XS_MD5HASH_LENGTH) && (!res); i++) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
96 res = (testHash1[i] - testHash2[i]); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
97 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
98 return res; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
99 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
100 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
101 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
102 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
103 * Get song length from database |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
104 */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
105 t_xs_sldb_node * xs_sldb_get(t_xs_md5hash pHash) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
106 { |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
107 gint iStartNode, iEndNode, iQNode, r, i; |
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
108 gboolean iFound; |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
109 t_xs_sldb_node *pResult; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
110 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
111 /* Check the database pointers */ |
96 | 112 if (!xs_sldb || !xs_sldbi) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
113 return NULL; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
114 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
115 /* Look-up via index using binary search */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
116 pResult = NULL; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
117 iStartNode = 0; |
96 | 118 iEndNode = (xs_sldbn - 1); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
119 iQNode = (iEndNode / 2); |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
120 iFound = FALSE; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
121 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
122 while ((!iFound) && ((iEndNode - iStartNode) > 128)) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
123 { |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
124 r = xs_sldb_cmphash(pHash, xs_sldbi[iQNode]->md5Hash); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
125 if (r < 0) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
126 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
127 /* Hash was in the <- LEFT side */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
128 iEndNode = iQNode; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
129 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
130 } else |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
131 if (r > 0) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
132 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
133 /* Hash was in the RIGHT -> side */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
134 iStartNode = iQNode; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
135 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
136 } else |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
137 iFound = TRUE; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
138 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
139 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
140 /* If not found already */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
141 if (!iFound) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
142 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
143 /* Search the are linearly */ |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
144 iFound = FALSE; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
145 i = iStartNode; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
146 while ((i <= iEndNode) && (!iFound)) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
147 { |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
148 if (xs_sldb_cmphash(pHash, xs_sldbi[i]->md5Hash) == 0) |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
149 iFound = TRUE; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
150 else |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
151 i++; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
152 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
153 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
154 /* Check the result */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
155 if (iFound) |
96 | 156 pResult = xs_sldbi[i]; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
157 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
158 } else { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
159 /* Found via binary search */ |
96 | 160 pResult = xs_sldbi[iQNode]; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
161 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
162 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
163 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
164 return pResult; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
165 } |
4 | 166 |
167 | |
168 /* | |
169 * Parses a time-entry in SLDB format | |
170 */ | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
171 gint32 xs_gettime(gchar *pcStr, int *piPos) |
4 | 172 { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
173 gint32 iResult, iTemp; |
4 | 174 |
175 /* Check if it starts with a digit */ | |
176 if (isdigit(pcStr[*piPos])) | |
177 { | |
178 /* Get minutes-field */ | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
179 iResult = 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
180 while (isdigit(pcStr[*piPos])) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
181 iResult = (iResult * 10) + (pcStr[(*piPos)++] - '0'); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
182 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
183 iResult *= 60; |
4 | 184 |
185 /* Check the field separator char */ | |
186 if (pcStr[*piPos] == ':') | |
187 { | |
188 /* Get seconds-field */ | |
189 (*piPos)++; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
190 iTemp = 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
191 while (isdigit(pcStr[*piPos])) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
192 iTemp = (iTemp * 10) + (pcStr[(*piPos)++] - '0'); |
4 | 193 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
194 iResult += iTemp; |
4 | 195 } else |
196 iResult = -2; | |
197 } else | |
198 iResult = -1; | |
199 | |
200 /* Ignore and skip the possible attributes */ | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
201 while (pcStr[*piPos] && !isspace(pcStr[*piPos])) (*piPos)++; |
4 | 202 |
203 return iResult; | |
204 } | |
205 | |
206 | |
207 /* | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
208 * Read database to memory |
4 | 209 */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
210 gint xs_sldb_read(gchar *dbFilename) |
4 | 211 { |
212 FILE *inFile; | |
24 | 213 gchar inLine[XS_BUFSIZE]; |
57
85811bcd049e
Improved, re-written configuration code and lots of minor fixes
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
214 guint lineNum, linePos; |
85811bcd049e
Improved, re-written configuration code and lots of minor fixes
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
215 gboolean iOK; |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
216 t_xs_sldb_node *tmpNode; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
217 |
4 | 218 /* Try to open the file */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
219 if ((inFile = fopen(dbFilename, "ra")) == NULL) |
4 | 220 { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
221 XSERR("Could not open SongLengthDB '%s'\n", dbFilename); |
4 | 222 return -1; |
223 } | |
224 | |
225 /* Read and parse the data */ | |
226 lineNum = 0; | |
227 | |
228 while (!feof(inFile)) | |
229 { | |
230 fgets(inLine, sizeof(inLine), inFile); | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
231 lineNum++; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
232 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
233 /* Check if it is datafield */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
234 if (isxdigit(inLine[0])) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
235 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
236 /* Check the length of the hash */ |
4 | 237 linePos = 0; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
238 while (isxdigit(inLine[linePos])) linePos++; |
4 | 239 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
240 if (linePos != XS_MD5HASH_LENGTH_CH) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
241 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
242 XSERR("Invalid hash in SongLengthDB file '%s' line #%d!\n", |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
243 dbFilename, lineNum); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
244 } else { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
245 /* Allocate new node */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
246 if ((tmpNode = xs_sldb_node_new()) == NULL) |
4 | 247 { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
248 XSERR("Error allocating new node. Fatal error.\n"); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
249 exit(5); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
250 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
251 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
252 /* Get hash value */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
253 #if (XS_MD5HASH_LENGTH != 16) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
254 #error Mismatch in hashcode length. Fix here. |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
255 #endif |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
256 sscanf(&inLine[0], "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
257 (guint *) &(tmpNode->md5Hash[0]), (guint *) &(tmpNode->md5Hash[1]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
258 (guint *) &(tmpNode->md5Hash[2]), (guint *) &(tmpNode->md5Hash[3]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
259 (guint *) &(tmpNode->md5Hash[4]), (guint *) &(tmpNode->md5Hash[5]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
260 (guint *) &(tmpNode->md5Hash[6]), (guint *) &(tmpNode->md5Hash[7]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
261 (guint *) &(tmpNode->md5Hash[8]), (guint *) &(tmpNode->md5Hash[9]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
262 (guint *) &(tmpNode->md5Hash[10]), (guint *) &(tmpNode->md5Hash[11]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
263 (guint *) &(tmpNode->md5Hash[12]), (guint *) &(tmpNode->md5Hash[13]), |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
264 (guint *) &(tmpNode->md5Hash[14]), (guint *) &(tmpNode->md5Hash[15])); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
265 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
266 /* Get playtimes */ |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
267 if (inLine[linePos] != 0) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
268 { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
269 if (inLine[linePos] != '=') |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
270 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
271 XSERR("'=' expected in SongLengthDB file '%s' line #%d, column #%d\n", |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
272 dbFilename, lineNum, linePos); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
273 |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
274 xs_sldb_node_free(tmpNode); |
4 | 275 } else { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
276 /* First playtime is after '=' */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
277 linePos++; |
57
85811bcd049e
Improved, re-written configuration code and lots of minor fixes
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
278 iOK = TRUE; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
279 |
57
85811bcd049e
Improved, re-written configuration code and lots of minor fixes
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
280 while ((linePos < strlen(inLine)) && iOK) |
4 | 281 { |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
282 xs_findnext(inLine, &linePos); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
283 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
284 if (tmpNode->nLengths < XS_STIL_MAXENTRY) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
285 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
286 tmpNode->sLengths[tmpNode->nLengths] = |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
287 xs_gettime(inLine, &linePos); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
288 tmpNode->nLengths++; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
289 } else |
57
85811bcd049e
Improved, re-written configuration code and lots of minor fixes
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
290 iOK = FALSE; |
4 | 291 } |
292 | |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
293 /* Add an node to db in memory */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
294 if (iOK) |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
295 xs_sldb_node_insert(tmpNode); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
296 else |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
297 xs_sldb_node_free(tmpNode); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
298 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
299 } |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
300 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
301 } else |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
302 if ((inLine[0] != ';') && (inLine[0] != '[')) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
303 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
304 XSERR("Invalid line in SongLengthDB file '%s' line #%d\n", |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
305 dbFilename, lineNum); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
306 } |
4 | 307 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
308 } /* while */ |
4 | 309 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
310 /* Close the file */ |
4 | 311 fclose(inFile); |
312 | |
313 return 0; | |
314 } | |
315 | |
316 | |
317 /* | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
318 * Compare two nodes' hashes |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
319 */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
320 gint xs_sldb_cmp(const void *pNode1, const void *pNode2) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
321 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
322 /* 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:
96
diff
changeset
|
323 return xs_sldb_cmphash((*(t_xs_sldb_node **) pNode1)->md5Hash, |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
324 (*(t_xs_sldb_node **) pNode2)->md5Hash); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
325 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
326 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
327 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
328 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
329 * Initialize the song-length system |
4 | 330 */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
331 gint xs_songlen_init(void) |
4 | 332 { |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
333 t_xs_sldb_node *pCurr; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
334 gint i; |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
335 |
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
336 XSDEBUG("sldb_init()\n"); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
337 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
338 /* Read the database */ |
86 | 339 if (!xs_cfg.songlenDBPath) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
340 return -10; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
341 |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
342 if (xs_sldb_read(xs_cfg.songlenDBPath) < 0) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
343 return -9; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
344 |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
345 XSDEBUG("indexing...\n"); |
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
346 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
347 /* Get size of db */ |
96 | 348 pCurr = xs_sldb; |
349 xs_sldbn = 0; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
350 while (pCurr) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
351 { |
96 | 352 xs_sldbn++; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
353 pCurr = pCurr->pNext; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
354 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
355 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
356 /* Check number of nodes */ |
96 | 357 if (xs_sldbn > 0) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
358 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
359 /* Allocate memory for index-table */ |
96 | 360 xs_sldbi = (t_xs_sldb_node **) g_malloc(sizeof(t_xs_sldb_node *) * xs_sldbn); |
361 if (!xs_sldbi) return -6; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
362 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
363 /* Get node-pointers to table */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
364 i = 0; |
96 | 365 pCurr = xs_sldb; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
366 while (pCurr) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
367 { |
96 | 368 xs_sldbi[i++] = pCurr; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
369 pCurr = pCurr->pNext; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
370 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
371 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
372 /* Sort the indexes */ |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
373 qsort(xs_sldbi, xs_sldbn, sizeof(t_xs_sldb_node *), xs_sldb_cmp); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
374 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
375 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
376 /* OK */ |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
377 XSDEBUG("init ok.\n"); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
378 return 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
379 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
380 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
381 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
382 /* |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
383 * Close song-length system |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
384 */ |
22 | 385 void xs_songlen_close(void) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
386 { |
62
0d1df20745dd
Started to rewrite STIL-support
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
387 t_xs_sldb_node *pCurr, *pNext; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
388 |
4 | 389 /* Free the memory allocated for database */ |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
390 XSDEBUG("sldb_close()\n"); |
96 | 391 pCurr = xs_sldb; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
392 while (pCurr) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
393 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
394 pNext = pCurr->pNext; |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
395 xs_sldb_node_free(pCurr); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
396 pCurr = pNext; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
397 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
398 |
96 | 399 xs_sldb = NULL; |
86 | 400 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
401 /* Free memory allocated for indexes */ |
96 | 402 if (xs_sldbi) |
86 | 403 { |
96 | 404 g_free(xs_sldbi); |
405 xs_sldbi = NULL; | |
86 | 406 } |
4 | 407 } |
408 | |
409 | |
410 /* | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
411 * Compute md5hash of given SID-file |
4 | 412 */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
413 typedef struct { |
86 | 414 gchar magicID[4]; /* "PSID" magic identifier */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
415 guint16 version, /* Version number */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
416 dataOffset, /* Start of actual c64 data in file */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
417 loadAddress, /* Loading address */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
418 initAddress, /* Initialization address */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
419 playAddress, /* Play one frame */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
420 nSongs, /* Number of subsongs */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
421 startSong; /* Default starting song */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
422 guint32 speed; /* Speed */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
423 gchar sidName[32]; /* Descriptive text-fields, ASCIIZ */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
424 gchar sidAuthor[32]; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
425 gchar sidCopyright[32]; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
426 } t_xs_psidv1_header; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
427 |
4 | 428 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
429 typedef struct { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
430 guint16 flags; /* Flags */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
431 guint8 startPage, |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
432 pageLength; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
433 guint16 reserved; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
434 } t_xs_psidv2_header; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
435 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
436 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
437 guint16 rd_be16(FILE *f) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
438 { |
92
2607683bc9eb
Improvements in length- and title handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
439 return (((guint16) fgetc(f)) << 8) | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
440 ((guint16) fgetc(f)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
441 } |
4 | 442 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
443 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
444 guint32 rd_be32(FILE *f) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
445 { |
92
2607683bc9eb
Improvements in length- and title handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
446 return (((guint32) fgetc(f)) << 24) | |
2607683bc9eb
Improvements in length- and title handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
447 (((guint32) fgetc(f)) << 16) | |
2607683bc9eb
Improvements in length- and title handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
448 (((guint32) fgetc(f)) << 8) | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
449 ((guint32) fgetc(f)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
450 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
451 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
452 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
453 gint rd_str(FILE *f, gchar *s, gint l) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
454 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
455 return fread(s, sizeof(gchar), l, f); |
4 | 456 } |
457 | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
458 #define MAX_MEMBUF (80*1024) |
4 | 459 |
86 | 460 gint xs_get_sid_hash(gchar *pcFilename, t_xs_md5hash hash) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
461 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
462 FILE *inFile; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
463 t_xs_md5state inState; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
464 t_xs_psidv1_header psidH; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
465 t_xs_psidv2_header psidH2; |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
466 guint8 songData[MAX_MEMBUF+1], ib8[2], i8; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
467 gint iIndex, iRes; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
468 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
469 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
470 /* Try to open the file */ |
86 | 471 if ((inFile = fopen(pcFilename, "rb")) == NULL) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
472 return -1; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
473 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
474 /* Read PSID header in */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
475 rd_str(inFile, psidH.magicID, sizeof(psidH.magicID)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
476 if ((psidH.magicID[0] != 'P') || (psidH.magicID[1] != 'S') || |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
477 (psidH.magicID[2] != 'I') || (psidH.magicID[3] != 'D')) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
478 return -2; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
479 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
480 psidH.version = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
481 psidH.dataOffset = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
482 psidH.loadAddress = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
483 psidH.initAddress = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
484 psidH.playAddress = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
485 psidH.nSongs = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
486 psidH.startSong = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
487 psidH.speed = rd_be32(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
488 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
489 rd_str(inFile, psidH.sidName, sizeof(psidH.sidName)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
490 rd_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
491 rd_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
492 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
493 /* Check if we need to load PSIDv2NG header ... */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
494 if (psidH.version == 2) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
495 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
496 /* Yes, we need to */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
497 psidH2.flags = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
498 psidH2.startPage = fgetc(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
499 psidH2.pageLength = fgetc(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
500 psidH2.reserved = rd_be16(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
501 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
502 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
503 /* Read data to buffer */ |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
504 iRes = fread(songData, sizeof(guint8), MAX_MEMBUF, inFile); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
505 fclose(inFile); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
506 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
507 /* Initialize and start MD5-hash calculation */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
508 xs_md5_init(&inState); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
509 if (psidH.loadAddress == 0) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
510 /* COULD SOMEONE EXPLAIN WHY DO WE NEED THIS +2 STRIP???? */ |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
511 xs_md5_append(&inState, &songData[2], iRes-2); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
512 else |
178
002e314712c4
Fixed a serious bug in MD5-hashing of file: &databuffer was given (pointer
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
513 xs_md5_append(&inState, songData, iRes); |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
514 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
515 /* Append header data to hash */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
516 #define XSADDHASH(QDATAB) { ib8[0] = (QDATAB & 0xff); ib8[1] = (QDATAB >> 8); xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
517 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
518 XSADDHASH(psidH.initAddress) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
519 XSADDHASH(psidH.playAddress) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
520 XSADDHASH(psidH.nSongs) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
521 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
522 #undef XSADDHASH |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
523 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
524 /* Append song speed data to hash */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
525 i8 = 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
526 for (iIndex = 0; (iIndex < psidH.nSongs) && (iIndex < 32); iIndex++) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
527 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
528 i8 = (psidH.speed & (1 << iIndex)) ? 60 : 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
529 xs_md5_append(&inState, &i8, sizeof(i8)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
530 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
531 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
532 /* Rest of songs (more than 32) */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
533 for (iIndex = 32; iIndex < psidH.nSongs; iIndex++) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
534 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
535 xs_md5_append(&inState, &i8, sizeof(i8)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
536 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
537 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
538 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
539 /* PSIDv2NG specific */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
540 if (psidH.version == 2) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
541 { |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
542 /* SEE SIDPLAY HEADERS FOR INFO */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
543 i8 = (psidH2.flags >> 2) & 3; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
544 if (i8 == 2) |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
545 xs_md5_append(&inState, &i8, sizeof(i8)); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
546 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
547 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
548 /* Calculate the hash */ |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
549 xs_md5_finish(&inState, hash); |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
550 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
551 return 0; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
552 } |
4 | 553 |
554 | |
555 /* | |
86 | 556 * Get song lengths |
4 | 557 */ |
86 | 558 t_xs_sldb_node * xs_songlen_get(gchar *pcFilename) |
4 | 559 { |
86 | 560 t_xs_sldb_node *pResult; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
561 t_xs_md5hash dbHash; |
4 | 562 |
86 | 563 pResult = NULL; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
564 |
39 | 565 if (xs_cfg.songlenDBEnable) |
566 { | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
567 /* Get the hash and then look up from db */ |
86 | 568 if (xs_get_sid_hash(pcFilename, dbHash) == 0) |
4 | 569 { |
99
2bc56809ec0b
STIL-support fixes, variable renaming
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
570 pResult = xs_sldb_get(dbHash); |
86 | 571 } |
39 | 572 } |
65
bf7b647b3239
The fabled 0.8-rewrite now works to some extent
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
573 |
86 | 574 return pResult; |
4 | 575 } |