annotate src/xs_length.c @ 923:86f914bb48a7

Oops, filename variable argument to xs_error() was missing, printing garbage instead. Fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 11 Nov 2012 07:28:41 +0200
parents 560cdf7f1fec
children f8e1de328ac1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
332
961212302eb9 Comment
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
4 Get song length from SLDB for PSID/RSID files
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
723
9321ffa2ea7e Update copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 660
diff changeset
7 (C) Copyright 1999-2009 Tecnic Software productions (TNSP)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 (at your option) any later version.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 GNU General Public License for more details.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
39
85a7753e2a9a Lots of new code
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
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
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #include <stdlib.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include <ctype.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
29
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
30 /* Free memory allocated for given SLDB node
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
32 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
33 {
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
34 if (node)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
35 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
36 g_free(node->lengths);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
37 g_free(node);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
38 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
39 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
40
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
41
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
42 /* 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
43 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
44 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
45 {
783
37ab2fba30c8 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 782
diff changeset
46 assert(db != NULL);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
47
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
48 if (db->nodes)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
49 {
783
37ab2fba30c8 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 782
diff changeset
50 node->prev = db->nodes->prev;
782
64352e85113e Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 780
diff changeset
51 db->nodes->prev->next = node;
64352e85113e Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 780
diff changeset
52 db->nodes->prev = node;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
53 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
54 else
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
55 {
782
64352e85113e Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 780
diff changeset
56 db->nodes = node;
783
37ab2fba30c8 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 782
diff changeset
57 node->prev = node;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
58 }
783
37ab2fba30c8 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 782
diff changeset
59 node->next = NULL;
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 */
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
65 static gint xs_sldb_gettime(gchar *str, size_t *pos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
67 gint result, tmp;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
69 /* Check if it starts with a digit */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
70 if (isdigit(str[*pos]))
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
71 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
72 /* Get minutes-field */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
73 result = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
74 while (isdigit(str[*pos]))
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
75 result = (result * 10) + (str[(*pos)++] - '0');
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
76
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
77 result *= 60;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
79 /* Check the field separator char */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
80 if (str[*pos] == ':')
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
81 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
82 /* Get seconds-field */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
83 (*pos)++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
84 tmp = 0;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
85 while (isdigit(str[*pos]))
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
86 tmp = (tmp * 10) + (str[(*pos)++] - '0');
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
88 result += tmp;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
89 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
90 else
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
91 result = -2;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
92 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
93 else
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
94 result = -1;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
96 /* Ignore and skip the possible attributes */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
97 while (str[*pos] && !isspace(str[*pos]))
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
98 (*pos)++;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
99
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
100 return result;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
104 /* 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
105 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
106 XSSLDBNode * xs_sldb_read_entry(gchar *inLine)
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
107 {
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
108 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
109 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
110 gboolean isOK;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
111 gint i;
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
112
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
113 /* Allocate new node */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
114 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
115 if (tmnode == NULL)
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
116 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
117 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
118 return NULL;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
119 }
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
120
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
121 /* Get hash value */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
122 linePos = 0;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
123 for (i = 0; i < XS_MD5HASH_LENGTH; i++, linePos += 2)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
124 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
125 gint tmpu;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
126 sscanf(&inLine[linePos], "%2x", &tmpu);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
127 tmnode->md5Hash[i] = tmpu;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
128 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
129
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
130 /* 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
131 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
132 if (inLine[linePos] != '=')
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
133 {
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
134 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
135 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
136 }
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
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
138 /* 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
139 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
140 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
141
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
142 /* 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
143 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
144 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
145 {
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 xs_findnext(inLine, &linePos);
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
147
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
148 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
149 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
150 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
151 isOK = FALSE;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
152 }
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
153
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
154 /* 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
155 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
156 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
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 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
159 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
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 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
162 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
163 }
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
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 /* 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
166 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
167 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
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 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
170 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
171
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 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
173 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
174 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
175 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
176 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
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
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 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
180
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
181 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
182 xs_sldb_node_free(tmnode);
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
183 return NULL;
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
184 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
185
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
186
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
187 /* Read database to memory
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
189 gint xs_sldb_read(XSSLDB *db, const gchar *dbFilename)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
191 FILE *inFile;
777
15f0c8e11338 Increase line buffer size in songlength database reader. Fixes problems with
Matti Hamalainen <ccr@tnsp.org>
parents: 751
diff changeset
192 gchar inLine[XS_BUF2_SIZE];
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
193 size_t lineNum;
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
194 XSSLDBNode *tmnode;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
195 assert(db);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
196
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
197 /* Try to open the file */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
198 if ((inFile = fopen(dbFilename, "ra")) == NULL)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
199 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
200 xs_error("Could not open SongLengthDB '%s'\n", dbFilename);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
201 return -1;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
202 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
203
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
204 /* Read and parse the data */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
205 lineNum = 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
207 while (fgets(inLine, XS_BUF2_SIZE, inFile) != NULL)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
208 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
209 size_t linePos = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
210 lineNum++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
211
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
212 xs_findnext(inLine, &linePos);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
214 /* Check if it is datafield */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
215 if (isxdigit(inLine[linePos]))
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
216 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
217 /* Check the length of the hash */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
218 gint hashLen;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
219 for (hashLen = 0; inLine[linePos] && isxdigit(inLine[linePos]); hashLen++, linePos++);
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
220
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
221 if (hashLen != XS_MD5HASH_LENGTH_CH)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
222 {
778
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
223 xs_error("Invalid MD5-hash in SongLengthDB file '%s' line #%d:\n%s\n",
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
224 dbFilename, lineNum, inLine);
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
225 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
226 else
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
227 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
228 /* Parse and add node to db */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
229 if ((tmnode = xs_sldb_read_entry(inLine)) != NULL)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
230 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
231 xs_sldb_node_insert(db, tmnode);
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
232 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
233 else
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
234 {
778
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
235 xs_error("Invalid entry in SongLengthDB file '%s' line #%d:\n%s\n",
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
236 dbFilename, lineNum, inLine);
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
237 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
238 }
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
239 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
240 else
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
241 if (inLine[linePos] != ';' && inLine[linePos] != '[' && inLine[linePos] != 0)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
242 {
778
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
243 xs_error("Invalid line in SongLengthDB file '%s' line #%d:\n%s\n",
54a7afbf251e Improve error messages in songlength database parser.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
244 dbFilename, lineNum, inLine);
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
245 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
246 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
248 fclose(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
249 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
253 /* Compare two given MD5-hashes.
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
254 * Return: 0 if equal
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
255 * negative if testHash1 < testHash2
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
256 * positive if testHash1 > testHash2
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
257 */
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
258 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
259 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
260 gint i, d;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
261
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
262 /* Compute difference of hashes */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
263 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
264 d = (testHash1[i] - testHash2[i]);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
265
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
266 return d;
227
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
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
269
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
270 /* Compare two nodes
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
271 */
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
272 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
273 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
274 /* 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
275 return xs_sldb_cmphash(
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
276 (*(XSSLDBNode **) node1)->md5Hash,
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
277 (*(XSSLDBNode **) node2)->md5Hash);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
278 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
279
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
280
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
281 /* (Re)create index
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
283 gint xs_sldb_index(XSSLDB * db)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 {
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
285 XSSLDBNode *node;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
286 size_t i;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
287 assert(db);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
288
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
289 /* Free old index */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
290 g_free(db->pindex);
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
291 db->pindex = NULL;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
292
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
293 /* Get size of db */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
294 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
295 db->n++;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
296
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
297 /* Check number of nodes */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
298 if (db->n > 0)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
299 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
300 /* Allocate memory for index-table */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
301 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
302 if (!db->pindex)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
303 return -1;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
304
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
305 /* Get node-pointers to table */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
306 for (i = 0, node = db->nodes; node && i < db->n; node = node->next)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
307 db->pindex[i++] = node;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
308
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
309 /* Sort the indexes */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
310 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
311 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
312
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
313 return 0;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
314 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
315
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
316
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
317 /* Free a given song-length database
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
318 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
319 void xs_sldb_free(XSSLDB * db)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
320 {
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
321 XSSLDBNode *node, *next;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
322
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
323 if (!db)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
324 return;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
325
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
326 /* Free the memory allocated for nodes */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
327 node = db->nodes;
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
328 while (node != NULL)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
329 {
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
330 next = node->next;
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
331 xs_sldb_node_free(node);
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
332 node = next;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
333 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
334
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
335 db->nodes = NULL;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
336
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
337 /* Free memory allocated for index */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
338 g_free(db->pindex);
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
339 db->pindex = NULL;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
340
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
341 /* Free structure */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
342 db->n = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
343 g_free(db);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
347 /* Compute md5hash of given SID-file
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
349 typedef struct
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
350 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
351 gchar magicID[4]; /* "PSID" / "RSID" magic identifier */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
352 guint16 version, /* Version number */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
353 dataOffset, /* Start of actual c64 data in file */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
354 loadAddress, /* Loading address */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
355 initAddress, /* Initialization address */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
356 playAddress, /* Play one frame */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
357 nSongs, /* Number of subsongs */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
358 startSong; /* Default starting song */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
359 guint32 speed; /* Speed */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
360 gchar sidName[32]; /* Descriptive text-fields, ASCIIZ */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
361 gchar sidAuthor[32];
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
362 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
363 } psidv1_header_t;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
364
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
366 typedef struct
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
367 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
368 guint16 flags; /* Flags */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
369 guint8 startPage, pageLength;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
370 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
371 } psidv2_header_t;
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
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
374 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
375 {
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
376 XSFile *inFile;
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
377 xs_md5state_t inState;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
378 psidv1_header_t psidH;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
379 psidv2_header_t psidH2;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
380 guint8 *songData;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
381 guint8 ib8[2], i8;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
382 gint index, result;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
383
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
384 /* Try to open the file */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
385 if ((inFile = xs_fopen(filename, "rb")) == NULL)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
386 return -1;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
387
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
388 /* Read PSID header in */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
389 xs_fread(psidH.magicID, sizeof(psidH.magicID), 1, inFile);
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
390 if (strncmp(psidH.magicID, "PSID", 4) &&
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
391 strncmp(psidH.magicID, "RSID", 4))
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
392 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
393 xs_fclose(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
394 xs_error("Not a PSID or RSID file '%s'\n", filename);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
395 return -2;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
396 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
397
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
398 psidH.version = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
399 psidH.dataOffset = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
400 psidH.loadAddress = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
401 psidH.initAddress = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
402 psidH.playAddress = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
403 psidH.nSongs = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
404 psidH.startSong = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
405 psidH.speed = xs_fread_be32(inFile);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
406
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
407 xs_fread(psidH.sidName, sizeof(gchar), sizeof(psidH.sidName), inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
408 xs_fread(psidH.sidAuthor, sizeof(gchar), sizeof(psidH.sidAuthor), inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
409 xs_fread(psidH.sidCopyright, sizeof(gchar), sizeof(psidH.sidCopyright), inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
410
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
411 if (xs_feof(inFile) || xs_ferror(inFile))
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
412 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
413 xs_fclose(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
414 xs_error("Error reading SID file header from '%s'\n", filename);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
415 return -4;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
416 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
417
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
418 /* Check if we need to load PSIDv2NG header ... */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
419 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
420
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
421 if (psidH.version == 2)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
422 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
423 /* Yes, we need to */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
424 psidH2.flags = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
425 psidH2.startPage = xs_fgetc(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
426 psidH2.pageLength = xs_fgetc(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
427 psidH2.reserved = xs_fread_be16(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
428 }
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
429
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
430 /* Allocate buffer */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
431 songData = (guint8 *) g_malloc(XS_SIDBUF_SIZE * sizeof(guint8));
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
432 if (!songData)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
433 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
434 xs_fclose(inFile);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
435 xs_error("Error allocating temp data buffer for file '%s'\n", filename);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
436 return -3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
437 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
438
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
439 /* Read data to buffer */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
440 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
441 xs_fclose(inFile);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
442
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
443 /* Initialize and start MD5-hash calculation */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
444 xs_md5_init(&inState);
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
445
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
446 if (psidH.loadAddress == 0)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
447 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
448 /* Strip load address (2 first bytes) */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
449 xs_md5_append(&inState, &songData[2], result - 2);
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
450 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
451 else
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
452 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
453 /* Append "as is" */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
454 xs_md5_append(&inState, songData, result);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
455 }
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
456
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
457 /* Free buffer */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
458 g_free(songData);
87
94497283affa Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
459
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
460 /* Append header data to hash */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
461 #define XSADDHASH(QDATAB) do { \
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
462 ib8[0] = (QDATAB & 0xff); \
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
463 ib8[1] = (QDATAB >> 8); \
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
464 xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
465 } while (0)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
466
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
467 XSADDHASH(psidH.initAddress);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
468 XSADDHASH(psidH.playAddress);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
469 XSADDHASH(psidH.nSongs);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
470 #undef XSADDHASH
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
471
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
472 /* Append song speed data to hash */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
473 i8 = 0;
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
474 for (index = 0; index < psidH.nSongs && index < 32; index++)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
475 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
476 i8 = (psidH.speed & (1 << index)) ? 60 : 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
477 xs_md5_append(&inState, &i8, sizeof(i8));
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
478 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
479
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
480 /* Rest of songs (more than 32) */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
481 for (index = 32; index < psidH.nSongs; index++)
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
482 xs_md5_append(&inState, &i8, sizeof(i8));
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
483
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
484 /* PSIDv2NG specific */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
485 if (psidH.version == 2)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
486 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
487 /* SEE SIDPLAY HEADERS FOR INFO */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
488 i8 = (psidH2.flags >> 2) & 3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
489 if (i8 == 2)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
490 xs_md5_append(&inState, &i8, sizeof(i8));
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
491 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
492
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
493 /* Calculate the hash */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
494 xs_md5_finish(&inState, hash);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
495
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
496 return 0;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
497 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499
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
500 /* Get node from db index via binary search
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 */
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
502 XSSLDBNode *xs_sldb_get(XSSLDB *db, const gchar *filename)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 {
751
55eea3fa8868 Rename some structures.
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
504 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
505
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
506 /* Check the database pointers */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
507 if (!db || !db->nodes || !db->pindex)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
508 return NULL;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
510 /* Get the hash and then look up from db */
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
511 if (xs_get_sid_hash(filename, keyItem.md5Hash) == 0)
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
512 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
513 key = &keyItem;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
514 item = bsearch(&key, db->pindex, db->n,
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
515 sizeof(db->pindex[0]), xs_sldb_cmp);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
516
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
517 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
518 {
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
519 gint i;
923
86f914bb48a7 Oops, filename variable argument to xs_error() was missing, printing garbage
Matti Hamalainen <ccr@tnsp.org>
parents: 920
diff changeset
520 xs_error("No matching hash in SLDB: %s\n", filename);
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
521 for (i = 0; i < XS_MD5HASH_LENGTH; 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
522 fprintf(stderr, "%02x", keyItem.md5Hash[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
523 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
524 }
909
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
525 return (item != NULL) ? *item : NULL;
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
526 }
84394ee26545 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 783
diff changeset
527 else
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
528 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
529 }