Mercurial > hg > xmms-sid
annotate src/xs_length.c @ 476:c67a7f2fd586
Moved the glue functions to xmms-sid.c
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 26 Jan 2007 12:52:05 +0000 |
parents | 3f02945a0c48 |
children | 81756f412b43 |
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> |
422 | 7 (C) Copyright 1999-2007 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" |
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 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
31 /* Free memory allocated for given SLDB node |
4 | 32 */ |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
33 static 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
|
34 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
35 if (pNode) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
36 /* Nothing much to do here ... */ |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
37 g_free(pNode->sLengths); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
38 g_free(pNode); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
39 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
40 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
41 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
42 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
43 /* 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
|
44 */ |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
45 static void xs_sldb_node_insert(t_xs_sldb *db, t_xs_sldb_node *pNode) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
46 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
47 assert(db); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
48 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
49 if (db->pNodes) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
50 /* The first node's pPrev points to last node */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
51 LPREV = db->pNodes->pPrev; /* New node's prev = Previous last node */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
52 db->pNodes->pPrev->pNext = pNode; /* Previous last node's next = New node */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
53 db->pNodes->pPrev = pNode; /* New last node = New node */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
54 LNEXT = NULL; /* But next is NULL! */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
55 } else { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
56 db->pNodes = pNode; /* First node ... */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
57 LPREV = pNode; /* ... it's also last */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
58 LNEXT = NULL; /* But next is NULL! */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
59 } |
14
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 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
62 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
63 /* 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
|
64 */ |
449 | 65 static gint xs_sldb_gettime(gchar *pcStr, size_t *piPos) |
4 | 66 { |
389 | 67 gint iResult, iTemp; |
4 | 68 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
69 /* Check if it starts with a digit */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
70 if (isdigit(pcStr[*piPos])) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
71 /* Get minutes-field */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
72 iResult = 0; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
73 while (isdigit(pcStr[*piPos])) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
74 iResult = (iResult * 10) + (pcStr[(*piPos)++] - '0'); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
75 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
76 iResult *= 60; |
4 | 77 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
78 /* Check the field separator char */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
79 if (pcStr[*piPos] == ':') { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
80 /* Get seconds-field */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
81 (*piPos)++; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
82 iTemp = 0; |
385 | 83 while (isdigit(pcStr[*piPos])) { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
84 iTemp = (iTemp * 10) + (pcStr[(*piPos)++] - '0'); |
385 | 85 } |
4 | 86 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
87 iResult += iTemp; |
4 | 88 } else |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
89 iResult = -2; |
4 | 90 } else |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
91 iResult = -1; |
4 | 92 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
93 /* Ignore and skip the possible attributes */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
94 while (pcStr[*piPos] && !isspace(pcStr[*piPos])) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
95 (*piPos)++; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
96 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
97 return iResult; |
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 */ |
389 | 103 t_xs_sldb_node * xs_sldb_read_entry(gchar *inLine) |
104 { | |
449 | 105 size_t linePos; |
106 gint i; | |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
107 gboolean iOK; |
389 | 108 t_xs_sldb_node *tmpNode; |
109 | |
110 /* Allocate new node */ | |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
111 tmpNode = (t_xs_sldb_node *) g_malloc0(sizeof(t_xs_sldb_node)); |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
112 if (!tmpNode) { |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
113 xs_error(_("Error allocating new node. Fatal error.\n")); |
389 | 114 return NULL; |
115 } | |
116 | |
117 /* Get hash value */ | |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
118 linePos = 0; |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
119 for (i = 0; i < XS_MD5HASH_LENGTH; i++, linePos += 2) { |
419
bf4664ed897d
sscanf() was used in unaligned access, causing problems on Sparc (and
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
120 gint tmpu; |
bf4664ed897d
sscanf() was used in unaligned access, causing problems on Sparc (and
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
121 sscanf(&inLine[linePos], "%2x", &tmpu); |
bf4664ed897d
sscanf() was used in unaligned access, causing problems on Sparc (and
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
122 tmpNode->md5Hash[i] = tmpu; |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
123 } |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
124 |
389 | 125 /* Get playtimes */ |
126 if (inLine[linePos] != 0) { | |
127 if (inLine[linePos] != '=') { | |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
128 xs_error(_("'=' expected on column #%d.\n"), linePos); |
389 | 129 xs_sldb_node_free(tmpNode); |
130 return NULL; | |
131 } else { | |
449 | 132 size_t tmpLen, savePos; |
133 | |
389 | 134 /* First playtime is after '=' */ |
135 savePos = ++linePos; | |
136 tmpLen = strlen(inLine); | |
137 | |
138 /* Get number of sub-tune lengths */ | |
139 iOK = TRUE; | |
140 while ((linePos < tmpLen) && iOK) { | |
141 xs_findnext(inLine, &linePos); | |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
142 |
389 | 143 if (xs_sldb_gettime(inLine, &linePos) >= 0) |
144 tmpNode->nLengths++; | |
145 else | |
146 iOK = FALSE; | |
147 } | |
148 | |
149 /* Allocate memory for lengths */ | |
472 | 150 if (tmpNode->nLengths > 0) { |
151 tmpNode->sLengths = (gint *) g_malloc0(tmpNode->nLengths * sizeof(gint)); | |
152 if (!tmpNode->sLengths) { | |
153 xs_error(_("Could not allocate memory for node.\n")); | |
154 xs_sldb_node_free(tmpNode); | |
155 return NULL; | |
156 } | |
157 } else { | |
389 | 158 xs_sldb_node_free(tmpNode); |
159 return NULL; | |
160 } | |
161 | |
162 /* Read lengths in */ | |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
163 i = 0; |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
164 linePos = savePos; |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
165 iOK = TRUE; |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
166 while ((linePos < tmpLen) && (i < tmpNode->nLengths) && iOK) { |
449 | 167 gint l; |
168 | |
389 | 169 xs_findnext(inLine, &linePos); |
170 | |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
171 l = xs_sldb_gettime(inLine, &linePos); |
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
172 if (l >= 0) |
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
173 tmpNode->sLengths[i] = l; |
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
174 else |
389 | 175 iOK = FALSE; |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
176 |
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
177 i++; |
389 | 178 } |
179 | |
180 if (!iOK) { | |
181 xs_sldb_node_free(tmpNode); | |
182 return NULL; | |
183 } else | |
184 return tmpNode; | |
185 } | |
186 } | |
187 | |
188 return NULL; | |
189 } | |
190 | |
191 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
192 /* Read database to memory |
4 | 193 */ |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
194 gint xs_sldb_read(t_xs_sldb *db, const gchar *dbFilename) |
4 | 195 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
196 FILE *inFile; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
197 gchar inLine[XS_BUF_SIZE]; |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
198 size_t lineNum; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
199 t_xs_sldb_node *tmpNode; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
200 assert(db); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
201 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
202 /* Try to open the file */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
203 if ((inFile = fopen(dbFilename, "ra")) == NULL) { |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
204 xs_error(_("Could not open SongLengthDB '%s'\n"), dbFilename); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
205 return -1; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
206 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
207 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
208 /* Read and parse the data */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
209 lineNum = 0; |
4 | 210 |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
211 while (!feof(inFile) && fgets(inLine, XS_BUF_SIZE, inFile)) { |
449 | 212 size_t linePos; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
213 inLine[XS_BUF_SIZE - 1] = 0; |
389 | 214 linePos = 0; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
215 lineNum++; |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
216 |
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
217 xs_findnext(inLine, &linePos); |
4 | 218 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
219 /* Check if it is datafield */ |
389 | 220 if (isxdigit(inLine[linePos])) { |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
221 /* Check the length of the hash */ |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
222 gint hashLen; |
418
226627246616
Another fix for the fix, which was invalid. :P
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
223 for (hashLen = 0; inLine[linePos] && isxdigit(inLine[linePos]); hashLen++, linePos++); |
389 | 224 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
225 if (hashLen != XS_MD5HASH_LENGTH_CH) { |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
226 xs_error(_("Invalid MD5-hash in SongLengthDB file '%s' line #%d!\n"), |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
227 dbFilename, lineNum); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
228 } else { |
389 | 229 /* Parse and add node to db */ |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
230 if ((tmpNode = xs_sldb_read_entry(inLine)) != NULL) { |
389 | 231 xs_sldb_node_insert(db, tmpNode); |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
232 } else { |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
233 xs_error(_("Invalid entry in SongLengthDB file '%s' line #%d!\n"), |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
234 dbFilename, lineNum); |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
235 } |
4 | 236 } |
424
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
237 } else if ((inLine[linePos] != ';') && (inLine[linePos] != '[') && (inLine[linePos] != 0)) { |
faf12767a6f1
Preparing for internationalization.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
238 xs_error(_("Invalid line in SongLengthDB file '%s' line #%d\n"), |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
239 dbFilename, lineNum); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
240 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
241 |
389 | 242 } |
4 | 243 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
244 /* Close the file */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
245 fclose(inFile); |
4 | 246 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
247 return 0; |
4 | 248 } |
249 | |
250 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
251 /* Compare two given MD5-hashes. |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
252 * Return: 0 if equal |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
253 * negative if testHash1 < testHash2 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
254 * positive if testHash1 > testHash2 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
255 */ |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
256 static gint xs_sldb_cmphash(t_xs_md5hash testHash1, t_xs_md5hash testHash2) |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
257 { |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
258 gint i, d; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
259 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
260 /* Compute difference of hashes */ |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
261 for (i = 0, d = 0; (i < XS_MD5HASH_LENGTH) && !d; i++) |
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
262 d = (testHash1[i] - testHash2[i]); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
263 |
392
b09d74eb71e6
Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents:
389
diff
changeset
|
264 return d; |
227
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 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
268 /* Get node from db index via binary search |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
269 */ |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
270 static t_xs_sldb_node *xs_sldb_get_node(t_xs_sldb * db, t_xs_md5hash pHash) |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
271 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
272 gint iStartNode, iEndNode, iQNode, r, i; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
273 gboolean iFound; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
274 t_xs_sldb_node *pResult; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
275 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
276 /* Check the database pointers */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
277 if (!db || !db->pNodes || !db->ppIndex) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
278 return NULL; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
279 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
280 /* Look-up via index using binary search */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
281 pResult = NULL; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
282 iStartNode = 0; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
283 iEndNode = (db->n - 1); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
284 iQNode = (iEndNode / 2); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
285 iFound = FALSE; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
286 |
369
4611f1194941
Make binary search bailout value a #define in xmms-sid.h
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
287 while ((!iFound) && ((iEndNode - iStartNode) > XS_BIN_BAILOUT)) { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
288 r = xs_sldb_cmphash(pHash, db->ppIndex[iQNode]->md5Hash); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
289 if (r < 0) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
290 /* Hash was in the <- LEFT side */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
291 iEndNode = iQNode; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
292 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
293 } else if (r > 0) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
294 /* Hash was in the RIGHT -> side */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
295 iStartNode = iQNode; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
296 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
297 } else |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
298 iFound = TRUE; |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
299 } |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
300 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
301 /* If not found already */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
302 if (!iFound) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
303 /* Search the are linearly */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
304 iFound = FALSE; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
305 i = iStartNode; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
306 while ((i <= iEndNode) && (!iFound)) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
307 if (xs_sldb_cmphash(pHash, db->ppIndex[i]->md5Hash) == 0) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
308 iFound = TRUE; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
309 else |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
310 i++; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
311 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
312 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
313 /* Check the result */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
314 if (iFound) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
315 pResult = db->ppIndex[i]; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
316 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
317 } else { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
318 /* Found via binary search */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
319 pResult = db->ppIndex[iQNode]; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
320 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
321 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
322 return pResult; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
323 } |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
324 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
325 |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
326 /* Compare two nodes |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
327 */ |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
328 static 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
|
329 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
330 /* We assume here that we never ever get NULL-pointers or similar */ |
385 | 331 return xs_sldb_cmphash( |
332 (*(t_xs_sldb_node **) pNode1)->md5Hash, | |
333 (*(t_xs_sldb_node **) pNode2)->md5Hash); | |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
334 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
335 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
336 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
337 /* (Re)create index |
4 | 338 */ |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
339 gint xs_sldb_index(t_xs_sldb * db) |
4 | 340 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
341 t_xs_sldb_node *pCurr; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
342 gint i; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
343 assert(db); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
344 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
345 /* Free old index */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
346 if (db->ppIndex) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
347 g_free(db->ppIndex); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
348 db->ppIndex = NULL; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
349 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
350 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
351 /* Get size of db */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
352 pCurr = db->pNodes; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
353 db->n = 0; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
354 while (pCurr) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
355 db->n++; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
356 pCurr = pCurr->pNext; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
357 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
358 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
359 /* Check number of nodes */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
360 if (db->n > 0) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
361 /* Allocate memory for index-table */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
362 db->ppIndex = (t_xs_sldb_node **) g_malloc(sizeof(t_xs_sldb_node *) * db->n); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
363 if (!db->ppIndex) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
364 return -1; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
365 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
366 /* Get node-pointers to table */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
367 i = 0; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
368 pCurr = db->pNodes; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
369 while (pCurr && (i < db->n)) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
370 db->ppIndex[i++] = pCurr; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
371 pCurr = pCurr->pNext; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
372 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
373 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
374 /* Sort the indexes */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
375 qsort(db->ppIndex, db->n, 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
|
376 } |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
377 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
378 return 0; |
14
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 |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
382 /* Free a given song-length database |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
383 */ |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
384 void xs_sldb_free(t_xs_sldb * db) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
385 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
386 t_xs_sldb_node *pCurr, *pNext; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
387 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
388 if (!db) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
389 return; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
390 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
391 /* Free the memory allocated for nodes */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
392 pCurr = db->pNodes; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
393 while (pCurr) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
394 pNext = pCurr->pNext; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
395 xs_sldb_node_free(pCurr); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
396 pCurr = pNext; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
397 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
398 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
399 db->pNodes = NULL; |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
400 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
401 /* Free memory allocated for index */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
402 if (db->ppIndex) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
403 g_free(db->ppIndex); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
404 db->ppIndex = NULL; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
405 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
406 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
407 /* Free structure */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
408 db->n = 0; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
409 g_free(db); |
4 | 410 } |
411 | |
412 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
413 /* Compute md5hash of given SID-file |
4 | 414 */ |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
415 typedef struct |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
416 { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
417 gchar magicID[4]; /* "PSID" / "RSID" magic identifier */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
418 guint16 version, /* Version number */ |
385 | 419 dataOffset, /* Start of actual c64 data in file */ |
420 loadAddress, /* Loading address */ | |
421 initAddress, /* Initialization address */ | |
422 playAddress, /* Play one frame */ | |
423 nSongs, /* Number of subsongs */ | |
424 startSong; /* Default starting song */ | |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
425 guint32 speed; /* Speed */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
426 gchar sidName[32]; /* Descriptive text-fields, ASCIIZ */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
427 gchar sidAuthor[32]; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
428 gchar sidCopyright[32]; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
429 } t_xs_psidv1_header; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
430 |
4 | 431 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
432 typedef struct |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
433 { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
434 guint16 flags; /* Flags */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
435 guint8 startPage, pageLength; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
436 guint16 reserved; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
437 } t_xs_psidv2_header; |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
438 |
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
439 |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
440 static gint xs_get_sid_hash(const gchar *pcFilename, t_xs_md5hash hash) |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
441 { |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
442 t_xs_file *inFile; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
443 t_xs_md5state inState; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
444 t_xs_psidv1_header psidH; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
445 t_xs_psidv2_header psidH2; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
446 guint8 *songData; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
447 guint8 ib8[2], i8; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
448 gint iIndex, iRes; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
449 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
450 /* Try to open the file */ |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
451 if ((inFile = xs_fopen(pcFilename, "rb")) == NULL) |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
452 return -1; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
453 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
454 /* Read PSID header in */ |
469
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
455 xs_fread(psidH.magicID, sizeof(psidH.magicID), 1, inFile); |
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
456 if (strncmp(psidH.magicID, "PSID", 4) && strncmp(psidH.magicID, "RSID", 4)) { |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
457 xs_fclose(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
458 xs_error(_("Not a PSID or RSID file '%s'\n"), pcFilename); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
459 return -2; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
460 } |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
461 |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
462 psidH.version = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
463 psidH.dataOffset = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
464 psidH.loadAddress = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
465 psidH.initAddress = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
466 psidH.playAddress = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
467 psidH.nSongs = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
468 psidH.startSong = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
469 psidH.speed = xs_fread_be32(inFile); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
470 |
469
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
471 xs_fread(psidH.sidName, sizeof(gchar), sizeof(psidH.sidName), inFile); |
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
472 xs_fread(psidH.sidAuthor, sizeof(gchar), sizeof(psidH.sidAuthor), inFile); |
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
473 xs_fread(psidH.sidCopyright, sizeof(gchar), sizeof(psidH.sidCopyright), inFile); |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
474 |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
475 if (xs_feof(inFile) || xs_ferror(inFile)) { |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
476 xs_fclose(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
477 xs_error(_("Error reading SID file header from '%s'\n"), pcFilename); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
478 return -4; |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
479 } |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
480 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
481 /* Check if we need to load PSIDv2NG header ... */ |
469
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
482 psidH2.flags = 0; /* Just silence a stupid gcc warning */ |
d600f45c92d2
Silence a gcc warning; Use xs_*() file handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
458
diff
changeset
|
483 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
484 if (psidH.version == 2) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
485 /* Yes, we need to */ |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
486 psidH2.flags = xs_fread_be16(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
487 psidH2.startPage = xs_fgetc(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
488 psidH2.pageLength = xs_fgetc(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
489 psidH2.reserved = xs_fread_be16(inFile); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
490 } |
385 | 491 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
492 /* Allocate buffer */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
493 songData = (guint8 *) g_malloc(XS_SIDBUF_SIZE * sizeof(guint8)); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
494 if (!songData) { |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
495 xs_fclose(inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
496 xs_error(_("Error allocating temp data buffer for file '%s'\n"), pcFilename); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
497 return -3; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
498 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
499 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
500 /* Read data to buffer */ |
458
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
501 iRes = xs_fread(songData, sizeof(guint8), XS_SIDBUF_SIZE, inFile); |
57836945fa71
Use new xs_* file functions for SID-file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
502 xs_fclose(inFile); |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
503 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
504 /* Initialize and start MD5-hash calculation */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
505 xs_md5_init(&inState); |
385 | 506 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
507 if (psidH.loadAddress == 0) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
508 /* Strip load address (2 first bytes) */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
509 xs_md5_append(&inState, &songData[2], iRes - 2); |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
510 } else { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
511 /* Append "as is" */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
512 xs_md5_append(&inState, songData, iRes); |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
513 } |
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
514 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
515 /* Free buffer */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
516 g_free(songData); |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
517 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
518 /* Append header data to hash */ |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
519 #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
|
520 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
521 XSADDHASH(psidH.initAddress) |
385 | 522 XSADDHASH(psidH.playAddress) |
523 XSADDHASH(psidH.nSongs) | |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
524 #undef XSADDHASH |
385 | 525 |
526 /* Append song speed data to hash */ | |
527 i8 = 0; | |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
528 for (iIndex = 0; (iIndex < psidH.nSongs) && (iIndex < 32); iIndex++) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
529 i8 = (psidH.speed & (1 << iIndex)) ? 60 : 0; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
530 xs_md5_append(&inState, &i8, sizeof(i8)); |
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 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
533 /* Rest of songs (more than 32) */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
534 for (iIndex = 32; iIndex < psidH.nSongs; iIndex++) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
535 xs_md5_append(&inState, &i8, sizeof(i8)); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
536 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
537 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
538 /* PSIDv2NG specific */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
539 if (psidH.version == 2) { |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
540 /* SEE SIDPLAY HEADERS FOR INFO */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
541 i8 = (psidH2.flags >> 2) & 3; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
542 if (i8 == 2) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
543 xs_md5_append(&inState, &i8, sizeof(i8)); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
544 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
545 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
546 /* Calculate the hash */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
547 xs_md5_finish(&inState, hash); |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
548 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
549 return 0; |
14
f5d82424b0ed
Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
550 } |
4 | 551 |
552 | |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
553 /* Get song lengths |
4 | 554 */ |
402
f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents:
392
diff
changeset
|
555 t_xs_sldb_node *xs_sldb_get(t_xs_sldb *db, const gchar *pcFilename) |
4 | 556 { |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
557 t_xs_sldb_node *pResult; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
558 t_xs_md5hash dbHash; |
4 | 559 |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
560 /* Get the hash and then look up from db */ |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
561 if (xs_get_sid_hash(pcFilename, dbHash) == 0) |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
562 pResult = xs_sldb_get_node(db, dbHash); |
227
92bad4c7b998
Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
563 else |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
564 pResult = NULL; |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
565 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
566 return pResult; |
4 | 567 } |