annotate src/xs_length.c @ 970:d90bca05521e

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