comparison src/xs_length.c @ 4:4bb09e405eab

Added new files for 0.8
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Jun 2003 11:03:04 +0000
parents
children f5d82424b0ed
comparison
equal deleted inserted replaced
3:279b1e12df2b 4:4bb09e405eab
1 /*
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
3
4 Get song length (from database or by other means)
5
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #include "xmms-sid.h"
24 #include "xs_length.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <ctype.h>
28 #include <string.h>
29
30 /*
31 * Pointer to database in memory
32 */
33 static t_xs_dbentry *xs_database = NULL;
34
35
36 /*
37 * Parses a time-entry in SLDB format
38 */
39 long int xs_gettime(char *pcStr, int *piPos)
40 {
41 long int iResult;
42 int iTemp;
43 char chTempBuf[16];
44
45 /* Check if it starts with a digit */
46 if (isdigit(pcStr[*piPos]))
47 {
48 /* Get minutes-field */
49 iTemp = *piPos;
50 xs_findnum(pcStr, piPos);
51
52 strncpy(chTempBuf, &pcStr[iTemp], (*piPos - iTemp));
53 chTempBuf[*piPos - iTemp] = 0;
54
55 iResult = (atol(chTempBuf) * 60);
56
57 /* Check the field separator char */
58 if (pcStr[*piPos] == ':')
59 {
60 /* Get seconds-field */
61 (*piPos)++;
62 iTemp = *piPos;
63 xs_findnum(pcStr, piPos);
64
65 strncpy(chTempBuf, &pcStr[iTemp], (*piPos - iTemp));
66 chTempBuf[*piPos - iTemp] = 0;
67
68 iResult += atol(chTempBuf);
69
70 } else
71 iResult = -2;
72 } else
73 iResult = -1;
74
75 /* Ignore and skip the possible attributes */
76 while (!isspace(pcStr[*piPos])) (*piPos)++;
77
78 return iResult;
79 }
80
81
82 /*
83 * Initialize, read database to memory
84 */
85 gint xs_db_initialize(gchar *pcFilename)
86 {
87 FILE *inFile;
88 char inLine[256];
89 int lineNum, linePos, i, j, k;
90 t_xs_hash tmpHash;
91
92
93 /* Try to open the file */
94 if ((inFile = fopen(pcFilename, "r")) == NULL)
95 {
96 fprintf(stderr, "hv!\n");
97 return -1;
98 }
99
100
101 /* Read and parse the data */
102 lineNum = 0;
103
104 while (!feof(inFile))
105 {
106 fgets(inLine, sizeof(inLine), inFile);
107 linePos = 0;
108
109 if (strlen(inLine) > 1)
110 {
111 /* Find first character */
112 xs_findnext(inLine, &linePos);
113
114 /* Check if it is a hash-line */
115 if (isxdigit(inLine[linePos]))
116 {
117 i = linePos;
118 while (isxdigit(inLine[linePos])) linePos++;
119
120 if ((linePos - i) != XS_HASH_LENGTH_CH)
121 {
122 XSERR("Invalid hash/syntax error in SongLengthDB file '%s' line #%d!\n",
123 pcFilename, lineNum);
124 } else {
125 /* Get hashcode value */
126 for (j = 0; j < XS_HASH_LENGTH; j++)
127 {
128
129 }
130
131 /* Get playtimes */
132 xs_findnext(line, &linePos);
133
134 if (line[linePos] != '=')
135 {
136 XSERR("Warning: '=' expected in line #%d in SongLengthDB file '%s'\n",
137 lineNum, pcFilename);
138 } else {
139 linePos++;
140
141 while (linePos < strlen(inLine))
142 {
143 xs_findnext(line, &linePos);
144 printf("[%lis]", xs_gettime(inLine, &linePos));
145 }
146
147
148 /* Add an entry to db in memory */
149 }
150 }
151 }
152 else
153 if ((line[linePos] != ';') && (line[linePos] != '['))
154 {
155 XSERR("Invalid line #%d in SongLengthDB file '%s'\n", lineNum, pcFilename);
156 }
157
158 } /* strlen(line) > 1 */
159
160 lineNum++;
161 }
162
163 fclose(inFile);
164
165 return 0;
166 }
167
168
169 /*
170 *
171 */
172 gint xs_db_delete(void)
173 {
174 /* Free the memory allocated for database */
175
176 return 0;
177 }
178
179
180 /*
181 *
182 */
183 int xs_comparehashes(t_xs_hash *testHash1, t_xs_hash *testHash2)
184 {
185 int iIndex, iOK;
186
187 iOK = 1;
188 iIndex = 0;
189 while ((iIndex < 16) && (iOK))
190 {
191 if (testHash1[iIndex] != testHash2[iIndex])
192 iOK = 0;
193 else
194 iIndex++;
195 }
196
197 return iOK;
198 }
199
200
201
202
203 /*
204 * Get song length from database
205 */
206 t_xs_dbentry * xs_db_get(gchar *pcFilename)
207 {
208
209 return NULL;
210 }
211
212
213 gint32 xs_get_length(gchar *pcFilename, gint iSubTune)
214 {
215 gint32 iResult;
216 t_xs_dbentry *dbEntry;
217 t_xs_hash dbHash;
218
219 iResult = -1;
220
221 switch (xs_cfg.playMethod) {
222
223 case XMMS_SID_PMETHOD_DATABASE:
224
225 iResult = xs_db_get(pcFilename, &dbHash);
226 if (iResult >= 0)
227 {
228 }
229
230 if (dbEntry)
231 {
232 if ((iSubTune >= 0) && (iSubTune < dbEntry->nlengths))
233 iResult = dbEntry->lengths[iSubTune];
234 else
235 iResult = -1;
236 }
237 break;
238
239 case XMMS_SID_PMETHOD_MAXSILENCE:
240 case XMMS_SID_PMETHOD_NONE:
241 iResult = -1;
242 break;
243
244 default:
245 XSERR("Invalid play-method! (%d, unknown)\n", xs_cfg.playMethod);
246 break;
247 }
248
249 /* Check for max playtime */
250 if (iResult == -1)
251 {
252 if (xs_cfg.playUseMaxTime)
253 iResult = xs_cfg.playMaxTime;
254 else
255 iResult = -1;
256 }
257
258 XSDEBUG("fname='%s', sub=%i, res=%li\n", pcFilename, iSubTune, iResult);
259
260 return iResult;
261 }
262