annotate sidlib.c @ 95:833bb78eb658

Use th_md5_append_le*() functions instead.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Feb 2016 18:19:46 +0200
parents 681dfc3b006e
children d9f38d657433
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * SIDInfoLib - Way too simplistic PSID/RSID file library
93
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
3 * Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
73
2b2376f1b0cc Update copyright years. Yay. It's 2016!
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
4 * (C) Copyright 2014-2016 Tecnic Software productions (TNSP)
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "sidlib.h"
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "th_endian.h"
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
8 #include "th_string.h"
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
11 int si_read_sid_file(th_ioctx *ctx, PSIDHeader *psid)
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 th_md5state_t state;
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
14 uint8_t tmp8, *data = NULL;
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 int index, ret = -1;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 size_t read;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 BOOL first;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 memset(psid, 0, sizeof(*psid));
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
21 if ((data = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL)
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
23 th_io_error(ctx, THERR_MALLOC,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
24 "Error allocating temporary data buffer of %d bytes.\n",
77
d14c82880141 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
25 PSID_BUFFER_SIZE);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 // Read PSID header in
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
30 if (!thfread_str(ctx, (uint8_t *) psid->magic, PSID_MAGIC_LEN) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
31 !thfread_be16(ctx, &psid->version) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
32 !thfread_be16(ctx, &psid->dataOffset) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
33 !thfread_be16(ctx, &psid->loadAddress) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
34 !thfread_be16(ctx, &psid->initAddress) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
35 !thfread_be16(ctx, &psid->playAddress) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
36 !thfread_be16(ctx, &psid->nSongs) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
37 !thfread_be16(ctx, &psid->startSong) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
38 !thfread_be32(ctx, &psid->speed))
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
40 th_io_error(ctx, ctx->errno,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
41 "Could not read PSID/RSID header: %s.\n",
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
42 th_error_str(ctx->errno));
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 psid->magic[PSID_MAGIC_LEN] = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') ||
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' ||
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 psid->version < 1 || psid->version > 3)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
52 th_io_error(ctx, THERR_NOT_SUPPORTED,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
53 "Not a supported PSID or RSID file.\n");
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 psid->isRSID = psid->magic[0] == 'R';
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
59 if (!thfread_str(ctx, (uint8_t *) psid->sidName, PSID_STR_LEN) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
60 !thfread_str(ctx, (uint8_t *) psid->sidAuthor, PSID_STR_LEN) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
61 !thfread_str(ctx, (uint8_t *) psid->sidCopyright, PSID_STR_LEN))
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
63 th_io_error(ctx, ctx->errno,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
64 "Error reading SID file header: %s.\n",
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
65 th_error_str(ctx->errno));
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 psid->sidName[PSID_STR_LEN] = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 psid->sidAuthor[PSID_STR_LEN] = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 psid->sidCopyright[PSID_STR_LEN] = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 // Check if we need to load PSIDv2NG header ...
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 if (psid->version >= 2)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 // Yes, we need to
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
77 if (!thfread_be16(ctx, &psid->flags) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
78 !thfread_byte(ctx, &psid->startPage) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
79 !thfread_byte(ctx, &psid->pageLength) ||
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
80 !thfread_be16(ctx, &psid->reserved))
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
82 th_io_error(ctx, ctx->errno,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
83 "Error reading PSID/RSID v2+ extra header data: %s.\n",
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
84 th_error_str(ctx->errno));
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 // Initialize MD5-hash calculation
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 th_md5_init(&state);
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 // Process actual data
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 psid->dataSize = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 first = TRUE;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 do
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
97 read = thfread(data, sizeof(uint8_t), PSID_BUFFER_SIZE, ctx);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 psid->dataSize += read;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 if (first && psid->loadAddress == 0)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if (read < 4)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
104 th_io_error(ctx, THERR_FREAD,
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
105 "Error reading song data, unexpectedly small file.\n");
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 goto error;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 // Grab the actual load address
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
110 psid->loadAddress = TH_LE16_TO_NATIVE(*(uint16_t *) data);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 // Strip load address (2 first bytes)
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
113 th_md5_append(&state, &data[2], read - 2);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 first = FALSE;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 else
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 if (read > 0)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 // Append "as is"
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
120 th_md5_append(&state, data, read);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
122 } while (read > 0 && !thfeof(ctx));
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 // Append header data to hash
95
833bb78eb658 Use th_md5_append_le*() functions instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
125 th_md5_append_le16(&state, psid->initAddress);
833bb78eb658 Use th_md5_append_le*() functions instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
126 th_md5_append_le16(&state, psid->playAddress);
833bb78eb658 Use th_md5_append_le*() functions instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
127 th_md5_append_le16(&state, psid->nSongs);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 // Append song speed data to hash
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 tmp8 = psid->isRSID ? 60 : 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 for (index = 0; index < psid->nSongs && index < 32; index++)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 if (psid->isRSID)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 tmp8 = 60;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 else
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 tmp8 = (psid->speed & (1 << index)) ? 60 : 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 th_md5_append(&state, &tmp8, sizeof(tmp8));
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 // Rest of songs (more than 32)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 for (index = 32; index < psid->nSongs; index++)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 th_md5_append(&state, &tmp8, sizeof(tmp8));
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 // PSIDv2NG specific
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 if (psid->version >= 2)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 tmp8 = (psid->flags >> 2) & 3;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 if (tmp8 == 2)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 th_md5_append(&state, &tmp8, sizeof(tmp8));
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 // Calculate the hash
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 th_md5_finish(&state, psid->hash);
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 ret = 0;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 error:
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 // Free buffer
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
160 th_free(data);
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return ret;
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
165 const char *si_get_sid_clock_str(const int flags)
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 switch (flags & PSF_CLOCK_MASK)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 case PSF_CLOCK_UNKNOWN : return "Unknown";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 case PSF_CLOCK_PAL : return "PAL 50Hz";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 case PSF_CLOCK_NTSC : return "NTSC 60Hz";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 case PSF_CLOCK_ANY : return "PAL / NTSC";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 default : return "?";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
178 const char *si_get_sid_model_str(const int flags)
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 switch (flags & PSF_MODEL_MASK)
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 {
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 case PSF_MODEL_UNKNOWN : return "Unknown";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 case PSF_MODEL_MOS6581 : return "MOS6581";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 case PSF_MODEL_MOS8580 : return "MOS8580";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 case PSF_MODEL_ANY : return "MOS6581 / MOS8580";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 default : return "?";
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
189
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
190
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
191 // Free memory allocated for given SLDB node
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
192 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
193 static void si_sldb_node_free(SIDLibSLDBNode *node)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
194 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
195 if (node)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
196 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
197 th_free_r(&node->lengths);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
198 th_free_r(&node);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
199 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
200 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
201
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
202
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
203 // Insert given node to db linked list
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
204 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
205 static void si_sldb_node_insert(SIDLibSLDB *dbh, SIDLibSLDBNode *node)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
206 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
207 if (dbh->nodes)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
208 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
209 node->prev = dbh->nodes->prev;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
210 dbh->nodes->prev->next = node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
211 dbh->nodes->prev = node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
212 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
213 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
214 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
215 dbh->nodes = node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
216 node->prev = node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
217 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
218 node->next = NULL;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
219 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
220
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
221
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
222 // Parse a time-entry in SLDB format
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
223 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
224 static int si_sldb_get_value(const char *str, size_t *pos)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
225 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
226 int result = 0;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
227
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
228 while (isdigit(str[*pos]))
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
229 result = (result * 10) + (str[(*pos)++] - '0');
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
230
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
231 return result;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
232 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
233
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
234
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
235 static int si_sldb_gettime(const char *str, size_t *pos)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
236 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
237 int result;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
238
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
239 // Check if it starts with a digit
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
240 if (th_isdigit(str[*pos]))
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
241 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
242 // Get minutes-field
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
243 result = si_sldb_get_value(str, pos) * 60;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
244
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
245 // Check the field separator char
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
246 if (str[*pos] == ':')
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
247 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
248 // Get seconds-field
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
249 (*pos)++;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
250 result += si_sldb_get_value(str, pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
251 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
252 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
253 result = -2;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
254 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
255 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
256 result = -1;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
257
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
258 // Ignore and skip the possible attributes
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
259 while (str[*pos] && !th_isspace(str[*pos]))
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
260 (*pos)++;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
261
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
262 return result;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
263 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
264
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
265
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
266 // Parse one SLDB definition line, return SLDB node
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
267 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
268 SIDLibSLDBNode *si_sldb_parse_entry(th_ioctx *ctx, const char *line)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
269 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
270 SIDLibSLDBNode *node = NULL;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
271 size_t pos, tmpLen, savePos;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
272 BOOL isOK;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
273 int i;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
274
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
275 // Allocate new node
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
276 node = (SIDLibSLDBNode *) th_malloc0(sizeof(SIDLibSLDBNode));
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
277 if (node == NULL)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
278 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
279 th_io_error(ctx, THERR_MALLOC,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
280 "Error allocating new node.\n");
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
281 return NULL;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
282 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
283
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
284 // Get hash value
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
285 pos = 0;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
286 for (i = 0; i < TH_MD5HASH_LENGTH; i++, pos += 2)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
287 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
288 unsigned int tmpu;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
289 sscanf(&line[pos], "%2x", &tmpu);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
290 node->hash[i] = tmpu;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
291 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
292
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
293 // Get playtimes
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
294 th_findnext(line, &pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
295 if (line[pos] != '=')
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
296 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
297 th_io_error(ctx, THERR_INVALID_DATA,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
298 "'=' expected on column #%d.\n", pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
299 goto error;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
300 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
301
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
302 // First playtime is after '='
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
303 savePos = ++pos;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
304 tmpLen = strlen(line);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
305
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
306 // Get number of sub-tune lengths
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
307 isOK = TRUE;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
308 while (pos < tmpLen && isOK)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
309 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
310 th_findnext(line, &pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
311
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
312 if (si_sldb_gettime(line, &pos) >= 0)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
313 node->nlengths++;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
314 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
315 isOK = FALSE;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
316 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
317
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
318 // Allocate memory for lengths
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
319 if (node->nlengths == 0)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
320 goto error;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
321
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
322 node->lengths = (int *) th_malloc0(node->nlengths * sizeof(int));
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
323 if (node->lengths == NULL)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
324 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
325 th_io_error(ctx, THERR_MALLOC,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
326 "Could not allocate memory for node.\n");
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
327 goto error;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
328 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
329
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
330 // Read lengths in
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
331 for (i = 0, pos = savePos, isOK = TRUE;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
332 pos < tmpLen && i < node->nlengths && isOK; i++)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
333 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
334 int l;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
335 th_findnext(line, &pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
336
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
337 l = si_sldb_gettime(line, &pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
338 if (l >= 0)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
339 node->lengths[i] = l;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
340 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
341 isOK = FALSE;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
342 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
343
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
344 return node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
345
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
346 error:
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
347 si_sldb_node_free(node);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
348 return NULL;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
349 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
350
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
351
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
352 SIDLibSLDB * si_sldb_new(void)
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
353 {
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
354 return (SIDLibSLDB *) th_malloc0(sizeof(SIDLibSLDB));
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
355 }
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
356
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
357
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
358 // Read SLDB database to memory
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
359 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
360 int si_sldb_read(th_ioctx *ctx, SIDLibSLDB *dbh)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
361 {
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
362 char *line = NULL;
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
363
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
364 if ((line = th_malloc(PSID_BUFFER_SIZE)) == NULL)
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
365 {
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
366 th_io_error(ctx, THERR_MALLOC,
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
367 "Error allocating temporary data buffer of %d bytes.\n",
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
368 PSID_BUFFER_SIZE);
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
369 return ctx->errno;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
370 }
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
371
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
372 while (thfgets(line, PSID_BUFFER_SIZE, ctx) != NULL)
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
373 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
374 SIDLibSLDBNode *tmnode;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
375 size_t pos = 0;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
376 ctx->line++;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
377
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
378 th_findnext(line, &pos);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
379
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
380 // Check if it is datafield
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
381 if (th_isxdigit(line[pos]))
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
382 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
383 // Check the length of the hash
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
384 int hashLen;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
385 for (hashLen = 0; line[pos] && th_isxdigit(line[pos]); hashLen++, pos++);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
386
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
387 if (hashLen != TH_MD5HASH_LENGTH_CH)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
388 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
389 th_io_error(ctx, THERR_INVALID_DATA,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
390 "Invalid MD5-hash in SongLengthDB file '%s' line #%d:\n%s\n",
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
391 ctx->filename, ctx->line, line);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
392 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
393 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
394 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
395 // Parse and add node to db
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
396 if ((tmnode = si_sldb_parse_entry(ctx, line)) != NULL)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
397 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
398 si_sldb_node_insert(dbh, tmnode);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
399 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
400 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
401 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
402 th_io_error(ctx, THERR_INVALID_DATA,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
403 "Invalid entry in SongLengthDB file '%s' line #%d:\n%s\n",
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
404 ctx->filename, ctx->line, line);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
405 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
406 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
407 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
408 else
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
409 if (line[pos] != ';' && line[pos] != '[' && line[pos] != 0)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
410 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
411 th_io_error(ctx, THERR_INVALID_DATA,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
412 "Invalid line in SongLengthDB file '%s' line #%d:\n%s\n",
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
413 ctx->filename, ctx->line, line);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
414 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
415 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
416
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
417 th_free(line);
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
418 return THERR_OK;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
419 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
420
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
421
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
422 // Compare two given MD5-hashes.
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
423 // Return: 0 if equal
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
424 // negative if testHash1 < testHash2
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
425 // positive if testHash1 > testHash2
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
426 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
427 static int si_sldb_compare_hash(th_md5hash_t testHash1, th_md5hash_t testHash2)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
428 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
429 int i, delta;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
430
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
431 for (i = delta = 0; i < TH_MD5HASH_LENGTH && !delta; i++)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
432 delta = testHash1[i] - testHash2[i];
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
433
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
434 return delta;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
435 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
436
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
437
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
438 // Compare two nodes.
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
439 // We assume here that we never ever get NULL-pointers.
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
440 static int si_sldb_compare_nodes(const void *node1, const void *node2)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
441 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
442 return si_sldb_compare_hash(
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
443 (*(SIDLibSLDBNode **) node1)->hash,
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
444 (*(SIDLibSLDBNode **) node2)->hash);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
445 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
446
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
447
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
448 // (Re)create index
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
449 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
450 int si_sldb_build_index(SIDLibSLDB * dbh)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
451 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
452 SIDLibSLDBNode *node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
453
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
454 // Free old index
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
455 th_free_r(&dbh->pindex);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
456
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
457 // Get size of db
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
458 for (node = dbh->nodes, dbh->n = 0; node != NULL; node = node->next)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
459 dbh->n++;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
460
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
461 // Check number of nodes
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
462 if (dbh->n > 0)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
463 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
464 size_t i;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
465
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
466 // Allocate memory for index-table
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
467 dbh->pindex = (SIDLibSLDBNode **) th_malloc(sizeof(SIDLibSLDBNode *) * dbh->n);
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
468 if (dbh->pindex == NULL)
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
469 return THERR_MALLOC;
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
470
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
471 // Get node-pointers to table
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
472 for (i = 0, node = dbh->nodes; node && i < dbh->n; node = node->next)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
473 dbh->pindex[i++] = node;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
474
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
475 // Sort the indexes
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
476 qsort(dbh->pindex, dbh->n, sizeof(SIDLibSLDBNode *), si_sldb_compare_nodes);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
477 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
478
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
479 return THERR_OK;
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
480 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
481
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
482
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
483 // Free a given song-length database
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
484 //
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
485 void si_sldb_free(SIDLibSLDB *dbh)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
486 {
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
487 if (dbh != NULL)
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
488 {
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
489 SIDLibSLDBNode *node = dbh->nodes;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
490 while (node != NULL)
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
491 {
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
492 SIDLibSLDBNode *next = node->next;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
493 si_sldb_node_free(node);
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
494 node = next;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
495 }
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
496
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
497 dbh->nodes = NULL;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
498 dbh->n = 0;
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
499
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
500 th_free_r(&dbh->pindex);
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
501 th_free(dbh);
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
502 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
503 }
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
504
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
505
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
506 SIDLibSLDBNode *si_sldb_get_by_hash(SIDLibSLDB *dbh, th_md5hash_t hash)
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
507 {
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
508 SIDLibSLDBNode keyItem, *key, **item;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
509
88
c5ff71d64e53 More work on sidlib SLDB code.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
510 memcpy(&keyItem.hash, hash, sizeof(th_md5hash_t));
86
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
511 key = &keyItem;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
512 item = bsearch(&key, dbh->pindex, dbh->n, sizeof(dbh->pindex[0]), si_sldb_compare_nodes);
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
513
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
514 return (item != NULL) ? *item : NULL;
e1ff9cd27a84 Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
515 }