Mercurial > hg > xmms-sid
annotate src/xs_length.c @ 1012:4a2b8517631d
Add one debug info line.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 25 Sep 2014 06:36:08 +0300 |
parents | 56368ab7d282 |
children |
rev | line source |
---|---|
4 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
332 | 4 Get song length from SLDB for PSID/RSID files |
4 | 5 |
324 | 6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
723 | 7 (C) Copyright 1999-2009 Tecnic Software productions (TNSP) |
4 | 8 |
9 This program is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
412
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
19 You should have received a copy of the GNU General Public License along |
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
20 with this program; if not, write to the Free Software Foundation, Inc., |
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
4 | 22 */ |
39 | 23 #include "xs_length.h" |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
24 #include "xs_support.h" |
4 | 25 |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
26 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
27 /* Free memory allocated for given SLDB node |
4 | 28 */ |
751 | 29 static void xs_sldb_node_free(XSSLDBNode *node) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
30 { |
909 | 31 if (node) |
32 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
33 g_free(node->lengths); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
34 g_free(node); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
35 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
36 } |
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 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
39 /* Insert given node to db linked list |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
40 */ |
751 | 41 static void xs_sldb_node_insert(XSSLDB *db, XSSLDBNode *node) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
42 { |
783 | 43 assert(db != NULL); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
44 |
909 | 45 if (db->nodes) |
46 { | |
783 | 47 node->prev = db->nodes->prev; |
782 | 48 db->nodes->prev->next = node; |
49 db->nodes->prev = node; | |
909 | 50 } |
51 else | |
52 { | |
782 | 53 db->nodes = node; |
783 | 54 node->prev = node; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
55 } |
783 | 56 node->next = NULL; |
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 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
60 /* Parse a time-entry in SLDB format |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
61 */ |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
62 static gint xs_sldb_gettime(gchar *str, size_t *pos) |
4 | 63 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
64 gint result, tmp; |
4 | 65 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
66 /* Check if it starts with a digit */ |
909 | 67 if (isdigit(str[*pos])) |
68 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
69 /* Get minutes-field */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
70 result = 0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
71 while (isdigit(str[*pos])) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
72 result = (result * 10) + (str[(*pos)++] - '0'); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
73 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
74 result *= 60; |
4 | 75 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
76 /* Check the field separator char */ |
909 | 77 if (str[*pos] == ':') |
78 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
79 /* Get seconds-field */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
80 (*pos)++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
81 tmp = 0; |
909 | 82 while (isdigit(str[*pos])) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
83 tmp = (tmp * 10) + (str[(*pos)++] - '0'); |
4 | 84 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
85 result += tmp; |
909 | 86 } |
87 else | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
88 result = -2; |
909 | 89 } |
90 else | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
91 result = -1; |
4 | 92 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
93 /* Ignore and skip the possible attributes */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
94 while (str[*pos] && !isspace(str[*pos])) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
95 (*pos)++; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
96 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
97 return result; |
4 | 98 } |
99 | |
100 | |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
101 /* Parse one SLDB definition line, return SLDB node |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
102 */ |
751 | 103 XSSLDBNode * xs_sldb_read_entry(gchar *inLine) |
389 | 104 { |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
105 XSSLDBNode *tmnode = NULL; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
106 size_t linePos, tmpLen, savePos; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
107 gboolean isOK; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
108 gint i; |
389 | 109 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
110 /* Allocate new node */ |
751 | 111 tmnode = (XSSLDBNode *) g_malloc0(sizeof(XSSLDBNode)); |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
112 if (tmnode == NULL) |
909 | 113 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
114 xs_error("Error allocating new node. Fatal error.\n"); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
115 return NULL; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
116 } |
389 | 117 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
118 /* Get hash value */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
119 linePos = 0; |
909 | 120 for (i = 0; i < XS_MD5HASH_LENGTH; i++, linePos += 2) |
121 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
122 gint tmpu; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
123 sscanf(&inLine[linePos], "%2x", &tmpu); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
124 tmnode->md5Hash[i] = tmpu; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
125 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
126 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
127 /* Get playtimes */ |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
128 xs_findnext(inLine, &linePos); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
129 if (inLine[linePos] != '=') |
909 | 130 { |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
131 xs_error("'=' expected on column #%d.\n", linePos); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
132 goto error; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
133 } |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
134 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
135 /* First playtime is after '=' */ |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
136 savePos = ++linePos; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
137 tmpLen = strlen(inLine); |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
138 |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
139 /* Get number of sub-tune lengths */ |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
140 isOK = TRUE; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
141 while (linePos < tmpLen && isOK) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
142 { |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
143 xs_findnext(inLine, &linePos); |
389 | 144 |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
145 if (xs_sldb_gettime(inLine, &linePos) >= 0) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
146 tmnode->nlengths++; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
147 else |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
148 isOK = FALSE; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
149 } |
389 | 150 |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
151 /* Allocate memory for lengths */ |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
152 if (tmnode->nlengths == 0) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
153 goto error; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
154 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
155 tmnode->lengths = (gint *) g_malloc0(tmnode->nlengths * sizeof(gint)); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
156 if (tmnode->lengths == NULL) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
157 { |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
158 xs_error("Could not allocate memory for node.\n"); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
159 goto error; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
160 } |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
161 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
162 /* Read lengths in */ |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
163 for (i = 0, linePos = savePos, isOK = TRUE; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
164 linePos < tmpLen && i < tmnode->nlengths && isOK; i++) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
165 { |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
166 gint l; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
167 xs_findnext(inLine, &linePos); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
168 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
169 l = xs_sldb_gettime(inLine, &linePos); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
170 if (l >= 0) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
171 tmnode->lengths[i] = l; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
172 else |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
173 isOK = FALSE; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
174 } |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
175 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
176 return tmnode; |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
177 |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
178 error: |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
179 xs_sldb_node_free(tmnode); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
180 return NULL; |
389 | 181 } |
182 | |
183 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
184 /* Read database to memory |
4 | 185 */ |
976 | 186 gint xs_sldb_read(XSSLDB *db, const gchar *filename) |
4 | 187 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
188 FILE *inFile; |
777
15f0c8e11338
Increase line buffer size in songlength database reader. Fixes problems with
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
189 gchar inLine[XS_BUF2_SIZE]; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
190 size_t lineNum; |
751 | 191 XSSLDBNode *tmnode; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
192 assert(db); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
193 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
194 /* Try to open the file */ |
976 | 195 if ((inFile = fopen(filename, "ra")) == NULL) |
909 | 196 { |
976 | 197 xs_error("Could not open SongLengthDB '%s'\n", filename); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
198 return -1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
199 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
200 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
201 /* Read and parse the data */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
202 lineNum = 0; |
4 | 203 |
909 | 204 while (fgets(inLine, XS_BUF2_SIZE, inFile) != NULL) |
205 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
206 size_t linePos = 0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
207 lineNum++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
208 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
209 xs_findnext(inLine, &linePos); |
4 | 210 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
211 /* Check if it is datafield */ |
909 | 212 if (isxdigit(inLine[linePos])) |
213 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
214 /* Check the length of the hash */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
215 gint hashLen; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
216 for (hashLen = 0; inLine[linePos] && isxdigit(inLine[linePos]); hashLen++, linePos++); |
389 | 217 |
909 | 218 if (hashLen != XS_MD5HASH_LENGTH_CH) |
219 { | |
778
54a7afbf251e
Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
777
diff
changeset
|
220 xs_error("Invalid MD5-hash in SongLengthDB file '%s' line #%d:\n%s\n", |
976 | 221 filename, lineNum, inLine); |
909 | 222 } |
223 else | |
224 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
225 /* Parse and add node to db */ |
909 | 226 if ((tmnode = xs_sldb_read_entry(inLine)) != NULL) |
227 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
228 xs_sldb_node_insert(db, tmnode); |
909 | 229 } |
230 else | |
231 { | |
778
54a7afbf251e
Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
777
diff
changeset
|
232 xs_error("Invalid entry in SongLengthDB file '%s' line #%d:\n%s\n", |
976 | 233 filename, lineNum, inLine); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
234 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
235 } |
909 | 236 } |
237 else | |
238 if (inLine[linePos] != ';' && inLine[linePos] != '[' && inLine[linePos] != 0) | |
239 { | |
778
54a7afbf251e
Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
777
diff
changeset
|
240 xs_error("Invalid line in SongLengthDB file '%s' line #%d:\n%s\n", |
976 | 241 filename, lineNum, inLine); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
242 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
243 } |
4 | 244 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
245 fclose(inFile); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
246 return 0; |
4 | 247 } |
248 | |
249 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
250 /* Compare two given MD5-hashes. |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
251 * Return: 0 if equal |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
252 * negative if testHash1 < testHash2 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
253 * positive if testHash1 > testHash2 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
254 */ |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
255 static gint xs_sldb_cmphash(xs_md5hash_t testHash1, xs_md5hash_t testHash2) |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
256 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
257 gint i, d; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
258 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
259 /* Compute difference of hashes */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
260 for (i = 0, d = 0; (i < XS_MD5HASH_LENGTH) && !d; i++) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
261 d = (testHash1[i] - testHash2[i]); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
262 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
263 return d; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
264 } |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
265 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
266 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
267 /* Compare two nodes |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
268 */ |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
269 static gint xs_sldb_cmp(const void *node1, const void *node2) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
270 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
271 /* We assume here that we never ever get NULL-pointers or similar */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
272 return xs_sldb_cmphash( |
751 | 273 (*(XSSLDBNode **) node1)->md5Hash, |
274 (*(XSSLDBNode **) node2)->md5Hash); | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
275 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
276 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
277 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
278 /* (Re)create index |
4 | 279 */ |
751 | 280 gint xs_sldb_index(XSSLDB * db) |
4 | 281 { |
909 | 282 XSSLDBNode *node; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
283 size_t i; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
284 assert(db); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
285 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
286 /* Free old index */ |
909 | 287 g_free(db->pindex); |
288 db->pindex = NULL; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
289 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
290 /* Get size of db */ |
909 | 291 for (node = db->nodes, db->n = 0; node != NULL; node = node->next) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
292 db->n++; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
293 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
294 /* Check number of nodes */ |
909 | 295 if (db->n > 0) |
296 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
297 /* Allocate memory for index-table */ |
751 | 298 db->pindex = (XSSLDBNode **) g_malloc(sizeof(XSSLDBNode *) * db->n); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
299 if (!db->pindex) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
300 return -1; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
301 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
302 /* Get node-pointers to table */ |
909 | 303 for (i = 0, node = db->nodes; node && i < db->n; node = node->next) |
304 db->pindex[i++] = node; | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
305 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
306 /* Sort the indexes */ |
751 | 307 qsort(db->pindex, db->n, sizeof(XSSLDBNode *), xs_sldb_cmp); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
308 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
309 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
310 return 0; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
311 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
312 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
313 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
314 /* Free a given song-length database |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
315 */ |
751 | 316 void xs_sldb_free(XSSLDB * db) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
317 { |
909 | 318 XSSLDBNode *node, *next; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
319 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
320 if (!db) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
321 return; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
322 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
323 /* Free the memory allocated for nodes */ |
909 | 324 node = db->nodes; |
325 while (node != NULL) | |
326 { | |
327 next = node->next; | |
328 xs_sldb_node_free(node); | |
329 node = next; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
330 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
331 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
332 db->nodes = NULL; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
333 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
334 /* Free memory allocated for index */ |
909 | 335 g_free(db->pindex); |
336 db->pindex = NULL; | |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
337 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
338 /* Free structure */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
339 db->n = 0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
340 g_free(db); |
4 | 341 } |
342 | |
343 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
344 /* Compute md5hash of given SID-file |
4 | 345 */ |
909 | 346 typedef struct |
347 { | |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
348 gchar magic[4]; /* "PSID" / "RSID" magic identifier */ |
951 | 349 guint16 version, /* Version number */ |
350 dataOffset, /* Start of actual c64 data in file */ | |
351 loadAddress, /* Loading address */ | |
352 initAddress, /* Initialization address */ | |
353 playAddress, /* Play one frame */ | |
354 nSongs, /* Number of subsongs */ | |
355 startSong; /* Default starting song */ | |
356 guint32 speed; /* Speed */ | |
357 gchar sidName[32]; /* Descriptive text-fields, ASCIIZ */ | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
358 gchar sidAuthor[32]; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
359 gchar sidCopyright[32]; |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
360 } psidv1_header_t; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
361 |
4 | 362 |
909 | 363 typedef struct |
364 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
365 guint16 flags; /* Flags */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
366 guint8 startPage, pageLength; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
367 guint16 reserved; |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
368 } psidv2_header_t; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
369 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
370 |
657
acaba070cf49
Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
371 static gint xs_get_sid_hash(const gchar *filename, xs_md5hash_t hash) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
372 { |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
373 XSFile *inFile = NULL; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
374 xs_md5state_t inState; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
375 psidv1_header_t psidH; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
376 psidv2_header_t psidH2; |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
377 guint8 *songData = NULL; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
378 guint8 ib8[2], i8; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
379 gint index, result; |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
380 gboolean isRSID; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
381 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
382 /* Try to open the file */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
383 if ((inFile = xs_fopen(filename, "rb")) == NULL) |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
384 goto error; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
385 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
386 /* Read PSID header in */ |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
387 if (!xs_fread_str(inFile, psidH.magic, sizeof(psidH.magic)) || |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
388 !xs_fread_be16(inFile, &psidH.version) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
389 !xs_fread_be16(inFile, &psidH.dataOffset) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
390 !xs_fread_be16(inFile, &psidH.loadAddress) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
391 !xs_fread_be16(inFile, &psidH.initAddress) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
392 !xs_fread_be16(inFile, &psidH.playAddress) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
393 !xs_fread_be16(inFile, &psidH.nSongs) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
394 !xs_fread_be16(inFile, &psidH.startSong) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
395 !xs_fread_be32(inFile, &psidH.speed)) |
909 | 396 { |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
397 xs_error("Could not read PSID/RSID header from '%s'\n", filename); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
398 goto error; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
399 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
400 |
972 | 401 if ((psidH.magic[0] != 'R' && psidH.magic[0] != 'P') || |
402 psidH.magic[1] != 'S' || psidH.magic[2] != 'I' || psidH.magic[3] != 'D' || | |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
403 psidH.version < 1 || psidH.version > 3) |
909 | 404 { |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
405 xs_error("Not a supported PSID or RSID file '%s'\n", filename); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
406 goto error; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
407 } |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
408 |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
409 isRSID = psidH.magic[0] == 'R'; |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
410 |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
411 if (!xs_fread_str(inFile, psidH.sidName, sizeof(psidH.sidName)) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
412 !xs_fread_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor)) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
413 !xs_fread_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright))) |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
414 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
415 xs_error("Error reading SID file header from '%s'\n", filename); |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
416 goto error; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
417 } |
970 | 418 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
419 /* Check if we need to load PSIDv2NG header ... */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
420 psidH2.flags = 0; /* Just silence a stupid gcc warning */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
421 |
972 | 422 if (psidH.version >= 2) |
909 | 423 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
424 /* Yes, we need to */ |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
425 if (!xs_fread_be16(inFile, &psidH2.flags) || |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
426 !xs_fread_byte(inFile, &psidH2.startPage) || |
969
b9e6f929a617
Fix a silly, but meaningless bug in reading PSIDv2/3 extra header (the value
Matti Hamalainen <ccr@tnsp.org>
parents:
968
diff
changeset
|
427 !xs_fread_byte(inFile, &psidH2.pageLength) || |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
428 !xs_fread_be16(inFile, &psidH2.reserved)) |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
429 { |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
430 xs_error("Error reading PSID/RSID v2+ extra header data from '%s'\n", |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
431 filename); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
432 goto error; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
433 } |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
434 } |
385 | 435 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
436 /* Allocate buffer */ |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
437 if ((songData = (guint8 *) g_malloc(XS_SIDBUF_SIZE)) == NULL) |
909 | 438 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
439 xs_error("Error allocating temp data buffer for file '%s'\n", filename); |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
440 goto error; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
441 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
442 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
443 /* Read data to buffer */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
444 result = xs_fread(songData, sizeof(guint8), XS_SIDBUF_SIZE, inFile); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
445 xs_fclose(inFile); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
446 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
447 /* Initialize and start MD5-hash calculation */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
448 xs_md5_init(&inState); |
385 | 449 |
909 | 450 if (psidH.loadAddress == 0) |
451 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
452 /* Strip load address (2 first bytes) */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
453 xs_md5_append(&inState, &songData[2], result - 2); |
909 | 454 } |
455 else | |
456 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
457 /* Append "as is" */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
458 xs_md5_append(&inState, songData, result); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
459 } |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
460 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
461 /* Free buffer */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
462 g_free(songData); |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
463 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
464 /* Append header data to hash */ |
909 | 465 #define XSADDHASH(QDATAB) do { \ |
970 | 466 ib8[0] = (QDATAB & 0xff); \ |
467 ib8[1] = (QDATAB >> 8); \ | |
468 xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); \ | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
469 } while (0) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
470 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
471 XSADDHASH(psidH.initAddress); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
472 XSADDHASH(psidH.playAddress); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
473 XSADDHASH(psidH.nSongs); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
474 #undef XSADDHASH |
385 | 475 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
476 /* Append song speed data to hash */ |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
477 i8 = isRSID ? 60 : 0; |
909 | 478 for (index = 0; index < psidH.nSongs && index < 32; index++) |
479 { | |
968
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
480 if (isRSID) |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
481 i8 = 60; |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
482 else |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
483 i8 = (psidH.speed & (1 << index)) ? 60 : 0; |
5e0a05c84694
Fix RSID MD5 hash calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
484 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
485 xs_md5_append(&inState, &i8, sizeof(i8)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
486 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
487 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
488 /* Rest of songs (more than 32) */ |
909 | 489 for (index = 32; index < psidH.nSongs; index++) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
490 xs_md5_append(&inState, &i8, sizeof(i8)); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
491 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
492 /* PSIDv2NG specific */ |
972 | 493 if (psidH.version >= 2) |
909 | 494 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
495 /* SEE SIDPLAY HEADERS FOR INFO */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
496 i8 = (psidH2.flags >> 2) & 3; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
497 if (i8 == 2) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
498 xs_md5_append(&inState, &i8, sizeof(i8)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
499 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
500 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
501 /* Calculate the hash */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
502 xs_md5_finish(&inState, hash); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
503 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
504 return 0; |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
505 |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
506 error: |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
507 if (inFile != NULL) |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
508 xs_fclose(inFile); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
509 g_free(songData); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
951
diff
changeset
|
510 return -1; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
511 } |
4 | 512 |
513 | |
509
81756f412b43
Changes based on patch from Heikki 'shd' Orsila: Fix a crash on 64-bit
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
514 /* Get node from db index via binary search |
4 | 515 */ |
751 | 516 XSSLDBNode *xs_sldb_get(XSSLDB *db, const gchar *filename) |
4 | 517 { |
751 | 518 XSSLDBNode keyItem, *key, **item; |
509
81756f412b43
Changes based on patch from Heikki 'shd' Orsila: Fix a crash on 64-bit
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
519 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
520 /* Check the database pointers */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
521 if (!db || !db->nodes || !db->pindex) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
522 return NULL; |
4 | 523 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
524 /* Get the hash and then look up from db */ |
909 | 525 if (xs_get_sid_hash(filename, keyItem.md5Hash) == 0) |
526 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
527 key = &keyItem; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
528 item = bsearch(&key, db->pindex, db->n, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
529 sizeof(db->pindex[0]), xs_sldb_cmp); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
530 |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
531 if (item == NULL) |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
532 { |
923
86f914bb48a7
Oops, filename variable argument to xs_error() was missing, printing garbage
Matti Hamalainen <ccr@tnsp.org>
parents:
920
diff
changeset
|
533 xs_error("No matching hash in SLDB: %s\n", filename); |
971
3edc4c508f99
Use the generic MD5 hash printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
970
diff
changeset
|
534 xs_md5_print(stderr, keyItem.md5Hash); |
920
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
535 fprintf(stderr, "\n"); |
560cdf7f1fec
Fix a silly bug in the SLDB parser caused by recent changes. Cleaned up the
Matti Hamalainen <ccr@tnsp.org>
parents:
909
diff
changeset
|
536 } |
909 | 537 return (item != NULL) ? *item : NULL; |
538 } | |
539 else | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
540 return NULL; |
509
81756f412b43
Changes based on patch from Heikki 'shd' Orsila: Fix a crash on 64-bit
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
541 } |