Mercurial > hg > sidinfo
annotate sidlib.c @ 86:e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Needs refactoring.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Feb 2016 23:21:26 +0200 |
parents | 4c0ecb078591 |
children | c5ff71d64e53 |
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 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
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 static void si_append_hash16(th_md5state_t *state, uint16_t data) |
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 uint8_t ib8[2]; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 ib8[0] = data & 0xff; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 ib8[1] = data >> 8; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 th_md5_append(state, (uint8_t *) &ib8, sizeof(ib8)); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 } |
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 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
20 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
|
21 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 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
|
23 uint8_t tmp8, *data = NULL; |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 int index, ret = -1; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 size_t read; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 BOOL first; |
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 memset(psid, 0, sizeof(*psid)); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
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 ((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
|
31 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
32 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
|
33 "Error allocating temporary data buffer of %d bytes.\n", |
77 | 34 PSID_BUFFER_SIZE); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 // 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
|
39 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
|
40 !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
|
41 !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
|
42 !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
|
43 !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
|
44 !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
|
45 !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
|
46 !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
|
47 !thfread_be32(ctx, &psid->speed)) |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
49 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
|
50 "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
|
51 th_error_str(ctx->errno)); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 psid->magic[PSID_MAGIC_LEN] = 0; |
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 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') || |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 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
|
59 psid->version < 1 || psid->version > 3) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
61 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
|
62 "Not a supported PSID or RSID file.\n"); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 psid->isRSID = psid->magic[0] == 'R'; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
68 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
|
69 !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
|
70 !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
|
71 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
72 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
|
73 "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
|
74 th_error_str(ctx->errno)); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 psid->sidName[PSID_STR_LEN] = 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 psid->sidAuthor[PSID_STR_LEN] = 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 psid->sidCopyright[PSID_STR_LEN] = 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 // Check if we need to load PSIDv2NG header ... |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 if (psid->version >= 2) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 // 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
|
86 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
|
87 !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
|
88 !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
|
89 !thfread_be16(ctx, &psid->reserved)) |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
91 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
|
92 "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
|
93 th_error_str(ctx->errno)); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 // Initialize MD5-hash calculation |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 th_md5_init(&state); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 // Process actual data |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 psid->dataSize = 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 first = TRUE; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 do |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 { |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
106 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
|
107 psid->dataSize += read; |
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 if (first && psid->loadAddress == 0) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 if (read < 4) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 { |
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_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
|
114 "Error reading song data, unexpectedly small file.\n"); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 goto error; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 // 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
|
119 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
|
120 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 // 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
|
122 th_md5_append(&state, &data[2], read - 2); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 first = FALSE; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 else |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 if (read > 0) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 // 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
|
129 th_md5_append(&state, data, read); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 } |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
131 } while (read > 0 && !thfeof(ctx)); |
70
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 // Append header data to hash |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
134 si_append_hash16(&state, psid->initAddress); |
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
135 si_append_hash16(&state, psid->playAddress); |
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
136 si_append_hash16(&state, psid->nSongs); |
70
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 // Append song speed data to hash |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 tmp8 = psid->isRSID ? 60 : 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 for (index = 0; index < psid->nSongs && index < 32; index++) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 if (psid->isRSID) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 tmp8 = 60; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 else |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 tmp8 = (psid->speed & (1 << index)) ? 60 : 0; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 th_md5_append(&state, &tmp8, sizeof(tmp8)); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 // Rest of songs (more than 32) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 for (index = 32; index < psid->nSongs; index++) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 th_md5_append(&state, &tmp8, sizeof(tmp8)); |
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 // PSIDv2NG specific |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 if (psid->version >= 2) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 tmp8 = (psid->flags >> 2) & 3; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 if (tmp8 == 2) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 th_md5_append(&state, &tmp8, sizeof(tmp8)); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 } |
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 // Calculate the hash |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 th_md5_finish(&state, psid->hash); |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 ret = 0; |
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 error: |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 // 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
|
169 th_free(data); |
70
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 return ret; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
174 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
|
175 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 switch (flags & PSF_CLOCK_MASK) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 case PSF_CLOCK_UNKNOWN : return "Unknown"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 case PSF_CLOCK_PAL : return "PAL 50Hz"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 case PSF_CLOCK_NTSC : return "NTSC 60Hz"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 case PSF_CLOCK_ANY : return "PAL / NTSC"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 default : return "?"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 |
85
4c0ecb078591
Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
187 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
|
188 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 switch (flags & PSF_MODEL_MASK) |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 case PSF_MODEL_UNKNOWN : return "Unknown"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 case PSF_MODEL_MOS6581 : return "MOS6581"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 case PSF_MODEL_MOS8580 : return "MOS8580"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 case PSF_MODEL_ANY : return "MOS6581 / MOS8580"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 default : return "?"; |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 } |
4779bbec2f28
Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 } |
86
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
198 |
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 // 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
|
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 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
|
203 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
204 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
|
205 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
206 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
|
207 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
|
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 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
210 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
211 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
212 // 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
|
213 // |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
214 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
|
215 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
216 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
|
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->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
|
219 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
|
220 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
|
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 else |
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 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
|
225 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
|
226 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
227 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
|
228 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
229 |
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 // 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
|
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 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
|
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 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
|
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 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
|
238 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
|
239 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
240 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
|
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 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
243 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
244 static int si_sldb_get_hex_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
|
245 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
246 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
|
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 do |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
249 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
250 char ch = 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 result <<= 4; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
252 if (ch >= 'A' && ch <= 'F') |
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 |= ch - 'A'; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
254 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
255 if (ch >= 'a' && ch <= 'f') |
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 |= ch - 'a'; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
257 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
258 if (ch >= '0' && ch <= '9') |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
259 result |= ch - '0'; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
260 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
261 break; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
262 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
263 while (1); |
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 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
|
266 } |
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 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
269 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
|
270 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
271 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
|
272 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
273 // Check if it starts with a digit |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
274 if (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
|
275 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
276 // 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
|
277 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
|
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 // 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
|
280 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
|
281 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
282 // 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
|
283 (*pos)++; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
284 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
|
285 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
286 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
287 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
|
288 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
289 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
290 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
|
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 // Ignore and skip the possible attributes |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
293 while (str[*pos] && !isspace(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
|
294 (*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 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
296 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
|
297 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
298 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
299 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
300 // 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
|
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 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
|
303 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
309 // 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
|
310 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
|
311 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
|
312 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
313 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
|
314 "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
|
315 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
|
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 // 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
|
319 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
|
320 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
|
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 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
|
323 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
|
324 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
|
325 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
326 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
327 // 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
|
328 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
|
329 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
|
330 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
331 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
|
332 "'=' 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
|
333 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
|
334 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
335 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
336 // 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
|
337 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
|
338 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
|
339 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
340 // 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
|
341 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
|
342 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
|
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 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
|
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 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
|
347 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
|
348 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
349 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
|
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 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
352 // 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
|
353 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
|
354 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
|
355 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
356 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
|
357 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
|
358 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
359 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
|
360 "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
|
361 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
|
362 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
363 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
364 // 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
|
365 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
|
366 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
|
367 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
368 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
|
369 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
|
370 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
375 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
|
376 } |
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 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
|
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 error: |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
381 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
|
382 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
|
383 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
384 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
385 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
386 // 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
|
387 // |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
388 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
|
389 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
390 char line[PSID_BUFFER2_SIZE]; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
391 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
392 while (thfgets(line, PSID_BUFFER2_SIZE, ctx) != NULL) |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
393 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
394 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
|
395 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
|
396 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
|
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 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
|
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 // 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
|
401 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
|
402 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
403 // 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
|
404 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
|
405 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
|
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 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
|
408 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
409 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
|
410 "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
|
411 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
|
412 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
413 else |
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 // 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
|
416 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
|
417 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
418 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
|
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 else |
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 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
|
423 "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
|
424 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
|
425 } |
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 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
428 else |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
429 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
|
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 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
|
432 "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
|
433 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
|
434 } |
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 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
|
438 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
439 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
440 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
441 // 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
|
442 // 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
|
443 // 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
|
444 // 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
|
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 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
|
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 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
|
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 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
|
451 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
|
452 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
453 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
|
454 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
455 |
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 // 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
|
458 // 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
|
459 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
|
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 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
|
462 (*(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
|
463 (*(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
|
464 } |
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 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
467 // (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
|
468 // |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
469 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
|
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 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
|
472 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
473 // 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
|
474 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
|
475 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
476 // 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
|
477 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
|
478 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
|
479 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
480 // 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
|
481 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
|
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 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
|
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 // Allocate memory for index-table |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
486 dbh->pindex = (SIDLibSLDBNode * *) th_malloc(sizeof(SIDLibSLDBNode *) * 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
|
487 if (dbh->pindex == NULL) |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
488 return -1; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
489 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
490 // 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
|
491 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
|
492 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
|
493 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
494 // 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
|
495 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
|
496 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
497 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
498 return 0; |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
499 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
500 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
501 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
502 // 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
|
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 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
|
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 *node = 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
|
507 while (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
|
508 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
509 SIDLibSLDBNode *next = 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
|
510 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
|
511 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
|
512 } |
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 dbh->nodes = 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 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
|
516 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
517 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
|
518 th_free(dbh); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
519 } |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
520 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
521 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
522 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
|
523 { |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
524 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
|
525 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
526 memcpy(&keyItem.hash, &hash, sizeof(th_md5hash_t)); |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
527 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
|
528 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
|
529 |
e1ff9cd27a84
Initial port of songlength database (SLDB) handling code from XMMS-SID to here.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
530 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
|
531 } |