annotate src/xs_length.c @ 402:f997b79a7251

More work on merging of improved STIL/SLDB handling code with completely dynamic memory allocation.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 01 Jun 2006 02:18:02 +0000
parents b09d74eb71e6
children 7f694e5a1493
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>
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
7 (C) Copyright 1999-2005 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
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 along with this program; if not, write to the Free Software
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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"
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
25 #include "xs_config.h"
223
16e3b2446a73 On some systems stdlib.h has prerequisite of stdio.h, corrected order of
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
26 #include <stdio.h>
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include <stdlib.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include <ctype.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include <string.h>
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
31
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
32 /* Free memory allocated for given SLDB node
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
34 static void xs_sldb_node_free(t_xs_sldb_node *pNode)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
35 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
36 if (pNode) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
37 /* Nothing much to do here ... */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
38 g_free(pNode->sLengths);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
39 g_free(pNode);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
40 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
41 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
42
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
43
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
44 /* 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
45 */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
46 static void xs_sldb_node_insert(t_xs_sldb *db, t_xs_sldb_node *pNode)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
47 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
48 assert(db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
49
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
50 if (db->pNodes) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
51 /* The first node's pPrev points to last node */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
52 LPREV = db->pNodes->pPrev; /* New node's prev = Previous last node */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
53 db->pNodes->pPrev->pNext = pNode; /* Previous last node's next = New node */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
54 db->pNodes->pPrev = pNode; /* New last node = New node */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
55 LNEXT = NULL; /* But next is NULL! */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
56 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
57 db->pNodes = pNode; /* First node ... */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
58 LPREV = pNode; /* ... it's also last */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
59 LNEXT = NULL; /* But next is NULL! */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
60 }
14
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
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
63
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
64 /* 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
65 */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
66 static gint xs_sldb_gettime(gchar *pcStr, gint *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
68 gint iResult, iTemp;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
70 /* Check if it starts with a digit */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
71 if (isdigit(pcStr[*piPos])) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
72 /* Get minutes-field */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
73 iResult = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
74 while (isdigit(pcStr[*piPos]))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
75 iResult = (iResult * 10) + (pcStr[(*piPos)++] - '0');
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
76
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
77 iResult *= 60;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
79 /* Check the field separator char */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
80 if (pcStr[*piPos] == ':') {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
81 /* Get seconds-field */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
82 (*piPos)++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
83 iTemp = 0;
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
84 while (isdigit(pcStr[*piPos])) {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
85 iTemp = (iTemp * 10) + (pcStr[(*piPos)++] - '0');
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
86 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
88 iResult += iTemp;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 } else
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
90 iResult = -2;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 } else
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
92 iResult = -1;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
94 /* Ignore and skip the possible attributes */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
95 while (pcStr[*piPos] && !isspace(pcStr[*piPos]))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
96 (*piPos)++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
97
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
98 return iResult;
4
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
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
102 /* 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
103 */
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
104 t_xs_sldb_node * xs_sldb_read_entry(gchar *inLine)
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
105 {
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
106 gint linePos, savePos, i, tmpLen, l;
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
107 gboolean iOK;
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
108 t_xs_sldb_node *tmpNode;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
109
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
110 /* Allocate new node */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
111 tmpNode = (t_xs_sldb_node *) g_malloc0(sizeof(t_xs_sldb_node));
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
112 if (!tmpNode) {
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
113 xs_error("Error allocating new node. Fatal error.\n");
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
114 return NULL;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
115 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
116
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
117 /* Get hash value */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
118 linePos = 0;
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
119 for (i = 0; i < XS_MD5HASH_LENGTH; i++, linePos += 2) {
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
120 sscanf(&inLine[linePos], "%2x",
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
121 (guint *) &(tmpNode->md5Hash[i]));
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
122 }
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
123
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
124 /* Get playtimes */
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
125 if (inLine[linePos] != 0) {
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
126 if (inLine[linePos] != '=') {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
127 xs_error("'=' expected on column #%d.\n", linePos);
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
128 xs_sldb_node_free(tmpNode);
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
129 return NULL;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
130 } else {
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
131 /* First playtime is after '=' */
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
132 savePos = ++linePos;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
133 tmpLen = strlen(inLine);
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
134
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
135 /* Get number of sub-tune lengths */
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
136 iOK = TRUE;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
137 while ((linePos < tmpLen) && iOK) {
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
138 xs_findnext(inLine, &linePos);
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
139
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
140 if (xs_sldb_gettime(inLine, &linePos) >= 0)
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
141 tmpNode->nLengths++;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
142 else
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
143 iOK = FALSE;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
144 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
145
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
146 /* Allocate memory for lengths */
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
147 tmpNode->sLengths = (gint *) g_malloc0(tmpNode->nLengths * sizeof(gint));
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
148 if (!tmpNode->sLengths) {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
149 xs_error("Could not allocate memory for node.\n");
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
150 xs_sldb_node_free(tmpNode);
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
151 return NULL;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
152 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
153
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
154 /* Read lengths in */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
155 i = 0;
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
156 linePos = savePos;
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
157 iOK = TRUE;
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
158 while ((linePos < tmpLen) && (i < tmpNode->nLengths) && iOK) {
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
159 xs_findnext(inLine, &linePos);
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
160
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
161 l = xs_sldb_gettime(inLine, &linePos);
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
162 if (l >= 0)
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
163 tmpNode->sLengths[i] = l;
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
164 else
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
165 iOK = FALSE;
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
166
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
167 i++;
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
168 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
169
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
170 if (!iOK) {
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
171 xs_sldb_node_free(tmpNode);
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
172 return NULL;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
173 } else
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
174 return tmpNode;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
175 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
176 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
177
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
178 return NULL;
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
179 }
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
180
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
181
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
182 /* Read database to memory
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 */
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
184 gint xs_sldb_read(t_xs_sldb *db, const gchar *dbFilename)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
186 FILE *inFile;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
187 gchar inLine[XS_BUF_SIZE];
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
188 gint lineNum;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
189 t_xs_sldb_node *tmpNode;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
190 assert(db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
191
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
192 /* Try to open the file */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
193 if ((inFile = fopen(dbFilename, "ra")) == NULL) {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
194 xs_error("Could not open SongLengthDB '%s'\n", dbFilename);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
195 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
196 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
197
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
198 /* Read and parse the data */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
199 lineNum = 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
201 while (!feof(inFile)) {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
202 gint linePos;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
203 fgets(inLine, XS_BUF_SIZE, inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
204 inLine[XS_BUF_SIZE - 1] = 0;
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
205 linePos = 0;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
206 lineNum++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
208 /* Check if it is datafield */
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
209 if (isxdigit(inLine[linePos])) {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
210 /* Check the length of the hash */
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
211 gint hashLen;
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
212 for (hashLen = 0; isxdigit(inLine[linePos]); hashLen++, linePos++);
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
213
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
214 if (hashLen != XS_MD5HASH_LENGTH_CH) {
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
215 xs_error("Invalid MD5-hash in SongLengthDB file '%s' line #%d!\n",
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
216 dbFilename, lineNum);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
217 } else {
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
218 /* Parse and add node to db */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
219 if ((tmpNode = xs_sldb_read_entry(inLine)) != NULL) {
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
220 xs_sldb_node_insert(db, tmpNode);
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
221 } else {
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
222 xs_error("Invalid entry in SongLengthDB file '%s' line #%d!\n",
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
223 dbFilename, lineNum);
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
224 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
226 } else if ((inLine[linePos] != ';') && (inLine[linePos] != '[')) {
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
227 xs_error("Invalid line in SongLengthDB file '%s' line #%d\n",
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
228 dbFilename, lineNum);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
229 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
230
389
3c239e4160d5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
231 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
233 /* Close the file */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
234 fclose(inFile);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
236 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
240 /* Compare two given MD5-hashes.
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
241 * Return: 0 if equal
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
242 * negative if testHash1 < testHash2
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
243 * positive if testHash1 > testHash2
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
244 */
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
245 static gint xs_sldb_cmphash(t_xs_md5hash testHash1, t_xs_md5hash testHash2)
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
246 {
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
247 gint i, d;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
248
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
249 /* Compute difference of hashes */
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
250 for (i = 0, d = 0; (i < XS_MD5HASH_LENGTH) && !d; i++)
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
251 d = (testHash1[i] - testHash2[i]);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
252
392
b09d74eb71e6 Working on getting STIL and SLDB using completely dynamically allocated
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
253 return d;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
254 }
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
255
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
256
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
257 /* Get node from db index via binary search
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
258 */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
259 static t_xs_sldb_node *xs_sldb_get_node(t_xs_sldb * db, t_xs_md5hash pHash)
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
260 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
261 gint iStartNode, iEndNode, iQNode, r, i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
262 gboolean iFound;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
263 t_xs_sldb_node *pResult;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
264
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
265 /* Check the database pointers */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
266 if (!db || !db->pNodes || !db->ppIndex)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
267 return NULL;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
268
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
269 /* Look-up via index using binary search */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
270 pResult = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
271 iStartNode = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
272 iEndNode = (db->n - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
273 iQNode = (iEndNode / 2);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
274 iFound = FALSE;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
275
369
4611f1194941 Make binary search bailout value a #define in xmms-sid.h
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
276 while ((!iFound) && ((iEndNode - iStartNode) > XS_BIN_BAILOUT)) {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
277 r = xs_sldb_cmphash(pHash, db->ppIndex[iQNode]->md5Hash);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
278 if (r < 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
279 /* Hash was in the <- LEFT side */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
280 iEndNode = iQNode;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
281 iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
282 } else if (r > 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
283 /* Hash was in the RIGHT -> side */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
284 iStartNode = iQNode;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
285 iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
286 } else
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
287 iFound = TRUE;
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
288 }
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
289
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
290 /* If not found already */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
291 if (!iFound) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
292 /* Search the are linearly */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
293 iFound = FALSE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
294 i = iStartNode;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
295 while ((i <= iEndNode) && (!iFound)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
296 if (xs_sldb_cmphash(pHash, db->ppIndex[i]->md5Hash) == 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
297 iFound = TRUE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
298 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
299 i++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
300 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
301
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
302 /* Check the result */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
303 if (iFound)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
304 pResult = db->ppIndex[i];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
305
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
306 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
307 /* Found via binary search */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
308 pResult = db->ppIndex[iQNode];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
309 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
310
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
311 return pResult;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
312 }
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
313
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
314
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
315 /* Compare two nodes
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
316 */
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
317 static gint xs_sldb_cmp(const void *pNode1, const void *pNode2)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
318 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
319 /* We assume here that we never ever get NULL-pointers or similar */
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
320 return xs_sldb_cmphash(
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
321 (*(t_xs_sldb_node **) pNode1)->md5Hash,
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
322 (*(t_xs_sldb_node **) pNode2)->md5Hash);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
323 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
324
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
325
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
326 /* (Re)create index
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
328 gint xs_sldb_index(t_xs_sldb * db)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
330 t_xs_sldb_node *pCurr;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
331 gint i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
332 assert(db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
333
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
334 /* Free old index */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
335 if (db->ppIndex) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
336 g_free(db->ppIndex);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
337 db->ppIndex = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
338 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
339
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
340 /* Get size of db */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
341 pCurr = db->pNodes;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
342 db->n = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
343 while (pCurr) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
344 db->n++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
345 pCurr = pCurr->pNext;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
346 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
347
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
348 /* Check number of nodes */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
349 if (db->n > 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
350 /* Allocate memory for index-table */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
351 db->ppIndex = (t_xs_sldb_node **) g_malloc(sizeof(t_xs_sldb_node *) * db->n);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
352 if (!db->ppIndex)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
353 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
354
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
355 /* Get node-pointers to table */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
356 i = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
357 pCurr = db->pNodes;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
358 while (pCurr && (i < db->n)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
359 db->ppIndex[i++] = pCurr;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
360 pCurr = pCurr->pNext;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
361 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
362
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
363 /* Sort the indexes */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
364 qsort(db->ppIndex, db->n, sizeof(t_xs_sldb_node *), xs_sldb_cmp);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
365 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
366
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
367 return 0;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
368 }
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
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
371 /* Free a given song-length database
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
372 */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
373 void xs_sldb_free(t_xs_sldb * db)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
374 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
375 t_xs_sldb_node *pCurr, *pNext;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
376
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
377 if (!db)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
378 return;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
379
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
380 /* Free the memory allocated for nodes */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
381 pCurr = db->pNodes;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
382 while (pCurr) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
383 pNext = pCurr->pNext;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
384 xs_sldb_node_free(pCurr);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
385 pCurr = pNext;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
386 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
387
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
388 db->pNodes = NULL;
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
389
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
390 /* Free memory allocated for index */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
391 if (db->ppIndex) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
392 g_free(db->ppIndex);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
393 db->ppIndex = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
394 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
395
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
396 /* Free structure */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
397 db->n = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
398 g_free(db);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
402 /* Compute md5hash of given SID-file
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
404 typedef struct
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
405 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
406 gchar magicID[4]; /* "PSID" / "RSID" magic identifier */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
407 guint16 version, /* Version number */
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
408 dataOffset, /* Start of actual c64 data in file */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
409 loadAddress, /* Loading address */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
410 initAddress, /* Initialization address */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
411 playAddress, /* Play one frame */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
412 nSongs, /* Number of subsongs */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
413 startSong; /* Default starting song */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
414 guint32 speed; /* Speed */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
415 gchar sidName[32]; /* Descriptive text-fields, ASCIIZ */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
416 gchar sidAuthor[32];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
417 gchar sidCopyright[32];
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
418 } t_xs_psidv1_header;
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
419
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
421 typedef struct
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
422 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
423 guint16 flags; /* Flags */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
424 guint8 startPage, pageLength;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
425 guint16 reserved;
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
426 } t_xs_psidv2_header;
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
427
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
428
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
429 static gint xs_get_sid_hash(const gchar *pcFilename, t_xs_md5hash hash)
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
430 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
431 FILE *inFile;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
432 t_xs_md5state inState;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
433 t_xs_psidv1_header psidH;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
434 t_xs_psidv2_header psidH2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
435 guint8 *songData;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
436 guint8 ib8[2], i8;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
437 gint iIndex, iRes;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
438
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
439 /* Try to open the file */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
440 if ((inFile = fopen(pcFilename, "rb")) == NULL)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
441 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
442
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
443 /* Read PSID header in */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
444 xs_rd_str(inFile, psidH.magicID, sizeof(psidH.magicID));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
445 if ((psidH.magicID[0] != 'P' && psidH.magicID[0] != 'R') ||
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
446 (psidH.magicID[1] != 'S') || (psidH.magicID[2] != 'I') || (psidH.magicID[3] != 'D')) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
447 fclose(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
448 return -2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
449 }
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
450
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
451 psidH.version = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
452 psidH.dataOffset = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
453 psidH.loadAddress = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
454 psidH.initAddress = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
455 psidH.playAddress = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
456 psidH.nSongs = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
457 psidH.startSong = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
458 psidH.speed = xs_rd_be32(inFile);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
459
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
460 xs_rd_str(inFile, psidH.sidName, sizeof(psidH.sidName));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
461 xs_rd_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
462 xs_rd_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
463
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
464 /* Check if we need to load PSIDv2NG header ... */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
465 if (psidH.version == 2) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
466 /* Yes, we need to */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
467 psidH2.flags = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
468 psidH2.startPage = fgetc(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
469 psidH2.pageLength = fgetc(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
470 psidH2.reserved = xs_rd_be16(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
471 }
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
472
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
473 /* Allocate buffer */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
474 songData = (guint8 *) g_malloc(XS_SIDBUF_SIZE * sizeof(guint8));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
475 if (!songData) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
476 fclose(inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
477 return -3;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
478 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
479
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
480 /* Read data to buffer */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
481 iRes = fread(songData, sizeof(guint8), XS_SIDBUF_SIZE, inFile);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
482 fclose(inFile);
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
483
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
484 /* Initialize and start MD5-hash calculation */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
485 xs_md5_init(&inState);
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
486
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
487 if (psidH.loadAddress == 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
488 /* Strip load address (2 first bytes) */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
489 xs_md5_append(&inState, &songData[2], iRes - 2);
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
490 } else {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
491 /* Append "as is" */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
492 xs_md5_append(&inState, songData, iRes);
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
493 }
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
494
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
495 /* Free buffer */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
496 g_free(songData);
87
94497283affa Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
497
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
498 /* Append header data to hash */
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
499 #define XSADDHASH(QDATAB) { ib8[0] = (QDATAB & 0xff); ib8[1] = (QDATAB >> 8); xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
500
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
501 XSADDHASH(psidH.initAddress)
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
502 XSADDHASH(psidH.playAddress)
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
503 XSADDHASH(psidH.nSongs)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
504 #undef XSADDHASH
385
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
505
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
506 /* Append song speed data to hash */
7dc7e7dbbf90 Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
507 i8 = 0;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
508 for (iIndex = 0; (iIndex < psidH.nSongs) && (iIndex < 32); iIndex++) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
509 i8 = (psidH.speed & (1 << iIndex)) ? 60 : 0;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
510 xs_md5_append(&inState, &i8, sizeof(i8));
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
511 }
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
512
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
513 /* Rest of songs (more than 32) */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
514 for (iIndex = 32; iIndex < psidH.nSongs; iIndex++) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
515 xs_md5_append(&inState, &i8, sizeof(i8));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
516 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
517
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
518 /* PSIDv2NG specific */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
519 if (psidH.version == 2) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
520 /* SEE SIDPLAY HEADERS FOR INFO */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
521 i8 = (psidH2.flags >> 2) & 3;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
522 if (i8 == 2)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
523 xs_md5_append(&inState, &i8, sizeof(i8));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
524 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
525
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
526 /* Calculate the hash */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
527 xs_md5_finish(&inState, hash);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
528
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
529 return 0;
14
f5d82424b0ed Made song-length database support FINALLY work!
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
530 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
533 /* Get song lengths
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 */
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
535 t_xs_sldb_node *xs_sldb_get(t_xs_sldb *db, const gchar *pcFilename)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
537 t_xs_sldb_node *pResult;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
538 t_xs_md5hash dbHash;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
540 /* Get the hash and then look up from db */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
541 if (xs_get_sid_hash(pcFilename, dbHash) == 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
542 pResult = xs_sldb_get_node(db, dbHash);
227
92bad4c7b998 Improved modularization of STIL and song-length database subsystems.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
543 else
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
544 pResult = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
545
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
546 return pResult;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 }
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
548
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
549
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
550 /*
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
551 * These should be moved out of this module some day ...
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
552 */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
553 static t_xs_sldb *xs_sldb_db = NULL;
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
554 XS_MUTEX(xs_sldb_db);
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
555
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
556 gint xs_songlen_init(void)
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
557 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
558 XS_MUTEX_LOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
559
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
560 if (!xs_cfg.songlenDBPath) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
561 XS_MUTEX_UNLOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
562 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
563 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
564
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
565 XS_MUTEX_LOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
566
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
567 /* Check if already initialized */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
568 if (xs_sldb_db)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
569 xs_sldb_free(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
570
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
571 /* Allocate database */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
572 xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
573 if (!xs_sldb_db) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
574 XS_MUTEX_UNLOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
575 XS_MUTEX_UNLOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
576 return -2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
577 }
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
578
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
579 /* Read the database */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
580 if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
581 xs_sldb_free(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
582 xs_sldb_db = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
583 XS_MUTEX_UNLOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
584 XS_MUTEX_UNLOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
585 return -3;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
586 }
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
587
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
588 /* Create index */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
589 if (xs_sldb_index(xs_sldb_db) != 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
590 xs_sldb_free(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
591 xs_sldb_db = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
592 XS_MUTEX_UNLOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
593 XS_MUTEX_UNLOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
594 return -4;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
595 }
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
596
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
597 XS_MUTEX_UNLOCK(xs_cfg);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
598 XS_MUTEX_UNLOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
599 return 0;
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
600 }
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
601
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
602
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
603 void xs_songlen_close(void)
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
604 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
605 XS_MUTEX_LOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
606 xs_sldb_free(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
607 xs_sldb_db = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
608 XS_MUTEX_UNLOCK(xs_sldb_db);
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
609 }
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
610
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
611
402
f997b79a7251 More work on merging of improved STIL/SLDB handling code with completely
Matti Hamalainen <ccr@tnsp.org>
parents: 392
diff changeset
612 t_xs_sldb_node *xs_songlen_get(const gchar * pcFilename)
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
613 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
614 t_xs_sldb_node *pResult;
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
615
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
616 XS_MUTEX_LOCK(xs_sldb_db);
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
617
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
618 if (xs_cfg.songlenDBEnable && xs_sldb_db)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
619 pResult = xs_sldb_get(xs_sldb_db, pcFilename);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
620 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
621 pResult = NULL;
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
622
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
623 XS_MUTEX_UNLOCK(xs_sldb_db);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
624
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
625 return pResult;
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 227
diff changeset
626 }