annotate src/xs_length.c @ 369:4611f1194941

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